[extensions] remove unused msm state and unused Boost.Unit example/header

This commit is contained in:
Barend Gehrels 2015-01-28 10:04:03 +01:00
parent 373f6cc24d
commit 486ed6605c
3 changed files with 0 additions and 531 deletions

View File

@ -1,210 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// 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)
//
// Example combining Boost.Geometry with Boost.Units
#include <iostream>
#include <boost/geometry/geometry.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/cgs/length.hpp>
#include <boost/units/systems/si/io.hpp>
// TEMPORARY this will go to somewhere within Boost.Geometry
namespace boost { namespace geometry
{
namespace cs
{
template <typename Unit>
struct units_cartesian {};
}
namespace traits
{
template<typename U>
struct cs_tag<cs::units_cartesian<U> >
{
typedef cartesian_tag type;
};
}
namespace model
{
// Define a point type to interoperate with Boost.Units, having
// 1. a constructor taking quantities
// 2. defining a quantified coordinate system
// Note that all values are still stored in "normal" types as double
template <typename U, std::size_t D = 2, typename T = double, typename CS = cs::units_cartesian<U> >
class quantity_point : public model::point<T, D, CS>
{
typedef boost::units::quantity<U, T> qtype;
public :
// Templated constructor to allow constructing with other units then qtype,
// e.g. to convert from centimeters to meters
template <typename Q>
inline quantity_point(Q const& x, Q const& y)
: model::point<T, D, CS>(
qtype(x).value(),
qtype(y).value())
{}
};
}
// Adapt quantity_point to the Point Concept
#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
namespace traits
{
template <typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct tag<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
{
typedef point_tag type;
};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct coordinate_type<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
{
typedef CoordinateType type;
};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct coordinate_system<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
{
typedef CoordinateSystem type;
};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct dimension<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
: boost::mpl::int_<DimensionCount>
{};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem, std::size_t Dimension>
struct access<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem>, Dimension >
{
static inline CoordinateType get(
model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> const& p)
{
return p.template get<Dimension>();
}
static inline void set(model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem>& p,
CoordinateType const& value)
{
p.template set<Dimension>(value);
}
};
} // namespace traits
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
// For extra support for functions as distance,area,get,set
namespace units
{
namespace detail
{
// Define an extra meta-function to get the units of a coordinate system
template <typename CS>
struct unit_dimension
{
// define it as dimensionless
// or MPL ASSERT
};
template <typename U>
struct unit_dimension<cs::units_cartesian<U> >
{
typedef U type;
};
}
// Define an extra metafunction to define the quantity of a Geometry type
template <typename Geometry, typename CT = typename coordinate_type<Geometry>::type>
struct quantity
{
typedef boost::units::quantity
<
typename detail::unit_dimension
<
typename coordinate_system<Geometry>::type
>::type,
CT
> type;
};
template <typename Geometry1, typename Geometry2>
inline typename quantity<Geometry1, typename default_distance_result<Geometry1, Geometry2>::type>::type
distance(Geometry1 const& g1, Geometry2 const& g2)
{
typedef typename quantity<Geometry1, typename default_distance_result<Geometry1, Geometry2>::type>::type q;
return q::from_value(geometry::distance(g1, g2));
}
template <std::size_t Index, typename Point>
inline typename quantity<Point>::type get(Point const& p)
{
typedef typename quantity<Point>::type q;
return q::from_value(geometry::get<Index>(p));
}
}
}}
// END TEMPORARY
int main(void)
{
using namespace boost::geometry;
using namespace boost::units;
// 1: using it directly
{
typedef model::quantity_point<si::length, 2> point;
point p1(1 * si::meter, 2 * si::meter);
point p2(3 * si::meter, 4 * si::meter);
std::cout << get<0>(p2) << std::endl;
// This is a little inconvenient:
quantity<si::length> d = distance(p1, p2) * si::meter;
std::cout << d << std::endl;
}
// 2: same but now using centimeters, and using boost::geometry::units::
{
typedef model::quantity_point<cgs::length, 2> point;
point p1(1 * si::meter, 2 * si::meter);
point p2(3 * si::meter, 4 * si::meter);
std::cout << boost::geometry::units::get<0>(p2) << std::endl;
quantity<cgs::length> d = boost::geometry::units::distance(p1, p2);
std::cout << d << std::endl;
}
return 0;
}

