Added boost header

This commit is contained in:
Christophe Riccio
2012-01-08 01:26:07 +00:00
parent 9c3faaca40
commit c7d752cdf8
8946 changed files with 1732316 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_ADD_CONST_IF_C_HPP
#define BOOST_GEOMETRY_UTIL_ADD_CONST_IF_C_HPP
#include <boost/mpl/if.hpp>
namespace boost { namespace geometry
{
/*!
\brief Meta-function to define a const or non const type
\ingroup utility
\details If the boolean template parameter is true, the type parameter
will be defined as const, otherwise it will be defined as it was.
This meta-function is used to have one implementation for both
const and non const references
\note This traits class is completely independant from Boost.Geometry
and might be a separate addition to Boost
\note Used in a.o. for_each, interior_rings, exterior_ring
\par Example
\code
void foo(typename add_const_if_c<IsConst, Point>::type& point)
\endcode
*/
template <bool IsConst, typename Type>
struct add_const_if_c
{
typedef typename boost::mpl::if_c
<
IsConst,
Type const,
Type
>::type type;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_ADD_CONST_IF_C_HPP

View File

@@ -0,0 +1,46 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_CLOSURE_AS_BOOL_HPP
#define BOOST_GEOMETRY_UTIL_CLOSURE_AS_BOOL_HPP
#include <boost/geometry/core/closure.hpp>
namespace boost { namespace geometry
{
template<closure_selector Closure>
struct closure_as_bool
{};
template<>
struct closure_as_bool<closed>
{
static const bool value = true;
};
template<>
struct closure_as_bool<open>
{
static const bool value = false;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_CLOSURE_AS_BOOL_HPP

View File

@@ -0,0 +1,55 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_COORDINATE_CAST_HPP
#define BOOST_GEOMETRY_UTIL_COORDINATE_CAST_HPP
#include <cstdlib>
#include <string>
#include <boost/lexical_cast.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
/*!
\brief cast coordinates from a string to a coordinate type
\detail By default it uses lexical_cast. However, lexical_cast seems not to support
ttmath / partial specializations. Therefore this small utility is added.
See also "define_pi" where the same issue is solved
*/
template <typename CoordinateType>
struct coordinate_cast
{
static inline CoordinateType apply(std::string const& source)
{
#if defined(BOOST_GEOMETRY_NO_LEXICAL_CAST)
return atof(source.c_str());
#else
return boost::lexical_cast<CoordinateType>(source);
#endif
}
};
} // namespace detail
#endif
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_COORDINATE_CAST_HPP

View File

@@ -0,0 +1,94 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP
#define BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP
#include <boost/concept/requires.hpp>
#include <boost/geometry/geometries/concepts/point_concept.hpp>
#include <boost/geometry/util/add_const_if_c.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
template <typename Point, int Dimension, int DimensionCount, bool IsConst>
struct coordinates_scanner
{
template <typename Op>
static inline Op apply(typename add_const_if_c
<
IsConst,
Point
>::type& point, Op operation)
{
operation.template apply<Point, Dimension>(point);
return coordinates_scanner
<
Point,
Dimension+1,
DimensionCount,
IsConst
>::apply(point, operation);
}
};
template <typename Point, int DimensionCount, bool IsConst>
struct coordinates_scanner<Point, DimensionCount, DimensionCount, IsConst>
{
template <typename Op>
static inline Op apply(typename add_const_if_c
<
IsConst,
Point
>::type& point, Op operation)
{
return operation;
}
};
} // namespace detail
#endif // DOXYGEN_NO_DETAIL
template <typename Point, typename Op>
inline void for_each_coordinate(Point& point, Op operation)
{
BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
typedef typename detail::coordinates_scanner
<
Point, 0, dimension<Point>::type::value, false
> scanner;
scanner::apply(point, operation);
}
template <typename Point, typename Op>
inline Op for_each_coordinate(Point const& point, Op operation)
{
BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point>) );
typedef typename detail::coordinates_scanner
<
Point, 0, dimension<Point>::type::value, true
> scanner;
return scanner::apply(point, operation);
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_FOR_EACH_COORDINATE_HPP

View File

@@ -0,0 +1,168 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_MATH_HPP
#define BOOST_GEOMETRY_UTIL_MATH_HPP
#include <cmath>
#include <limits>
#include <boost/math/constants/constants.hpp>
#include <boost/geometry/util/select_most_precise.hpp>
namespace boost { namespace geometry
{
namespace math
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail
{
template <typename Type, bool IsFloatingPoint>
struct equals
{
static inline bool apply(Type const& a, Type const& b)
{
return a == b;
}
};
template <typename Type>
struct equals<Type, true>
{
static inline bool apply(Type const& a, Type const& b)
{
// See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17,
// FUTURE: replace by some boost tool or boost::test::close_at_tolerance
return std::abs(a - b) <= std::numeric_limits<Type>::epsilon() * std::abs(a);
}
};
template <typename Type, bool IsFloatingPoint>
struct equals_with_epsilon : public equals<Type, IsFloatingPoint> {};
/*!
\brief Short construct to enable partial specialization for PI, currently not possible in Math.
*/
template <typename T>
struct define_pi
{
static inline T apply()
{
// Default calls Boost.Math
return boost::math::constants::pi<T>();
}
};
} // namespace detail
#endif
template <typename T>
inline T pi() { return detail::define_pi<T>::apply(); }
// Maybe replace this by boost equals or boost ublas numeric equals or so
/*!
\brief returns true if both arguments are equal.
\ingroup utility
\param a first argument
\param b second argument
\return true if a == b
\note If both a and b are of an integral type, comparison is done by ==.
If one of the types is floating point, comparison is done by abs and
comparing with epsilon. If one of the types is non-fundamental, it might
be a high-precision number and comparison is done using the == operator
of that class.
*/
template <typename T1, typename T2>
inline bool equals(T1 const& a, T2 const& b)
{
typedef typename select_most_precise<T1, T2>::type select_type;
return detail::equals
<
select_type,
boost::is_floating_point<select_type>::type::value
>::apply(a, b);
}
template <typename T1, typename T2>
inline bool equals_with_epsilon(T1 const& a, T2 const& b)
{
typedef typename select_most_precise<T1, T2>::type select_type;
return detail::equals_with_epsilon
<
select_type,
boost::is_floating_point<select_type>::type::value
>::apply(a, b);
}
double const d2r = geometry::math::pi<double>() / 180.0;
double const r2d = 1.0 / d2r;
/*!
\brief Calculates the haversine of an angle
\ingroup utility
\note See http://en.wikipedia.org/wiki/Haversine_formula
haversin(alpha) = sin2(alpha/2)
*/
template <typename T>
inline T hav(T const& theta)
{
T const half = T(0.5);
T const sn = sin(half * theta);
return sn * sn;
}
/*!
\brief Short utility to return the square
\ingroup utility
\param value Value to calculate the square from
\return The squared value
*/
template <typename T>
inline T sqr(T const& value)
{
return value * value;
}
/*!
\brief Short utility to workaround gcc/clang problem that abs is converting to integer
\ingroup utility
*/
template<typename T>
inline T abs(const T& t)
{
using std::abs;
return abs(t);
}
} // namespace math
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_MATH_HPP

View File

@@ -0,0 +1,46 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_ORDER_AS_DIRECTION_HPP
#define BOOST_GEOMETRY_UTIL_ORDER_AS_DIRECTION_HPP
#include <boost/geometry/core/point_order.hpp>
#include <boost/geometry/views/reversible_view.hpp>
namespace boost { namespace geometry
{
template<order_selector Order>
struct order_as_direction
{};
template<>
struct order_as_direction<clockwise>
{
static const iterate_direction value = iterate_forward;
};
template<>
struct order_as_direction<counterclockwise>
{
static const iterate_direction value = iterate_reverse;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_ORDER_AS_DIRECTION_HPP

View File

@@ -0,0 +1,75 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_PARAMETER_TYPE_OF_HPP
#define BOOST_GEOMETRY_UTIL_PARAMETER_TYPE_OF_HPP
#include <boost/function_types/function_arity.hpp>
#include <boost/function_types/is_member_function_pointer.hpp>
#include <boost/function_types/parameter_types.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/type_traits.hpp>
namespace boost { namespace geometry
{
/*!
\brief Meta-function selecting a parameter type of a (member) function, by index
\ingroup utility
*/
template <typename Method, std::size_t Index>
struct parameter_type_of
{
typedef typename boost::function_types::parameter_types
<
Method
>::type parameter_types;
typedef typename boost::mpl::if_
<
boost::function_types::is_member_function_pointer<Method>,
boost::mpl::int_<1>,
boost::mpl::int_<0>
>::type base_index_type;
typedef typename boost::mpl::if_c
<
Index == 0,
base_index_type,
typename boost::mpl::plus
<
base_index_type,
boost::mpl::int_<Index>
>::type
>::type indexed_type;
typedef typename boost::remove_reference
<
typename boost::mpl::at
<
parameter_types,
indexed_type
>::type
>::type type;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_PARAMETER_TYPE_OF_HPP

View File

@@ -0,0 +1,50 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_PROMOTE_FLOATING_POINT_HPP
#define BOOST_GEOMETRY_UTIL_PROMOTE_FLOATING_POINT_HPP
#include <boost/mpl/if.hpp>
#include <boost/type_traits.hpp>
namespace boost { namespace geometry
{
/*!
\brief Meta-function converting, if necessary, to "a floating point" type
\details
- if input type is integer, type is double
- else type is input type
\ingroup utility
*/
template <typename T, typename PromoteIntegerTo = double>
struct promote_floating_point
{
typedef typename
boost::mpl::if_
<
boost::is_integral<T>,
PromoteIntegerTo,
T
>::type type;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_PROMOTE_FLOATING_POINT_HPP

View File

@@ -0,0 +1,179 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2011-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2011-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2011-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_RATIONAL_HPP
#define BOOST_GEOMETRY_UTIL_RATIONAL_HPP
#include <boost/rational.hpp>
#include <boost/numeric/conversion/bounds.hpp>
#include <boost/geometry/util/coordinate_cast.hpp>
#include <boost/geometry/util/select_most_precise.hpp>
namespace boost{ namespace geometry
{
// Specialize for Boost.Geometry's coordinate cast
// (from string to coordinate type)
namespace detail
{
template <typename T>
struct coordinate_cast<rational<T> >
{
static inline void split_parts(std::string const& source, std::string::size_type p,
T& before, T& after, bool& negate, std::string::size_type& len)
{
std::string before_part = source.substr(0, p);
std::string const after_part = source.substr(p + 1);
negate = false;
if (before_part.size() > 0 && before_part[0] == '-')
{
negate = true;
before_part.erase(0, 1);
}
before = atol(before_part.c_str());
after = atol(after_part.c_str());
len = after_part.length();
}
static inline rational<T> apply(std::string const& source)
{
T before, after;
bool negate;
std::string::size_type len;
// Note: decimal comma is not (yet) supported, it does (and should) not
// occur in a WKT, where points are comma separated.
std::string::size_type p = source.find(".");
if (p == std::string::npos)
{
p = source.find("/");
if (p == std::string::npos)
{
return rational<T>(atol(source.c_str()));
}
split_parts(source, p, before, after, negate, len);
return negate
? -rational<T>(before, after)
: rational<T>(before, after)
;
}
split_parts(source, p, before, after, negate, len);
T den = 1;
for (std::string::size_type i = 0; i < len; i++)
{
den *= 10;
}
return negate
? -rational<T>(before) - rational<T>(after, den)
: rational<T>(before) + rational<T>(after, den)
;
}
};
} // namespace detail
// Specialize for Boost.Geometry's select_most_precise
template <typename T1, typename T2>
struct select_most_precise<boost::rational<T1>, boost::rational<T2> >
{
typedef typename boost::rational
<
typename select_most_precise<T1, T2>::type
> type;
};
template <typename T>
struct select_most_precise<boost::rational<T>, double>
{
typedef typename boost::rational<T> type;
};
}} // namespace boost::geometry
// Specializes boost::rational to boost::numeric::bounds
namespace boost { namespace numeric
{
template<class T>
struct bounds<rational<T> >
{
static inline rational<T> lowest()
{
return rational<T>(bounds<T>::lowest(), 1);
}
static inline rational<T> highest()
{
return rational<T>(bounds<T>::highest(), 1);
}
};
}} // namespace boost::numeric
// Support for boost::numeric_cast to int and to double (necessary for SVG-mapper)
namespace boost { namespace numeric
{
template
<
typename T,
typename Traits,
typename OverflowHandler,
typename Float2IntRounder,
typename RawConverter,
typename UserRangeChecker
>
struct converter<int, rational<T>, Traits, OverflowHandler, Float2IntRounder, RawConverter, UserRangeChecker>
{
static inline int convert(rational<T> const& arg)
{
return int(rational_cast<double>(arg));
}
};
template
<
typename T,
typename Traits,
typename OverflowHandler,
typename Float2IntRounder,
typename RawConverter,
typename UserRangeChecker
>
struct converter<double, rational<T>, Traits, OverflowHandler, Float2IntRounder, RawConverter, UserRangeChecker>
{
static inline double convert(rational<T> const& arg)
{
return rational_cast<double>(arg);
}
};
}}
#endif // BOOST_GEOMETRY_UTIL_RATIONAL_HPP

View File

@@ -0,0 +1,17 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
This folder contains several headerfiles not fitting in one of the other folders,
or meta-functions which would fit into boost as a separate trait or utility,
such as add_const_if_c

View File

@@ -0,0 +1,57 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_SELECT_CALCULATION_TYPE_HPP
#define BOOST_GEOMETRY_UTIL_SELECT_CALCULATION_TYPE_HPP
#include <boost/mpl/if.hpp>
#include <boost/type_traits.hpp>
#include <boost/geometry/util/select_coordinate_type.hpp>
namespace boost { namespace geometry
{
/*!
\brief Meta-function selecting the "calculation" type
\details Based on two input geometry types, and an input calculation type,
(which defaults to void in the calling function), this meta-function
selects the most appropriate:
- if calculation type is specified, that one is used,
- if it is void, the most precise of the two points is used
\ingroup utility
*/
template <typename Geometry1, typename Geometry2, typename CalculationType>
struct select_calculation_type
{
typedef typename
boost::mpl::if_
<
boost::is_void<CalculationType>,
typename select_coordinate_type
<
Geometry1,
Geometry2
>::type,
CalculationType
>::type type;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_SELECT_CALCULATION_TYPE_HPP

View File

@@ -0,0 +1,45 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_SELECT_COORDINATE_TYPE_HPP
#define BOOST_GEOMETRY_UTIL_SELECT_COORDINATE_TYPE_HPP
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/util/select_most_precise.hpp>
namespace boost { namespace geometry
{
/*!
\brief Meta-function selecting the most precise coordinate type
of two geometries
\ingroup utility
*/
template <typename T1, typename T2>
struct select_coordinate_type
{
typedef typename select_most_precise
<
typename coordinate_type<T1>::type,
typename coordinate_type<T2>::type
>::type type;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_SELECT_COORDINATE_TYPE_HPP

View File

@@ -0,0 +1,162 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_SELECT_MOST_PRECISE_HPP
#define BOOST_GEOMETRY_UTIL_SELECT_MOST_PRECISE_HPP
#include <boost/mpl/if.hpp>
#include <boost/type_traits.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace select_most_precise
{
// At least one of the types is non-fundamental. Take that one.
// if both are non-fundamental, the type-to-be-selected
// is unknown, it should be defined by explicit specialization.
template <bool Fundamental1, bool Fundamental2, typename T1, typename T2>
struct select_non_fundamental
{
typedef T1 type;
};
template <typename T1, typename T2>
struct select_non_fundamental<true, false, T1, T2>
{
typedef T2 type;
};
template <typename T1, typename T2>
struct select_non_fundamental<false, true, T1, T2>
{
typedef T1 type;
};
// Selection of largest type (e.g. int of <short int,int>
// It defaults takes the first one, if second is larger, take the second one
template <bool SecondLarger, typename T1, typename T2>
struct select_largest
{
typedef T1 type;
};
template <typename T1, typename T2>
struct select_largest<true, T1, T2>
{
typedef T2 type;
};
// Selection of floating point and specializations:
// both FP or both !FP does never occur...
template <bool FP1, bool FP2, typename T1, typename T2>
struct select_floating_point
{
typedef char type;
};
// ... so if ONE but not both of these types is floating point, take that one
template <typename T1, typename T2>
struct select_floating_point<true, false, T1, T2>
{
typedef T1 type;
};
template <typename T1, typename T2>
struct select_floating_point<false, true, T1, T2>
{
typedef T2 type;
};
}} // namespace detail::select_most_precise
#endif // DOXYGEN_NO_DETAIL
/*!
\brief Meta-function to select, of two types, the most accurate type for
calculations
\ingroup utility
\details select_most_precise classes, compares two types on compile time.
For example, if an addition must be done with a double and an integer, the
result must be a double.
If both types are integer, the result can be an integer.
\note It is different from the "promote" class, already in boost. That
class promotes e.g. a (one) float to a double. This class selects a
type from two types. It takes the most accurate, but does not promote
afterwards.
\note This traits class is completely independant from GGL and might be a
separate addition to Boost
\note If the input is a non-fundamental type, it might be a calculation
type such as a GMP-value or another high precision value. Therefore,
if one is non-fundamental, that one is chosen.
\note If both types are non-fundamental, the result is indeterminate and
currently the first one is chosen.
*/
template <typename T1, typename T2>
struct select_most_precise
{
static const bool second_larger = sizeof(T2) > sizeof(T1);
static const bool one_not_fundamental = !
(boost::is_fundamental<T1>::type::value
&& boost::is_fundamental<T2>::type::value);
static const bool both_same =
boost::is_floating_point<T1>::type::value
== boost::is_floating_point<T2>::type::value;
typedef typename boost::mpl::if_c
<
one_not_fundamental,
typename detail::select_most_precise::select_non_fundamental
<
boost::is_fundamental<T1>::type::value,
boost::is_fundamental<T2>::type::value,
T1,
T2
>::type,
typename boost::mpl::if_c
<
both_same,
typename detail::select_most_precise::select_largest
<
second_larger,
T1,
T2
>::type,
typename detail::select_most_precise::select_floating_point
<
boost::is_floating_point<T1>::type::value,
boost::is_floating_point<T2>::type::value,
T1,
T2
>::type
>::type
>::type type;
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_SELECT_MOST_PRECISE_HPP

View File

@@ -0,0 +1,396 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_UTIL_WRITE_DSV_HPP
#define BOOST_GEOMETRY_UTIL_WRITE_DSV_HPP
#include <cstddef>
#include <ostream>
#include <string>
#include <boost/concept_check.hpp>
#include <boost/range.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/geometry/core/exterior_ring.hpp>
#include <boost/geometry/core/interior_rings.hpp>
#include <boost/geometry/core/ring_type.hpp>
#include <boost/geometry/core/tag_cast.hpp>
#include <boost/geometry/geometries/concepts/check.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace dsv
{
struct dsv_settings
{
std::string coordinate_separator;
std::string point_open;
std::string point_close;
std::string point_separator;
std::string list_open;
std::string list_close;
std::string list_separator;
dsv_settings(std::string const& sep
, std::string const& open
, std::string const& close
, std::string const& psep
, std::string const& lopen
, std::string const& lclose
, std::string const& lsep
)
: coordinate_separator(sep)
, point_open(open)
, point_close(close)
, point_separator(psep)
, list_open(lopen)
, list_close(lclose)
, list_separator(lsep)
{}
};
/*!
\brief Stream coordinate of a point as \ref DSV
*/
template <typename Point, std::size_t Dimension, std::size_t Count>
struct stream_coordinate
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Point const& point,
dsv_settings const& settings)
{
os << (Dimension > 0 ? settings.coordinate_separator : "")
<< get<Dimension>(point);
stream_coordinate
<
Point, Dimension + 1, Count
>::apply(os, point, settings);
}
};
template <typename Point, std::size_t Count>
struct stream_coordinate<Point, Count, Count>
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>&,
Point const&,
dsv_settings const& )
{
}
};
/*!
\brief Stream indexed coordinate of a box/segment as \ref DSV
*/
template
<
typename Geometry,
std::size_t Index,
std::size_t Dimension,
std::size_t Count
>
struct stream_indexed
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Geometry const& geometry,
dsv_settings const& settings)
{
os << (Dimension > 0 ? settings.coordinate_separator : "")
<< get<Index, Dimension>(geometry);
stream_indexed
<
Geometry, Index, Dimension + 1, Count
>::apply(os, geometry, settings);
}
};
template <typename Geometry, std::size_t Index, std::size_t Count>
struct stream_indexed<Geometry, Index, Count, Count>
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>&, Geometry const&,
dsv_settings const& )
{
}
};
/*!
\brief Stream points as \ref DSV
*/
template <typename Point>
struct dsv_point
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Point const& p,
dsv_settings const& settings)
{
os << settings.point_open;
stream_coordinate<Point, 0, dimension<Point>::type::value>::apply(os, p, settings);
os << settings.point_close;
}
};
/*!
\brief Stream ranges as DSV
\note policy is used to stream prefix/postfix, enabling derived classes to override this
*/
template <typename Range>
struct dsv_range
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Range const& range,
dsv_settings const& settings)
{
typedef typename boost::range_iterator<Range const>::type iterator_type;
bool first = true;
os << settings.list_open;
for (iterator_type it = boost::begin(range);
it != boost::end(range);
++it)
{
os << (first ? "" : settings.point_separator)
<< settings.point_open;
stream_coordinate
<
point_type, 0, dimension<point_type>::type::value
>::apply(os, *it, settings);
os << settings.point_close;
first = false;
}
os << settings.list_close;
}
private:
typedef typename boost::range_value<Range>::type point_type;
};
/*!
\brief Stream sequence of points as DSV-part, e.g. (1 2),(3 4)
\note Used in polygon, all multi-geometries
*/
template <typename Polygon>
struct dsv_poly
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Polygon const& poly,
dsv_settings const& settings)
{
typedef typename ring_type<Polygon>::type ring;
os << settings.list_open;
dsv_range<ring>::apply(os, exterior_ring(poly), settings);
typename interior_return_type<Polygon const>::type rings
= interior_rings(poly);
for (BOOST_AUTO_TPL(it, boost::begin(rings)); it != boost::end(rings); ++it)
{
os << settings.list_separator;
dsv_range<ring>::apply(os, *it, settings);
}
os << settings.list_close;
}
};
template <typename Geometry, std::size_t Index>
struct dsv_per_index
{
typedef typename point_type<Geometry>::type point_type;
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Geometry const& geometry,
dsv_settings const& settings)
{
os << settings.point_open;
stream_indexed
<
Geometry, Index, 0, dimension<Geometry>::type::value
>::apply(os, geometry, settings);
os << settings.point_close;
}
};
template <typename Geometry>
struct dsv_indexed
{
typedef typename point_type<Geometry>::type point_type;
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Geometry const& geometry,
dsv_settings const& settings)
{
os << settings.list_open;
dsv_per_index<Geometry, 0>::apply(os, geometry, settings);
os << settings.point_separator;
dsv_per_index<Geometry, 1>::apply(os, geometry, settings);
os << settings.list_close;
}
};
}} // namespace detail::dsv
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template <typename Tag, typename Geometry>
struct dsv {};
template <typename Point>
struct dsv<point_tag, Point>
: detail::dsv::dsv_point<Point>
{};
template <typename Linestring>
struct dsv<linestring_tag, Linestring>
: detail::dsv::dsv_range<Linestring>
{};
template <typename Box>
struct dsv<box_tag, Box>
: detail::dsv::dsv_indexed<Box>
{};
template <typename Segment>
struct dsv<segment_tag, Segment>
: detail::dsv::dsv_indexed<Segment>
{};
template <typename Ring>
struct dsv<ring_tag, Ring>
: detail::dsv::dsv_range<Ring>
{};
template <typename Polygon>
struct dsv<polygon_tag, Polygon>
: detail::dsv::dsv_poly<Polygon>
{};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace dsv
{
// FIXME: This class is not copyable/assignable but it is used as such --mloskot
template <typename Geometry>
class dsv_manipulator
{
public:
inline dsv_manipulator(Geometry const& g,
dsv_settings const& settings)
: m_geometry(g)
, m_settings(settings)
{}
template <typename Char, typename Traits>
inline friend std::basic_ostream<Char, Traits>& operator<<(
std::basic_ostream<Char, Traits>& os,
dsv_manipulator const& m)
{
dispatch::dsv
<
typename tag_cast
<
typename tag<Geometry>::type,
multi_tag
>::type,
Geometry
>::apply(os, m.m_geometry, m.m_settings);
os.flush();
return os;
}
private:
Geometry const& m_geometry;
dsv_settings m_settings;
};
}} // namespace detail::dsv
#endif // DOXYGEN_NO_DETAIL
/*!
\brief Main DSV-streaming function
\details DSV stands for Delimiter Separated Values. Geometries can be streamed
as DSV. There are defaults for all separators.
\note Useful for examples and testing purposes
\note With this function GeoJSON objects can be created, using the right
delimiters
\ingroup utility
*/
template <typename Geometry>
inline detail::dsv::dsv_manipulator<Geometry> dsv(Geometry const& geometry
, std::string const& coordinate_separator = ", "
, std::string const& point_open = "("
, std::string const& point_close = ")"
, std::string const& point_separator = ", "
, std::string const& list_open = "("
, std::string const& list_close = ")"
, std::string const& list_separator = ", "
)
{
concept::check<Geometry const>();
return detail::dsv::dsv_manipulator<Geometry>(geometry,
detail::dsv::dsv_settings(coordinate_separator,
point_open, point_close, point_separator,
list_open, list_close, list_separator));
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_UTIL_WRITE_DSV_HPP