Wolframe, 0.0.3

intrusiveSerializer.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_SERLIALIZE_STRUCT_INTRUSIVE_SERIALIZER_HPP_INCLUDED
35 #define _Wolframe_SERLIALIZE_STRUCT_INTRUSIVE_SERIALIZER_HPP_INCLUDED
36 #include "filter/typedfilter.hpp"
37 #include "types/bignumber.hpp"
38 #include "types/datetime.hpp"
42 #include <string>
43 #include <vector>
44 #include <map>
45 #include <boost/cstdint.hpp>
46 
47 namespace _Wolframe {
48 namespace serialize {
49 
51 template <typename TYPE>
53 {
54  static bool fetch( Context& ctx, SerializeStateStack& stk);
55 };
56 
57 bool fetchCloseTag( Context& ctx, SerializeStateStack& stk);
58 
59 bool fetchOpenTag( Context& ctx, SerializeStateStack& stk);
60 
62 
63 typedef bool (*PrintValue)( const void* ptr, types::VariantConst& value);
64 
66 
67 typedef bool (*PrintValue)( const void* value, types::VariantConst& element);
68 
69 bool printValue_int64( const boost::int64_t*, types::VariantConst& element);
70 bool printValue_uint64( const boost::uint64_t*, types::VariantConst& element);
71 bool printValue_int32( const boost::int32_t*, types::VariantConst& element);
72 bool printValue_uint32( const boost::uint32_t*, types::VariantConst& element);
73 bool printValue_short( const signed short*, types::VariantConst& element);
74 bool printValue_ushort( const unsigned short*, types::VariantConst& element);
75 bool printValue_char( const signed char*, types::VariantConst& element);
76 bool printValue_uchar( const unsigned char*, types::VariantConst& element);
77 bool printValue_bool( const bool*, types::VariantConst& element);
78 bool printValue_float( const float*, types::VariantConst& element);
79 bool printValue_double( const double*, types::VariantConst& element);
80 bool printValue_string( const std::string*, types::VariantConst& element);
83 
84 typedef bool (*FetchElement)( Context& ctx, SerializeStateStack& stk);
85 
86 bool fetchObjectVectorElement( FetchElement fetchElement, const void* ve, Context& ctx, SerializeStateStack& stk);
87 
88 namespace {
89 template <typename TYPE> struct Printer {};
90 
91 template <> struct Printer<boost::int64_t>
92 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_int64( (const boost::int64_t*)value, element);}};
93 template <> struct Printer<boost::uint64_t>
94 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_uint64( (const boost::uint64_t*)value, element);}};
95 
96 template <> struct Printer<boost::int32_t>
97 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_int32( (const boost::int32_t*)value, element);}};
98 template <> struct Printer<boost::uint32_t>
99 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_uint32( (const boost::uint32_t*)value, element);}};
100 
101 template <> struct Printer<boost::int16_t>
102 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_short( (const boost::int16_t*)value, element);}};
103 template <> struct Printer<boost::uint16_t>
104 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_ushort( (const boost::uint16_t*)value, element);}};
105 
106 template <> struct Printer<signed char>
107 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_char( (const signed char*)value, element);}};
108 template <> struct Printer<unsigned char>
109 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_uchar( (const unsigned char*)value, element);}};
110 
111 template <> struct Printer<bool>
112 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_bool( (const bool*)value, element);}};
113 
114 template <> struct Printer<float>
115 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_float( (const float*)value, element);}};
116 
117 template <> struct Printer<double>
118 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_double( (const double*)value, element);}};
119 
120 template <> struct Printer<std::string>
121 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_string( (const std::string*)value, element);}};
122 
123 template <> struct Printer<types::DateTime>
124 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_datetime( (const types::DateTime*)value, element);}};
125 
126 template <> struct Printer<types::BigNumber>
127 {static bool printValue( const void* value, types::VariantConst& element) {return printValue_bignumber( (const types::BigNumber*)value, element);}};
128 
129 
130 template <typename TYPE>
131 static bool fetchObject_( const traits::struct_&, Context& ctx, SerializeStateStack& stk)
132 {
133  static const StructDescriptionBase* descr = TYPE::getStructDescription();
134  return fetchObjectStruct( descr, ctx, stk);
135 }
136 
137 template <typename TYPE>
138 static bool fetchObject_( const traits::atomic_&, Context& ctx, SerializeStateStack& stk)
139 {
140  return fetchObjectAtomic( Printer<TYPE>::printValue, ctx, stk);
141 }
142 
143 template <typename TYPE>
144 static bool fetchObject_( const traits::vector_&, Context& ctx, SerializeStateStack& stk)
145 {
146  const std::vector<typename TYPE::value_type>* obj = (const TYPE*)stk.back().value();
147  std::size_t idx = stk.back().state();
148  if (idx >= obj->size())
149  {
150  stk.pop_back();
151  return false;
152  }
153  const void* ve = &(*obj)[ idx];
154  return fetchObjectVectorElement( &IntrusiveSerializer<typename TYPE::value_type>::fetch, ve, ctx, stk);
155 }
156 }//anonymous namespace
157 
158 template <typename TYPE>
160 {
161  static TYPE* t = 0;
162  return fetchObject_<TYPE>( traits::getCategory(*t), ctx, stk);
163 }
164 
165 }}//namespace
166 #endif
bool fetchObjectStruct(const StructDescriptionBase *descr, Context &ctx, SerializeStateStack &stk)
bool fetchOpenTag(Context &ctx, SerializeStateStack &stk)
Type for representing arbitrary precision fixed point numbers and big integers as binary coded decima...
static bool fetch(Context &ctx, SerializeStateStack &stk)
Definition: intrusiveSerializer.hpp:159
bool printValue_double(const double *, types::VariantConst &element)
bool printValue_bool(const bool *, 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
bool printValue_short(const signed short *, types::VariantConst &element)
Type for representing big numbers as binary coded decimal (BCD) numbers.
Definition: bignumber.hpp:49
bool printValue_int32(const boost::int32_t *, types::VariantConst &element)
bool fetchObjectAtomic(PrintValue prnt, Context &ctx, SerializeStateStack &stk)
Data type for normalized date time (absolute time without time zone info)
Definition: datetime.hpp:55
bool printValue_string(const std::string *, types::VariantConst &element)
bool printValue_uint64(const boost::uint64_t *, types::VariantConst &element)
forward declaration
Definition: intrusiveSerializer.hpp:52
bool printValue(const ValueType &val, types::VariantConst &element)
Definition: printValue.hpp:178
bool fetchObjectVectorElement(FetchElement fetchElement, const void *ve, Context &ctx, SerializeStateStack &stk)
Defines the parsing stack for serialization of objects.
Variant value type that represents a variant copy without content ownership.
Definition: variant.hpp:286
bool printValue_int64(const boost::int64_t *, types::VariantConst &element)
bool printValue_bignumber(const types::BigNumber *, types::VariantConst &element)
bool(* PrintValue)(const void *ptr, types::VariantConst &value)
Definition: intrusiveSerializer.hpp:63
bool printValue_datetime(const types::DateTime *, types::VariantConst &element)
bool printValue_char(const signed char *, types::VariantConst &element)
Date and datetime value type.
bool(* FetchElement)(Context &ctx, SerializeStateStack &stk)
Definition: intrusiveSerializer.hpp:84
std::vector< SerializeState > SerializeStateStack
State stack for an iterator on a structure (serializer)
Definition: serializeStack.hpp:79
bool printValue_uchar(const unsigned char *, types::VariantConst &element)
bool fetchCloseTag(Context &ctx, SerializeStateStack &stk)
bool printValue_float(const float *, types::VariantConst &element)
Defines the non intrusive base class of serialization/deserialization of objects interfaced as TypedI...
Typed interface for input/output filter.
Global state variables of a running serialization/deserialization procedure (without the stack) ...
Definition: mapContext.hpp:46
bool printValue_uint32(const boost::uint32_t *, types::VariantConst &element)
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
bool printValue_ushort(const unsigned short *, types::VariantConst &element)