View File

@ -1,187 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, 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_ALGORITHMS_DETAIL_OVERLAY_MSM_STATE_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_MSM_STATE_HPP
#ifdef USE_MSM_MINI
# include <boost/msm/back/mini_state_machine.hpp>
# include <boost/fusion/include/vector.hpp>
#else
# include <boost/msm/back/state_machine.hpp>
# include <boost/msm/front/state_machine_def.hpp>
#endif
// Events
struct starting {};
struct visit {};
struct finish {};
// Flags
struct is_init {};
struct is_visited {};
enum StatesEnum
{
STATE_NONE=0,
STATE_IS_INIT=1,
STATE_IS_VISITED=2
};
#ifndef USE_MSM_MINI
// front-end: define the FSM structure
struct traverse_state_ : public boost::msm::front::state_machine_def<traverse_state_>
{
traverse_state_():m_state(STATE_IS_INIT){}
// The list of FSM states
struct Init : public boost::msm::front::state<>
{
typedef boost::mpl::vector1<is_init> flag_list;
//template <class Event,class FSM>
//void on_entry(Event const&,FSM& fsm) {fsm.m_state=STATE_IS_INIT;}
};
struct Started : public boost::msm::front::state<>
{
//template <class Event,class FSM>
//void on_entry(Event const&,FSM& fsm) {fsm.m_state=STATE_NONE;}
};
struct Visited : public boost::msm::front::state<>
{
typedef boost::mpl::vector1<is_visited> flag_list;
//template <class Event,class FSM>
//void on_entry(Event const&,FSM& fsm) {fsm.m_state=STATE_IS_VISITED;}
};
struct Finished : public boost::msm::front::state<>
{
typedef boost::mpl::vector1<is_visited> flag_list;
//template <class Event,class FSM>
//void on_entry(Event const&,FSM& fsm) {fsm.m_state=STATE_IS_VISITED;}
};
// the initial state of the player SM. Must be defined
typedef Init initial_state;
// transition actions
void start_traverse(starting const&) {m_state=STATE_NONE;}
void finish_after_visit(finish const&) {m_state=STATE_IS_VISITED;}
void do_finish(finish const&) {m_state=STATE_IS_VISITED;}
void do_visit(visit const&) {m_state=STATE_IS_VISITED;}
void do_visit2(visit const&) {m_state=STATE_IS_VISITED;}
void do_nothing(finish const&) {m_state=STATE_IS_VISITED;}
typedef traverse_state_ p; // makes transition table cleaner
// Transition table for player
struct transition_table : mpl::vector
<
// Start Event Next Action Guard
// +---------+-------------+---------+---------------------+----------------------+
a_row < Init , starting , Started , &p::start_traverse >,
a_row < Init , visit , Visited , &p::do_visit >,
a_row < Init , finish , Finished , &p::do_nothing >,
a_row < Started , finish , Finished , &p::do_finish >,
a_row < Started , visit , Visited , &p::do_visit2 >,
// +---------+-------------+---------+---------------------+----------------------+
a_row < Visited , finish , Finished , &p::finish_after_visit >
// +---------+-------------+---------+---------------------+----------------------+
> {};
// Replaces the default no-transition response.
template <class Machine, class Event>
void no_transition(Event const& e, Machine&, int state)
{
//std::cout << "no transition from state " << state << " on event " << typeid(e).name() << std::endl;
}
typedef int no_exception_thrown;
typedef int no_message_queue;
StatesEnum m_state;
};
typedef boost::msm::back::state_machine<traverse_state_> traverse_state;
#else
// mini-back-end
struct traverse_state : public boost::msm::back::mini::state_machine<traverse_state>
{
traverse_state():m_state(STATE_IS_INIT){}
// The list of FSM states
enum states
{
Init, Started, Visited, Finished
, initial_state = Init
};
friend class boost::msm::back::mini::state_machine<traverse_state>;
typedef traverse_state p; // makes transition table cleaner
// transition actions
void start_traverse(starting const&) {m_state=STATE_NONE;}
void finish_after_visit(finish const&) {m_state=STATE_IS_VISITED;}
void do_finish(finish const&) {m_state=STATE_IS_VISITED;}
void do_visit(visit const&) {m_state=STATE_IS_VISITED;}
void do_visit2(visit const&) {m_state=STATE_IS_VISITED;}
void do_nothing(finish const&) {m_state=STATE_IS_VISITED;}
bool flag_none() const { return m_state == STATE_IS_INIT; }
bool flag_visited() const { return m_state == STATE_IS_VISITED; }
// Transition table
struct transition_table : mpl::vector6<
// Start Event Next Action
// +---------+-------------+---------+---------------------+
row < Init , starting , Started , &p::start_traverse >,
row < Init , visit , Visited , &p::do_visit >,
row < Init , finish , Finished, &p::do_nothing >,
row < Started , finish , Finished, &p::do_finish >,
row < Started , visit , Visited , &p::do_visit2 >,
row < Visited , finish , Finished, &p::finish_after_visit>
// +---------+-------------+---------+---------------------+
> {};
// Replaces the default no-transition response.
template <class Event>
int no_transition(int state, Event const& e)
{
std::cout << "no transition from state " << state
<< " on event " << typeid(e).name() << std::endl;
return state;
}
StatesEnum m_state;
};
#endif
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_MSM_STATE_HPP

