mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-20 14:18:22 +00:00
Added thirdparty: boost library
This commit is contained in:
+146
@@ -0,0 +1,146 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
Copyright (c) 2011 Bryce Lelbach
|
||||
|
||||
Distributed under 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)
|
||||
=============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_UTREE_DETAIL1)
|
||||
#define BOOST_SPIRIT_UTREE_DETAIL1
|
||||
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace detail
|
||||
{
|
||||
template <typename UTreeX, typename UTreeY>
|
||||
struct visit_impl;
|
||||
|
||||
struct index_impl;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Our POD double linked list. Straightforward implementation.
|
||||
// This implementation is very primitive and is not meant to be
|
||||
// used stand-alone. This is the internal data representation
|
||||
// of lists in our utree.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct list // keep this a POD!
|
||||
{
|
||||
struct node;
|
||||
|
||||
template <typename Value>
|
||||
class node_iterator;
|
||||
|
||||
void free();
|
||||
void copy(list const& other);
|
||||
void default_construct();
|
||||
|
||||
template <typename T, typename Iterator>
|
||||
void insert(T const& val, Iterator pos);
|
||||
|
||||
template <typename T>
|
||||
void push_front(T const& val);
|
||||
|
||||
template <typename T>
|
||||
void push_back(T const& val);
|
||||
|
||||
void pop_front();
|
||||
void pop_back();
|
||||
node* erase(node* pos);
|
||||
|
||||
node* first;
|
||||
node* last;
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// A range of utree(s) using an iterator range (begin/end) of node(s)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct range
|
||||
{
|
||||
list::node* first;
|
||||
list::node* last;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// A range of char*s
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct string_range
|
||||
{
|
||||
char const* first;
|
||||
char const* last;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// A void* plus type_info
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct void_ptr
|
||||
{
|
||||
void* p;
|
||||
std::type_info const* i;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Our POD fast string. This implementation is very primitive and is not
|
||||
// meant to be used stand-alone. This is the internal data representation
|
||||
// of strings in our utree. This is deliberately a POD to allow it to be
|
||||
// placed in a union. This POD fast string specifically utilizes
|
||||
// (sizeof(list) * alignment_of(list)) - (2 * sizeof(char)). In a 32 bit
|
||||
// system, this is 14 bytes. The two extra bytes are used by utree to store
|
||||
// management info.
|
||||
//
|
||||
// It is a const string (i.e. immutable). It stores the characters directly
|
||||
// if possible and only uses the heap if the string does not fit. Null
|
||||
// characters are allowed, making it suitable to encode raw binary. The
|
||||
// string length is encoded in the first byte if the string is placed in-situ,
|
||||
// else, the length plus a pointer to the string in the heap are stored.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct fast_string // Keep this a POD!
|
||||
{
|
||||
static std::size_t const
|
||||
buff_size = (sizeof(list) + boost::alignment_of<list>::value)
|
||||
/ sizeof(char);
|
||||
|
||||
static std::size_t const
|
||||
small_string_size = buff_size-sizeof(char);
|
||||
|
||||
static std::size_t const
|
||||
max_string_len = small_string_size - 3;
|
||||
|
||||
struct heap_store
|
||||
{
|
||||
char* str;
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
char buff[buff_size];
|
||||
long lbuff[buff_size / (sizeof(long)/sizeof(char))]; // for initialize
|
||||
heap_store heap;
|
||||
};
|
||||
|
||||
int get_type() const;
|
||||
void set_type(int t);
|
||||
bool is_heap_allocated() const;
|
||||
|
||||
std::size_t size() const;
|
||||
char const* str() const;
|
||||
|
||||
template <typename Iterator>
|
||||
void construct(Iterator f, Iterator l);
|
||||
|
||||
void swap(fast_string& other);
|
||||
void free();
|
||||
void copy(fast_string const& other);
|
||||
void initialize();
|
||||
|
||||
char& info();
|
||||
char info() const;
|
||||
|
||||
short tag() const;
|
||||
void tag(short tag);
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+1638
File diff suppressed because it is too large
Load Diff
+719
@@ -0,0 +1,719 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
Copyright (c) 2011 Bryce Lelbach
|
||||
|
||||
Distributed under 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)
|
||||
=============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_UTREE_OPERATORS)
|
||||
#define BOOST_SPIRIT_UTREE_OPERATORS
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4804)
|
||||
# pragma warning(disable: 4805)
|
||||
#endif
|
||||
|
||||
#include <exception>
|
||||
#if !defined(BOOST_SPIRIT_DISABLE_UTREE_IO)
|
||||
#include <ios>
|
||||
#include <boost/io/ios_state.hpp>
|
||||
#endif
|
||||
#include <boost/spirit/home/support/utree/utree.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
// Relational operators
|
||||
bool operator==(utree const& a, utree const& b);
|
||||
bool operator<(utree const& a, utree const& b);
|
||||
bool operator!=(utree const& a, utree const& b);
|
||||
bool operator>(utree const& a, utree const& b);
|
||||
bool operator<=(utree const& a, utree const& b);
|
||||
bool operator>=(utree const& a, utree const& b);
|
||||
|
||||
#if !defined(BOOST_SPIRIT_DISABLE_UTREE_IO)
|
||||
// output
|
||||
std::ostream& operator<<(std::ostream& out, utree const& x);
|
||||
std::ostream& operator<<(std::ostream& out, utree::invalid_type const& x);
|
||||
std::ostream& operator<<(std::ostream& out, utree::nil_type const& x);
|
||||
#endif
|
||||
|
||||
// Logical operators
|
||||
utree operator&&(utree const& a, utree const& b);
|
||||
utree operator||(utree const& a, utree const& b);
|
||||
utree operator!(utree const& a);
|
||||
|
||||
// Arithmetic operators
|
||||
utree operator+(utree const& a, utree const& b);
|
||||
utree operator-(utree const& a, utree const& b);
|
||||
utree operator*(utree const& a, utree const& b);
|
||||
utree operator/(utree const& a, utree const& b);
|
||||
utree operator%(utree const& a, utree const& b);
|
||||
utree operator-(utree const& a);
|
||||
|
||||
// Bitwise operators
|
||||
utree operator&(utree const& a, utree const& b);
|
||||
utree operator|(utree const& a, utree const& b);
|
||||
utree operator^(utree const& a, utree const& b);
|
||||
utree operator<<(utree const& a, utree const& b);
|
||||
utree operator>>(utree const& a, utree const& b);
|
||||
utree operator~(utree const& a);
|
||||
|
||||
// Implementation
|
||||
struct utree_is_equal
|
||||
{
|
||||
typedef bool result_type;
|
||||
|
||||
template <typename A, typename B>
|
||||
bool dispatch(const A&, const B&, boost::mpl::false_) const
|
||||
{
|
||||
return false; // cannot compare different types by default
|
||||
}
|
||||
|
||||
template <typename A, typename B>
|
||||
bool dispatch(const A& a, const B& b, boost::mpl::true_) const
|
||||
{
|
||||
return a == b; // for arithmetic types
|
||||
}
|
||||
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const
|
||||
{
|
||||
return dispatch(a, b,
|
||||
boost::mpl::and_<
|
||||
boost::is_arithmetic<A>,
|
||||
boost::is_arithmetic<B> >());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
// This code works for lists
|
||||
return a == b;
|
||||
}
|
||||
|
||||
template <typename Base, utree_type::info type_>
|
||||
bool operator()(
|
||||
basic_string<Base, type_> const& a,
|
||||
basic_string<Base, type_> const& b) const
|
||||
{
|
||||
return static_cast<Base const&>(a) == static_cast<Base const&>(b);
|
||||
}
|
||||
|
||||
bool operator()(utree::invalid_type, utree::invalid_type) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator()(utree::nil_type, utree::nil_type) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator()(function_base const&, function_base const&) const
|
||||
{
|
||||
return false; // just don't allow comparison of functions
|
||||
}
|
||||
};
|
||||
|
||||
struct utree_is_less_than
|
||||
{
|
||||
typedef bool result_type;
|
||||
|
||||
template <typename A, typename B>
|
||||
bool dispatch(const A&, const B&, boost::mpl::false_) const
|
||||
{
|
||||
return false; // cannot compare different types by default
|
||||
}
|
||||
|
||||
template <typename A, typename B>
|
||||
bool dispatch(const A& a, const B& b, boost::mpl::true_) const
|
||||
{
|
||||
return a < b; // for arithmetic types
|
||||
}
|
||||
|
||||
template <typename A, typename B>
|
||||
bool operator()(const A& a, const B& b) const
|
||||
{
|
||||
return dispatch(a, b,
|
||||
boost::mpl::and_<
|
||||
boost::is_arithmetic<A>,
|
||||
boost::is_arithmetic<B> >());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
// This code works for lists
|
||||
return a < b;
|
||||
}
|
||||
|
||||
template <typename Base, utree_type::info type_>
|
||||
bool operator()(
|
||||
basic_string<Base, type_> const& a,
|
||||
basic_string<Base, type_> const& b) const
|
||||
{
|
||||
return static_cast<Base const&>(a) < static_cast<Base const&>(b);
|
||||
}
|
||||
|
||||
bool operator()(utree::invalid_type, utree::invalid_type) const
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("no less-than comparison for this utree type",
|
||||
utree_type::invalid_type));
|
||||
BOOST_UNREACHABLE_RETURN(false) // no less than comparison for nil
|
||||
}
|
||||
|
||||
bool operator()(utree::nil_type, utree::nil_type) const
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("no less-than comparison for this utree type",
|
||||
utree_type::nil_type));
|
||||
BOOST_UNREACHABLE_RETURN(false) // no less than comparison for nil
|
||||
}
|
||||
|
||||
bool operator()(any_ptr const&, any_ptr const&) const
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("no less-than comparison for this utree type",
|
||||
utree_type::any_type));
|
||||
BOOST_UNREACHABLE_RETURN(false) // no less than comparison for any_ptr
|
||||
}
|
||||
|
||||
bool operator()(function_base const&, function_base const&) const
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("no less-than comparison for this utree type",
|
||||
utree_type::function_type));
|
||||
BOOST_UNREACHABLE_RETURN(false) // no less than comparison of functions
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(BOOST_SPIRIT_DISABLE_UTREE_IO)
|
||||
struct utree_print
|
||||
{
|
||||
typedef void result_type;
|
||||
|
||||
std::ostream& out;
|
||||
utree_print(std::ostream& out) : out(out) {}
|
||||
|
||||
void operator()(utree::invalid_type) const
|
||||
{
|
||||
out << "<invalid> ";
|
||||
}
|
||||
|
||||
void operator()(utree::nil_type) const
|
||||
{
|
||||
out << "<nil> ";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(T val) const
|
||||
{
|
||||
out << val << ' ';
|
||||
}
|
||||
|
||||
void operator()(bool b) const
|
||||
{
|
||||
out << (b ? "true" : "false") << ' ';
|
||||
}
|
||||
|
||||
void operator()(binary_range_type const& b) const
|
||||
{
|
||||
boost::io::ios_all_saver saver(out);
|
||||
out << "#";
|
||||
out.width(2);
|
||||
out.fill('0');
|
||||
|
||||
typedef binary_range_type::const_iterator iterator;
|
||||
for (iterator i = b.begin(); i != b.end(); ++i)
|
||||
out << std::hex << int((unsigned char)*i);
|
||||
out << "# ";
|
||||
}
|
||||
|
||||
void operator()(utf8_string_range_type const& str) const
|
||||
{
|
||||
typedef utf8_string_range_type::const_iterator iterator;
|
||||
iterator i = str.begin();
|
||||
out << '"';
|
||||
for (; i != str.end(); ++i)
|
||||
out << *i;
|
||||
out << "\" ";
|
||||
}
|
||||
|
||||
void operator()(utf8_symbol_range_type const& str) const
|
||||
{
|
||||
typedef utf8_symbol_range_type::const_iterator iterator;
|
||||
iterator i = str.begin();
|
||||
for (; i != str.end(); ++i)
|
||||
out << *i;
|
||||
out << ' ';
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
void operator()(boost::iterator_range<Iterator> const& range) const
|
||||
{
|
||||
typedef typename boost::iterator_range<Iterator>::const_iterator iterator;
|
||||
(*this)('(');
|
||||
for (iterator i = range.begin(); i != range.end(); ++i)
|
||||
{
|
||||
boost::spirit::utree::visit(*i, *this);
|
||||
}
|
||||
(*this)(')');
|
||||
}
|
||||
|
||||
void operator()(any_ptr const&) const
|
||||
{
|
||||
return (*this)("<pointer>");
|
||||
}
|
||||
|
||||
void operator()(function_base const&) const
|
||||
{
|
||||
return (*this)("<function>");
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template <typename Base>
|
||||
struct logical_function
|
||||
{
|
||||
typedef utree result_type;
|
||||
|
||||
// We assume anything except false is true
|
||||
|
||||
// binary
|
||||
template <typename A, typename B>
|
||||
utree operator()(A const& a, B const& b) const
|
||||
{
|
||||
return dispatch(a, b
|
||||
, boost::is_arithmetic<A>()
|
||||
, boost::is_arithmetic<B>());
|
||||
}
|
||||
|
||||
// binary
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const& a, B const& b, mpl::true_, mpl::true_) const
|
||||
{
|
||||
return Base::eval(a, b); // for arithmetic types
|
||||
}
|
||||
|
||||
// binary
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const&, B const& b, mpl::false_, mpl::true_) const
|
||||
{
|
||||
return Base::eval(true, b);
|
||||
}
|
||||
|
||||
// binary
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const& a, B const&, mpl::true_, mpl::false_) const
|
||||
{
|
||||
return Base::eval(a, true);
|
||||
}
|
||||
|
||||
// binary
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const&, B const&, mpl::false_, mpl::false_) const
|
||||
{
|
||||
return Base::eval(true, true);
|
||||
}
|
||||
|
||||
// unary
|
||||
template <typename A>
|
||||
utree operator()(A const& a) const
|
||||
{
|
||||
return dispatch(a, boost::is_arithmetic<A>());
|
||||
}
|
||||
|
||||
// unary
|
||||
template <typename A>
|
||||
utree dispatch(A const& a, mpl::true_) const
|
||||
{
|
||||
return Base::eval(a);
|
||||
}
|
||||
|
||||
// unary
|
||||
template <typename A>
|
||||
utree dispatch(A const&, mpl::false_) const
|
||||
{
|
||||
return Base::eval(true);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Base>
|
||||
struct arithmetic_function
|
||||
{
|
||||
typedef utree result_type;
|
||||
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const&, B const&, boost::mpl::false_) const
|
||||
{
|
||||
return utree(); // cannot apply to non-arithmetic types
|
||||
}
|
||||
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const& a, B const& b, boost::mpl::true_) const
|
||||
{
|
||||
return Base::eval(a, b); // for arithmetic types
|
||||
}
|
||||
|
||||
// binary
|
||||
template <typename A, typename B>
|
||||
utree operator()(A const& a, B const& b) const
|
||||
{
|
||||
return dispatch(a, b,
|
||||
boost::mpl::and_<
|
||||
boost::is_arithmetic<A>,
|
||||
boost::is_arithmetic<B> >());
|
||||
}
|
||||
|
||||
template <typename A>
|
||||
utree dispatch(A const&, boost::mpl::false_) const
|
||||
{
|
||||
return utree(); // cannot apply to non-arithmetic types
|
||||
}
|
||||
|
||||
template <typename A>
|
||||
utree dispatch(A const& a, boost::mpl::true_) const
|
||||
{
|
||||
return Base::eval(a); // for arithmetic types
|
||||
}
|
||||
|
||||
// unary
|
||||
template <typename A>
|
||||
utree operator()(A const& a) const
|
||||
{
|
||||
return dispatch(a, boost::is_arithmetic<A>());
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Base>
|
||||
struct integral_function
|
||||
{
|
||||
typedef utree result_type;
|
||||
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const&, B const&, boost::mpl::false_) const
|
||||
{
|
||||
return utree(); // cannot apply to non-integral types
|
||||
}
|
||||
|
||||
template <typename A, typename B>
|
||||
utree dispatch(A const& a, B const& b, boost::mpl::true_) const
|
||||
{
|
||||
return Base::eval(a, b); // for integral types
|
||||
}
|
||||
|
||||
// binary
|
||||
template <typename A, typename B>
|
||||
utree operator()(A const& a, B const& b) const
|
||||
{
|
||||
return dispatch(a, b,
|
||||
boost::mpl::and_<
|
||||
boost::is_integral<A>,
|
||||
boost::is_integral<B> >());
|
||||
}
|
||||
|
||||
template <typename A>
|
||||
utree dispatch(A const&, boost::mpl::false_) const
|
||||
{
|
||||
return utree(); // cannot apply to non-integral types
|
||||
}
|
||||
|
||||
template <typename A>
|
||||
utree dispatch(A const& a, boost::mpl::true_) const
|
||||
{
|
||||
return Base::eval(a); // for integral types
|
||||
}
|
||||
|
||||
// unary
|
||||
template <typename A>
|
||||
utree operator()(A const& a) const
|
||||
{
|
||||
return dispatch(a, boost::is_integral<A>());
|
||||
}
|
||||
};
|
||||
|
||||
#define BOOST_SPIRIT_UTREE_CREATE_FUNCTION_BINARY \
|
||||
template <typename Lhs, typename Rhs> \
|
||||
static utree eval(Lhs const& a, Rhs const& b) \
|
||||
/***/
|
||||
|
||||
#define BOOST_SPIRIT_UTREE_CREATE_FUNCTION_UNARY \
|
||||
template <typename Operand> \
|
||||
static utree eval(Operand const& a) \
|
||||
/***/
|
||||
|
||||
#define BOOST_SPIRIT_UTREE_CREATE_FUNCTION(arity, name, expr, base) \
|
||||
struct BOOST_PP_CAT(function_impl_, name) \
|
||||
{ \
|
||||
BOOST_SPIRIT_UTREE_CREATE_FUNCTION_##arity \
|
||||
{ \
|
||||
return utree(expr); \
|
||||
} \
|
||||
}; \
|
||||
base<BOOST_PP_CAT(function_impl_, name)> const \
|
||||
BOOST_PP_CAT(base, BOOST_PP_CAT(_, name)) = {}; \
|
||||
/***/
|
||||
|
||||
#define BOOST_SPIRIT_UTREE_CREATE_ARITHMETIC_FUNCTION(arity, name, expr) \
|
||||
BOOST_SPIRIT_UTREE_CREATE_FUNCTION(arity, name, expr, arithmetic_function)\
|
||||
/***/
|
||||
|
||||
#define BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION(arity, name, expr) \
|
||||
BOOST_SPIRIT_UTREE_CREATE_FUNCTION(arity, name, expr, integral_function) \
|
||||
/***/
|
||||
|
||||
#define BOOST_SPIRIT_UTREE_CREATE_LOGICAL_FUNCTION(arity, name, expr) \
|
||||
BOOST_SPIRIT_UTREE_CREATE_FUNCTION(arity, name, expr, logical_function) \
|
||||
/***/
|
||||
|
||||
inline bool operator==(utree const& a, utree const& b)
|
||||
{
|
||||
return utree::visit(a, b, utree_is_equal());
|
||||
}
|
||||
|
||||
inline bool operator<(utree const& a, utree const& b)
|
||||
{
|
||||
return utree::visit(a, b, utree_is_less_than());
|
||||
}
|
||||
|
||||
inline bool operator!=(utree const& a, utree const& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
inline bool operator>(utree const& a, utree const& b)
|
||||
{
|
||||
return b < a;
|
||||
}
|
||||
|
||||
inline bool operator<=(utree const& a, utree const& b)
|
||||
{
|
||||
return !(b < a);
|
||||
}
|
||||
|
||||
inline bool operator>=(utree const& a, utree const& b)
|
||||
{
|
||||
return !(a < b);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_SPIRIT_DISABLE_UTREE_IO)
|
||||
inline std::ostream& operator<<(std::ostream& out, utree const& x)
|
||||
{
|
||||
utree::visit(x, utree_print(out));
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, utree::invalid_type const&)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, utree::nil_type const&)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_SPIRIT_UTREE_CREATE_LOGICAL_FUNCTION(BINARY, and_, a&&b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_LOGICAL_FUNCTION(BINARY, or_, a||b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_LOGICAL_FUNCTION(UNARY, not_, !a)
|
||||
|
||||
BOOST_SPIRIT_UTREE_CREATE_ARITHMETIC_FUNCTION(BINARY, plus, a+b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_ARITHMETIC_FUNCTION(BINARY, minus, a-b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_ARITHMETIC_FUNCTION(BINARY, times, a*b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_ARITHMETIC_FUNCTION(BINARY, divides, a/b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION (BINARY, modulus, a%b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_ARITHMETIC_FUNCTION(UNARY, negate, -a)
|
||||
|
||||
BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION(BINARY, bitand_, a&b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION(BINARY, bitor_, a|b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION(BINARY, bitxor_, a^b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION(BINARY, shift_left, a<<b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION(BINARY, shift_right, a>>b)
|
||||
BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION(UNARY, invert, ~a)
|
||||
|
||||
// avoid `'~' on an expression of type bool` warning
|
||||
template <> inline utree function_impl_invert::eval<bool>(bool const& a)
|
||||
{
|
||||
return utree(!a);
|
||||
}
|
||||
|
||||
#undef BOOST_SPIRIT_UTREE_CREATE_FUNCTION_BINARY
|
||||
#undef BOOST_SPIRIT_UTREE_CREATE_FUNCTION_UNARY
|
||||
#undef BOOST_SPIRIT_UTREE_CREATE_FUNCTION
|
||||
#undef BOOST_SPIRIT_UTREE_CREATE_LOGICAL_FUNCTION
|
||||
#undef BOOST_SPIRIT_UTREE_CREATE_INTEGRAL_FUNCTION
|
||||
#undef BOOST_SPIRIT_UTREE_CREATE_ARITHMETIC_FUNCTION
|
||||
|
||||
inline utree operator&&(utree const& a, utree const& b)
|
||||
{
|
||||
return utree::visit(a, b, logical_function_and_);
|
||||
}
|
||||
|
||||
inline utree operator||(utree const& a, utree const& b)
|
||||
{
|
||||
return utree::visit(a, b, logical_function_or_);
|
||||
}
|
||||
|
||||
inline utree operator!(utree const& a)
|
||||
{
|
||||
return utree::visit(a, logical_function_not_);
|
||||
}
|
||||
|
||||
inline utree operator+(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, arithmetic_function_plus);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("addition performed on non-arithmetic utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator-(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, arithmetic_function_minus);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("subtraction performed on non-arithmetic utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator*(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, arithmetic_function_times);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("multiplication performed on non-arithmetic utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator/(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, arithmetic_function_divides);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("division performed on non-arithmetic utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator%(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, integral_function_modulus);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("modulos performed on non-integral utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator-(utree const& a)
|
||||
{
|
||||
utree r = utree::visit(a, arithmetic_function_negate);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("negation performed on non-arithmetic utree type",
|
||||
a.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator&(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, integral_function_bitand_);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("bitwise and performed on non-integral utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator|(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, integral_function_bitor_);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("bitwise or performed on non-integral utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator^(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, integral_function_bitxor_);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("bitwise xor performed on non-integral utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator<<(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, integral_function_shift_left);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("left shift performed on non-integral utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator>>(utree const& a, utree const& b)
|
||||
{
|
||||
utree r = utree::visit(a, b, integral_function_shift_right);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("right shift performed on non-integral utree types",
|
||||
a.which(), b.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
inline utree operator~(utree const& a)
|
||||
{
|
||||
utree r = utree::visit(a, integral_function_invert);
|
||||
if (r.which() == utree_type::invalid_type)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(bad_type_exception
|
||||
("inversion performed on non-integral utree type",
|
||||
a.which()));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}}
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+636
@@ -0,0 +1,636 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
Copyright (c) 2010-2011 Bryce Lelbach
|
||||
|
||||
Distributed under 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)
|
||||
=============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_UTREE)
|
||||
#define BOOST_SPIRIT_UTREE
|
||||
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <ios>
|
||||
#include <sstream>
|
||||
#include <typeinfo>
|
||||
|
||||
#include <boost/io/ios_state.hpp>
|
||||
#include <boost/integer.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/type_traits/remove_pointer.hpp>
|
||||
#include <boost/type_traits/is_polymorphic.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/spirit/home/support/utree/detail/utree_detail1.hpp>
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4804)
|
||||
# pragma warning(disable: 4805)
|
||||
# pragma warning(disable: 4244)
|
||||
#endif
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
//[utree_exceptions
|
||||
/*` All exceptions thrown by utree are derived from utree_exception. */
|
||||
struct BOOST_SYMBOL_VISIBLE utree_exception : std::exception {};
|
||||
|
||||
/*`The `bad_type_exception` is thrown whenever somebody calls a member
|
||||
function, which applies to certain stored utree_type's only, but this
|
||||
precondition is violated as the `utree` instance holds some other type.
|
||||
*/
|
||||
struct bad_type_exception /*: utree_exception*/;
|
||||
|
||||
/*`The `empty_exception` is thrown whenever a precondition of a list
|
||||
or range utree method is violated due to the list or range being empty.
|
||||
*/
|
||||
struct empty_exception /*: utree_exception*/;
|
||||
//]
|
||||
|
||||
//[utree_types
|
||||
/*`Each instance of an `utree` data structure can store exactly one of the
|
||||
following data types at a time:
|
||||
*/
|
||||
struct utree_type
|
||||
{
|
||||
enum info
|
||||
{
|
||||
invalid_type, // the utree has not been initialized (it's
|
||||
// default constructed)
|
||||
nil_type, // nil is the sentinel (empty) utree type.
|
||||
list_type, // A doubly linked list of utrees.
|
||||
range_type, // A range of list::iterators.
|
||||
reference_type, // A reference to another utree.
|
||||
any_type, // A pointer or reference to any C++ type.
|
||||
function_type, // A utree holding a stored_function<F> object,
|
||||
// where F is an unary function object taking a
|
||||
// utree as it's parameter and returning a
|
||||
// utree.
|
||||
|
||||
// numeric atoms
|
||||
bool_type, // An utree holding a boolean value
|
||||
int_type, // An utree holding a integer (int) value
|
||||
double_type, // An utree holding a floating point (double) value
|
||||
|
||||
// text atoms (utf8)
|
||||
string_type, // An UTF-8 string
|
||||
string_range_type, // A pair of iterators into an UTF-8 string
|
||||
symbol_type, // An UTF-8 symbol name
|
||||
|
||||
binary_type // Arbitrary binary data
|
||||
};
|
||||
typedef boost::uint_t<sizeof(info)*8>::exact exact_integral_type;
|
||||
typedef boost::uint_t<sizeof(info)*8>::fast fast_integral_type;
|
||||
};
|
||||
//]
|
||||
|
||||
// streaming operator for utree types - essential for diagnostics
|
||||
inline std::ostream& operator<<(std::ostream& out, utree_type::info t)
|
||||
{
|
||||
boost::io::ios_all_saver saver(out);
|
||||
switch (t) {
|
||||
case utree_type::invalid_type: { out << "invalid"; break; }
|
||||
case utree_type::nil_type: { out << "nil"; break; }
|
||||
case utree_type::list_type: { out << "list"; break; }
|
||||
case utree_type::range_type: { out << "range"; break; }
|
||||
case utree_type::reference_type: { out << "reference"; break; }
|
||||
case utree_type::any_type: { out << "any"; break; }
|
||||
case utree_type::function_type: { out << "function"; break; }
|
||||
case utree_type::bool_type: { out << "bool"; break; }
|
||||
case utree_type::int_type: { out << "int"; break; }
|
||||
case utree_type::double_type: { out << "double"; break; }
|
||||
case utree_type::string_type: { out << "string"; break; }
|
||||
case utree_type::string_range_type: { out << "string_range"; break; }
|
||||
case utree_type::symbol_type: { out << "symbol"; break; }
|
||||
case utree_type::binary_type: { out << "binary"; break; }
|
||||
default: { out << "unknown"; break; }
|
||||
}
|
||||
out << std::hex << "[0x"
|
||||
<< static_cast<utree_type::fast_integral_type>(t) << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
struct bad_type_exception : utree_exception
|
||||
{
|
||||
std::string msg;
|
||||
|
||||
bad_type_exception(char const* error, utree_type::info got)
|
||||
: msg()
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "utree: " << error
|
||||
<< " (got utree type '" << got << "')";
|
||||
msg = oss.str();
|
||||
}
|
||||
|
||||
bad_type_exception(char const* error, utree_type::info got1,
|
||||
utree_type::info got2)
|
||||
: msg()
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "utree: " << error
|
||||
<< " (got utree types '" << got1 << "' and '" << got2 << "')";
|
||||
msg = oss.str();
|
||||
}
|
||||
|
||||
virtual ~bad_type_exception() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
|
||||
virtual char const* what() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return msg.c_str(); }
|
||||
};
|
||||
|
||||
struct empty_exception : utree_exception
|
||||
{
|
||||
char const* msg;
|
||||
|
||||
empty_exception(char const* error) : msg(error) {}
|
||||
|
||||
virtual ~empty_exception() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
|
||||
virtual char const* what() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
{ return msg; }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// A typed string with parametric Base storage. The storage can be any
|
||||
// range or (stl container) of chars.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Base, utree_type::info type_>
|
||||
struct basic_string : Base
|
||||
{
|
||||
static utree_type::info const type = type_;
|
||||
|
||||
basic_string()
|
||||
: Base() {}
|
||||
|
||||
basic_string(Base const& base)
|
||||
: Base(base) {}
|
||||
|
||||
template <typename Iterator>
|
||||
basic_string(Iterator bits, std::size_t len)
|
||||
: Base(bits, bits + len) {}
|
||||
|
||||
template <typename Iterator>
|
||||
basic_string(Iterator first, Iterator last)
|
||||
: Base(first, last) {}
|
||||
|
||||
basic_string& operator=(Base const& other)
|
||||
{
|
||||
Base::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
//[utree_strings
|
||||
/*`The `utree` string types described below are used by the `utree` API
|
||||
only. These are not used to store information in the `utree` itself.
|
||||
Their purpose is to refer to different internal `utree` node types
|
||||
only. For instance, creating a `utree` from a binary data type will
|
||||
create a `binary_type` utree node (see above).
|
||||
*/
|
||||
/*`The binary data type can be represented either verbatim as a sequence
|
||||
of bytes or as a pair of iterators into some other stored binary data
|
||||
sequence. Use this string type to access/create a `binary_type` `utree`.
|
||||
*/
|
||||
typedef basic_string<
|
||||
boost::iterator_range<char const*>, utree_type::binary_type
|
||||
> binary_range_type;
|
||||
typedef basic_string<
|
||||
std::string, utree_type::binary_type
|
||||
> binary_string_type;
|
||||
|
||||
/*`The UTF-8 string can be represented either verbatim as a sequence of
|
||||
characters or as a pair of iterators into some other stored binary data
|
||||
sequence. Use this string type to access/create a `string_type` `utree`.
|
||||
*/
|
||||
typedef basic_string<
|
||||
boost::iterator_range<char const*>, utree_type::string_type
|
||||
> utf8_string_range_type;
|
||||
typedef basic_string<
|
||||
std::string, utree_type::string_type
|
||||
> utf8_string_type;
|
||||
|
||||
/*`The UTF-8 symbol can be represented either verbatim as a sequence of
|
||||
characters or as a pair of iterators into some other stored binary data
|
||||
sequence. Use this string type to access/create a `symbol_type` `utree`.
|
||||
*/
|
||||
typedef basic_string<
|
||||
boost::iterator_range<char const*>, utree_type::symbol_type
|
||||
> utf8_symbol_range_type;
|
||||
typedef basic_string<
|
||||
std::string, utree_type::symbol_type
|
||||
> utf8_symbol_type;
|
||||
//]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Our function type
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class utree;
|
||||
|
||||
//[utree_function_object_interface
|
||||
struct function_base
|
||||
{
|
||||
virtual ~function_base() {}
|
||||
virtual utree operator()(utree const& env) const = 0;
|
||||
virtual utree operator()(utree& env) const = 0;
|
||||
|
||||
// Calling f.clone() must return a newly allocated function_base
|
||||
// instance that is equal to f.
|
||||
virtual function_base* clone() const = 0;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
struct stored_function : function_base
|
||||
{
|
||||
F f;
|
||||
stored_function(F f = F());
|
||||
virtual ~stored_function();
|
||||
virtual utree operator()(utree const& env) const;
|
||||
virtual utree operator()(utree& env) const;
|
||||
virtual function_base* clone() const;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
struct referenced_function : function_base
|
||||
{
|
||||
F& f;
|
||||
referenced_function(F& f);
|
||||
virtual ~referenced_function();
|
||||
virtual utree operator()(utree const& env) const;
|
||||
virtual utree operator()(utree& env) const;
|
||||
virtual function_base* clone() const;
|
||||
};
|
||||
//]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Shallow tag. Instructs utree to hold an iterator_range
|
||||
// as-is without deep copying the range.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct shallow_tag {};
|
||||
shallow_tag const shallow = {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// A void* plus type_info
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
class any_ptr
|
||||
{
|
||||
public:
|
||||
template <typename Ptr>
|
||||
typename boost::disable_if<
|
||||
boost::is_polymorphic<
|
||||
typename boost::remove_pointer<Ptr>::type>,
|
||||
Ptr>::type
|
||||
get() const
|
||||
{
|
||||
if (*i == typeid(Ptr))
|
||||
{
|
||||
return static_cast<Ptr>(p);
|
||||
}
|
||||
boost::throw_exception(std::bad_cast());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
any_ptr(T* p)
|
||||
: p(p), i(&typeid(T*))
|
||||
{}
|
||||
|
||||
friend bool operator==(any_ptr const& a, any_ptr const& b)
|
||||
{
|
||||
return (a.p == b.p) && (*a.i == *b.i);
|
||||
}
|
||||
|
||||
private:
|
||||
// constructor is private
|
||||
any_ptr(void* p, std::type_info const* i)
|
||||
: p(p), i(i) {}
|
||||
|
||||
template <typename UTreeX, typename UTreeY>
|
||||
friend struct detail::visit_impl;
|
||||
|
||||
friend class utree;
|
||||
|
||||
void* p;
|
||||
std::type_info const* i;
|
||||
};
|
||||
|
||||
//[utree
|
||||
class utree {
|
||||
public:
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// The invalid type
|
||||
struct invalid_type {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// The nil type
|
||||
struct nil_type {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// The list type, this can be used to initialize an utree to hold an
|
||||
// empty list
|
||||
struct list_type;
|
||||
|
||||
//[utree_container_types
|
||||
typedef utree value_type;
|
||||
typedef utree& reference;
|
||||
typedef utree const& const_reference;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef std::size_t size_type;
|
||||
|
||||
typedef detail::list::node_iterator<utree> iterator;
|
||||
typedef detail::list::node_iterator<utree const> const_iterator;
|
||||
//]
|
||||
|
||||
typedef detail::list::node_iterator<boost::reference_wrapper<utree> >
|
||||
ref_iterator;
|
||||
|
||||
typedef boost::iterator_range<iterator> range;
|
||||
typedef boost::iterator_range<const_iterator> const_range;
|
||||
|
||||
// dtor
|
||||
~utree();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//[utree_initialization
|
||||
/*`A `utree` can be constructed or initialized from a wide range of
|
||||
data types, allowing to create `utree` instances for every
|
||||
possible node type (see the description of `utree_type::info` above).
|
||||
For this reason it exposes a constructor and an assignment operator
|
||||
for each of the allowed node types as shown below. All constructors
|
||||
are non-explicit on purpose, allowing to use an utree instance as
|
||||
the attribute to almost any Qi parser.
|
||||
*/
|
||||
// This constructs an `invalid_type` node. When used in places
|
||||
// where a boost::optional is expected (i.e. as an attribute for the
|
||||
// optional component), this represents the 'empty' state.
|
||||
utree(invalid_type = invalid_type());
|
||||
|
||||
// This initializes a `nil_type` node, which represents a valid,
|
||||
// 'initialized empty' utree (different from invalid_type!).
|
||||
utree(nil_type);
|
||||
reference operator=(nil_type);
|
||||
|
||||
// This initializes a `boolean_type` node, which can hold 'true' or
|
||||
// 'false' only.
|
||||
explicit utree(bool);
|
||||
reference operator=(bool);
|
||||
|
||||
// This initializes an `integer_type` node, which can hold arbitrary
|
||||
// integers. For convenience these functions are overloaded for signed
|
||||
// and unsigned integer types.
|
||||
utree(unsigned int);
|
||||
utree(int);
|
||||
reference operator=(unsigned int);
|
||||
reference operator=(int);
|
||||
|
||||
// This initializes a `double_type` node, which can hold arbitrary
|
||||
// floating point (double) values.
|
||||
utree(double);
|
||||
reference operator=(double);
|
||||
|
||||
// This initializes a `string_type` node, which can hold a narrow
|
||||
// character sequence (usually an UTF-8 string).
|
||||
utree(char);
|
||||
utree(char const*);
|
||||
utree(char const*, std::size_t);
|
||||
utree(std::string const&);
|
||||
reference operator=(char);
|
||||
reference operator=(char const*);
|
||||
reference operator=(std::string const&);
|
||||
|
||||
// This constructs a `string_range_type` node, which does not copy the
|
||||
// data but stores the iterator range to the character sequence the
|
||||
// range has been initialized from.
|
||||
utree(utf8_string_range_type const&, shallow_tag);
|
||||
|
||||
// This initializes a `reference_type` node, which holds a reference to
|
||||
// another utree node. All operations on such a node are automatically
|
||||
// forwarded to the referenced utree instance.
|
||||
utree(boost::reference_wrapper<utree>);
|
||||
reference operator=(boost::reference_wrapper<utree>);
|
||||
|
||||
// This initializes an `any_type` node, which can hold a pointer to an
|
||||
// instance of any type together with the typeid of that type. When
|
||||
// accessing that pointer the typeid will be checked, causing a
|
||||
// std::bad_cast to be thrown if the typeids do not match.
|
||||
utree(any_ptr const&);
|
||||
reference operator=(any_ptr const&);
|
||||
|
||||
// This initializes a `range_type` node, which holds an utree list node
|
||||
// the elements of which are copy constructed (assigned) from the
|
||||
// elements referenced by the given range of iterators.
|
||||
template <class Iterator>
|
||||
utree(boost::iterator_range<Iterator>);
|
||||
template <class Iterator>
|
||||
reference operator=(boost::iterator_range<Iterator>);
|
||||
|
||||
// This initializes a `function_type` node from a polymorphic function
|
||||
// object pointer (takes ownership) or reference.
|
||||
utree(function_base const&);
|
||||
reference operator=(function_base const&);
|
||||
utree(function_base*);
|
||||
reference operator=(function_base*);
|
||||
|
||||
// This initializes either a `string_type`, a `symbol_type`, or a
|
||||
// `binary_type` node (depending on the template parameter `type_`),
|
||||
// which will hold the corresponding narrow character sequence (usually
|
||||
// an UTF-8 string).
|
||||
template <class Base, utree_type::info type_>
|
||||
utree(basic_string<Base, type_> const&);
|
||||
template <class Base, utree_type::info type_>
|
||||
reference operator=(basic_string<Base, type_> const&);
|
||||
//]
|
||||
|
||||
// copy
|
||||
utree(const_reference);
|
||||
reference operator=(const_reference);
|
||||
|
||||
// range
|
||||
utree(range, shallow_tag);
|
||||
utree(const_range, shallow_tag);
|
||||
|
||||
// assign dispatch
|
||||
template <class Iterator>
|
||||
void assign(Iterator, Iterator);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// function object visitation interface
|
||||
|
||||
// single dispatch
|
||||
template <class F>
|
||||
typename boost::result_of<F(utree const&)>::type
|
||||
static visit(utree const&, F);
|
||||
|
||||
template <class F>
|
||||
typename boost::result_of<F(utree&)>::type
|
||||
static visit(utree&, F);
|
||||
|
||||
// double dispatch
|
||||
template <class F>
|
||||
typename boost::result_of<F(utree const&, utree const&)>::type
|
||||
static visit(utree const&, utree const&, F);
|
||||
|
||||
template <class F>
|
||||
typename boost::result_of<F(utree&, utree const&)>::type
|
||||
static visit(utree&, utree const&, F);
|
||||
|
||||
template <class F>
|
||||
typename boost::result_of<F(utree const&, utree&)>::type
|
||||
static visit(utree const&, utree&, F);
|
||||
|
||||
template <class F>
|
||||
typename boost::result_of<F(utree&, utree&)>::type
|
||||
static visit(utree&, utree&, F);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//[utree_container_functions
|
||||
// STL Container interface
|
||||
|
||||
// insertion
|
||||
template <class T>
|
||||
void push_back(T const&);
|
||||
template <class T>
|
||||
void push_front(T const&);
|
||||
template <class T>
|
||||
iterator insert(iterator, T const&);
|
||||
template <class T>
|
||||
void insert(iterator, std::size_t, T const&);
|
||||
template <class Iterator>
|
||||
void insert(iterator, Iterator, Iterator);
|
||||
|
||||
// erasure
|
||||
void pop_front();
|
||||
void pop_back();
|
||||
iterator erase(iterator);
|
||||
iterator erase(iterator, iterator);
|
||||
|
||||
// front access
|
||||
reference front();
|
||||
const_reference front() const;
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
ref_iterator ref_begin();
|
||||
|
||||
// back access
|
||||
reference back();
|
||||
const_reference back() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
ref_iterator ref_end();
|
||||
//]
|
||||
|
||||
// This clears the utree instance and resets its type to `invalid_type`
|
||||
void clear();
|
||||
|
||||
void swap(utree&);
|
||||
|
||||
bool empty() const;
|
||||
|
||||
size_type size() const;
|
||||
/*`[warning `size()` has O(n) complexity on `utree` ranges. On utree
|
||||
lists, it has O(1) complexity.]`*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//[utree_variant_functions
|
||||
// return the data type (`utree_type::info`) of the currently stored
|
||||
// data item
|
||||
utree_type::info which() const;
|
||||
|
||||
// access the currently stored data in a type safe manner, this will
|
||||
// throw a `std::bad_cast()` if the currently stored data item is not
|
||||
// default convertible to `T`.
|
||||
template <class T>
|
||||
T get() const;
|
||||
//]
|
||||
|
||||
reference deref();
|
||||
const_reference deref() const;
|
||||
|
||||
short tag() const;
|
||||
void tag(short);
|
||||
|
||||
utree eval(utree const&) const;
|
||||
utree eval(utree&) const;
|
||||
|
||||
utree operator() (utree const&) const;
|
||||
utree operator() (utree&) const;
|
||||
//<-
|
||||
protected:
|
||||
void ensure_list_type(char const* failed_in = "ensure_list_type()");
|
||||
|
||||
private:
|
||||
typedef utree_type type;
|
||||
|
||||
template <class UTreeX, class UTreeY>
|
||||
friend struct detail::visit_impl;
|
||||
friend struct detail::index_impl;
|
||||
|
||||
type::info get_type() const;
|
||||
void set_type(type::info);
|
||||
void free();
|
||||
void copy(const_reference);
|
||||
|
||||
union {
|
||||
detail::fast_string s;
|
||||
detail::list l;
|
||||
detail::range r;
|
||||
detail::string_range sr;
|
||||
detail::void_ptr v;
|
||||
bool b;
|
||||
int i;
|
||||
double d;
|
||||
utree* p;
|
||||
function_base* pf;
|
||||
};
|
||||
//->
|
||||
};
|
||||
//]
|
||||
|
||||
//[utree_tuple_interface
|
||||
/*<-*/inline/*->*/
|
||||
utree::reference get(utree::reference, utree::size_type);
|
||||
/*<-*/inline/*->*/
|
||||
utree::const_reference get(utree::const_reference, utree::size_type);
|
||||
/*`[warning `get()` has O(n) complexity.]`*/
|
||||
//]
|
||||
|
||||
struct utree::list_type : utree
|
||||
{
|
||||
using utree::operator=;
|
||||
|
||||
list_type() : utree() { ensure_list_type("list_type()"); }
|
||||
|
||||
template <typename T0>
|
||||
list_type(T0 t0) : utree(t0) {}
|
||||
|
||||
template <typename T0, typename T1>
|
||||
list_type(T0 t0, T1 t1) : utree(t0, t1) {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// predefined instances for singular types
|
||||
utree::invalid_type const invalid = {};
|
||||
utree::nil_type const nil = {};
|
||||
utree::list_type const empty_list = utree::list_type();
|
||||
}}
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+1294
File diff suppressed because it is too large
Load Diff
+24
@@ -0,0 +1,24 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
|
||||
Distributed under 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)
|
||||
=============================================================================*/
|
||||
#if !defined(BOOST_SPIRIT_OUTPUT_UTREE_TRAITS_FWD_FEB_14_2011_0632AM)
|
||||
#define BOOST_SPIRIT_OUTPUT_UTREE_TRAITS_FWD_FEB_14_2011_0632AM
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// forward declarations only
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
class utree;
|
||||
}}
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template <typename T>
|
||||
inline T get(boost::spirit::utree const& x);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user