Wolframe, 0.0.3

intrusiveParser.hpp
Go to the documentation of this file.
1 /************************************************************************
2 Copyright (C) 2011 - 2014 Project Wolframe.
3 All rights reserved.
4 
5 This file is part of Project Wolframe.
6 
7 Commercial Usage
8 Licensees holding valid Project Wolframe Commercial licenses may
9 use this file in accordance with the Project Wolframe
10 Commercial License Agreement provided with the Software or,
11 alternatively, in accordance with the terms contained
12 in a written agreement between the licensee and Project Wolframe.
13 
14 GNU General Public License Usage
15 Alternatively, you can redistribute this file and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19 
20 Wolframe is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
27 
28 If you have questions regarding the use of this file, please contact
29 Project Wolframe.
30 
31 ************************************************************************/
34 #ifndef _Wolframe_SERIALIZE_STRUCT_INTRUSIVE_PARSER_HPP_INCLUDED
35 #define _Wolframe_SERIALIZE_STRUCT_INTRUSIVE_PARSER_HPP_INCLUDED
36 #include "filter/typedfilter.hpp"
37 #include "types/variant.hpp"
38 #include "types/datetime.hpp"
39 #include "types/bignumber.hpp"
40 #include "types/customDataType.hpp"
45 #include <string>
46 #include <cstddef>
47 #include <boost/utility/value_init.hpp>
48 #include <boost/cstdint.hpp>
49 
50 namespace _Wolframe {
51 namespace serialize {
52 
54 template <typename TYPE>
56 {
57  static bool parse( langbind::TypedInputFilter& inp, Context& ctx, ParseStateStack& stk);
58 };
59 
61 
63 
64 typedef bool (*ParseValue)( void* value, const types::VariantConst& element);
65 
66 bool parseValue_int64( boost::int64_t* value, const types::VariantConst& element);
67 bool parseValue_uint64( boost::uint64_t* value, const types::VariantConst& element);
68 bool parseValue_int32( boost::int32_t* value, const types::VariantConst& element);
69 bool parseValue_uint32( boost::uint32_t* value, const types::VariantConst& element);
70 bool parseValue_short( signed short*, const types::VariantConst& element);
71 bool parseValue_ushort( unsigned short*, const types::VariantConst& element);
72 bool parseValue_char( signed char*, const types::VariantConst& element);
73 bool parseValue_uchar( unsigned char*, const types::VariantConst& element);
74 bool parseValue_bool( bool*, const types::VariantConst& element);
75 bool parseValue_float( float*, const types::VariantConst& element);
76 bool parseValue_double( double*, const types::VariantConst& element);
77 bool parseValue_string( std::string*, const types::VariantConst& element);
80 
82 
83 
84 namespace {
85 template <typename TYPE> struct Parser {};
86 
87 template <> struct Parser<boost::int64_t>
88 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_int64( (boost::int64_t*)value, element);}};
89 template <> struct Parser<boost::uint64_t>
90 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_uint64( (boost::uint64_t*)value, element);}};
91 
92 template <> struct Parser<boost::int32_t>
93 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_int32( (boost::int32_t*)value, element);}};
94 template <> struct Parser<boost::uint32_t>
95 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_uint32( (boost::uint32_t*)value, element);}};
96 
97 template <> struct Parser<boost::int16_t>
98 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_short( (boost::int16_t*)value, element);}};
99 template <> struct Parser<boost::uint16_t>
100 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_ushort( (boost::uint16_t*)value, element);}};
101 
102 template <> struct Parser<signed char>
103 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_char( (signed char*)value, element);}};
104 template <> struct Parser<unsigned char>
105 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_uchar( (unsigned char*)value, element);}};
106 
107 template <> struct Parser<float>
108 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_float( (float*)value, element);}};
109 
110 template <> struct Parser<bool>
111 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_bool( (bool*)value, element);}};
112 
113 template <> struct Parser<double>
114 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_double( (double*)value, element);}};
115 
116 template <> struct Parser<std::string>
117 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_string( (std::string*)value, element);}};
118 
119 template <> struct Parser<types::DateTime>
120 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_datetime( (types::DateTime*)value, element);}};
121 
122 template <> struct Parser<types::BigNumber>
123 {static bool parseValue( void* value, const types::VariantConst& element) {return parseValue_bignumber( (types::BigNumber*)value, element);}};
124 
125 template <typename TYPE>
126 bool parseObject_( const traits::struct_&, langbind::TypedInputFilter& inp, Context& ctx, ParseStateStack& stk)
127 {
128  return parseObjectStruct( TYPE::getStructDescription(), inp, ctx, stk);
129 }
130 
131 template <typename TYPE>
132 bool parseObject_( const traits::vector_&, langbind::TypedInputFilter&, Context&, ParseStateStack& stk)
133 {
134  if (stk.back().state())
135  {
136  stk.pop_back();
137  return true;
138  }
139  typedef typename TYPE::value_type Element;
140  boost::value_initialized<Element> val;
141  ((TYPE*)stk.back().value())->push_back( val);
142  stk.back().state( 1);
143  Element* ee = &((TYPE*)stk.back().value())->back();
144  if (IntrusiveProperty<Element>::type() == StructDescriptionBase::Atomic)
145  {
146  stk.push_back( ParseState( 0, &parseAtomicElementEndTag, 0));
147  }
148  stk.push_back( ParseState( 0, &IntrusiveParser<Element>::parse, ee));
149  return true;
150 }
151 
152 template <typename TYPE>
153 static bool parseObject_( const traits::atomic_&, langbind::TypedInputFilter& inp, Context& ctx, ParseStateStack& stk)
154 {
155  return parseObjectAtomic( Parser<TYPE>::parseValue, inp, ctx, stk);
156 }
157 
158 }//anonymous namespace
159 
160 
161 template <typename TYPE>
163 {
164  static TYPE* t = 0;
165  return parseObject_<TYPE>( traits::getCategory(*t), inp, ctx, stk);
166 }
167 
168 }}//namespace
169 #endif
170 
State stack for an initializer of a structure.
Definition: parseStack.hpp:80
bool parseValue_uint64(boost::uint64_t *value, const types::VariantConst &element)
bool parseObjectAtomic(ParseValue parseVal, langbind::TypedInputFilter &inp, Context &, ParseStateStack &stk)
Atomic element type.
Definition: structDescriptionBase.hpp:58
Type for representing arbitrary precision fixed point numbers and big integers as binary coded decima...
bool parseValue_bool(bool *, const types::VariantConst &element)
bool parseValue_int32(boost::int32_t *value, const types::VariantConst &element)
defines the type traits for the intrusive part of serialization/deserialization
Base class for structure description used for introspection in serialization/deserialization.
Definition: structDescriptionBase.hpp:51
Custom data type interface for variant.
bool parseAtomicElementEndTag(langbind::TypedInputFilter &inp, Context &, ParseStateStack &stk)
Type for representing big numbers as binary coded decimal (BCD) numbers.
Definition: bignumber.hpp:49
forward declaration
Definition: intrusiveParser.hpp:55
bool parseValue_ushort(unsigned short *, const types::VariantConst &element)
bool(* ParseValue)(void *value, const types::VariantConst &element)
Definition: intrusiveParser.hpp:64
Data type for normalized date time (absolute time without time zone info)
Definition: datetime.hpp:55
bool parseValue_float(float *, const types::VariantConst &element)
bool parseValue_string(std::string *, const types::VariantConst &element)
bool parseValue_uchar(unsigned char *, const types::VariantConst &element)
Variant value type that represents a variant copy without content ownership.
Definition: variant.hpp:286
bool parseValue_datetime(types::DateTime *, const types::VariantConst &element)
Variant value type.
bool parseValue_double(double *, const types::VariantConst &element)
bool parseValue_char(signed char *, const types::VariantConst &element)
Defines the parsing stack for deserialization.
Defines the intrusive implementation of some parsing element properties.
Date and datetime value type.
static bool parse(langbind::TypedInputFilter &inp, Context &ctx, ParseStateStack &stk)
Definition: intrusiveParser.hpp:162
bool parseValue_uint32(boost::uint32_t *value, const types::VariantConst &element)
bool parseObjectStruct(const StructDescriptionBase *descr, langbind::TypedInputFilter &inp, Context &ctx, ParseStateStack &stk)
bool parseValue_int64(boost::int64_t *value, const types::VariantConst &element)
Defines the non intrusive base class of serialization/deserialization of objects interfaced as TypedI...
bool parseValue_short(signed short *, const types::VariantConst &element)
bool parseValue_bignumber(types::BigNumber *, const types::VariantConst &element)
Typed interface for input/output filter.
Global state variables of a running serialization/deserialization procedure (without the stack) ...
Definition: mapContext.hpp:46
Input filter with atomic values having a type.
Definition: typedfilter.hpp:48
bool parseValue(ValueType &val, const types::VariantConst &element)
Definition: parseValue.hpp:405
boost::enable_if_c< boost::is_same< std::vector< typename T::value_type >,T >::value &&!boost::is_same< std::string, T >::value,const vector_ & >::type getCategory(const T &)
get category vector_ for a type
Definition: traits_getCategory.hpp:90