View File

@ -1,134 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 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_EXTENSIONS_GEOMETRIES_QUANTITY_POINT_HPP
#define BOOST_GEOMETRY_EXTENSIONS_GEOMETRIES_QUANTITY_POINT_HPP
#include <cstddef>
#include <boost/mpl/int.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/units/quantity.hpp>
namespace boost { namespace geometry
{
namespace cs
{
template <typename Unit>
struct units_cartesian {};
}
namespace traits
{
template<typename U>
struct cs_tag<cs::units_cartesian<U> >
{
typedef cartesian_tag type;
};
}
namespace model
{
// Define a point type to interoperate with Boost.Units, having
// 1. a constructor taking quantities
// 2. defining a quantified coordinate system
// Note that all values are still stored in "normal" types as double
template
<
typename Units,
std::size_t DimensionCount = 2,
typename CoordinateType = double,
typename CoordinateSystem = cs::units_cartesian<Units>
>
class quantity_point
: public model::point<CoordinateType, DimensionCount, CoordinateSystem>
{
typedef boost::units::quantity<Units, CoordinateType> qtype;
public :
// Templated constructor to allow constructing with other units then qtype,
// e.g. to convert from centimeters to meters
template <typename Quantity>
inline quantity_point(Quantity const& x, Quantity const& y)
: model::point<CoordinateType, DimensionCount, CoordinateSystem>(
qtype(x).value(),
qtype(y).value())
{}
};
}
// Adapt quantity_point to the Point Concept
#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
namespace traits
{
template <typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct tag<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
{
typedef point_tag type;
};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct coordinate_type<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
{
typedef CoordinateType type;
};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct coordinate_system<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
{
typedef CoordinateSystem type;
};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem>
struct dimension<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> >
: boost::mpl::int_<DimensionCount>
{};
template<typename Units, std::size_t DimensionCount, typename CoordinateType, typename CoordinateSystem, std::size_t Dimension>
struct access<model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem>, Dimension >
{
static inline CoordinateType get(
model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem> const& p)
{
return p.template get<Dimension>();
}
static inline void set(model::quantity_point<Units, DimensionCount, CoordinateType, CoordinateSystem>& p,
CoordinateType const& value)
{
p.template set<Dimension>(value);
}
};
} // namespace traits
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_EXTENSIONS_GEOMETRIES_QUANTITY_POINT_HPP