Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 #ifndef KEYVALUE_MNGT_BUILDERFROM_H_
00036 #define KEYVALUE_MNGT_BUILDERFROM_H_
00037
00038 #include <boost/static_assert.hpp>
00039
00040 #include "keyvalue/frontend/LexicalToolKit.h"
00041 #include "keyvalue/mngt/AbstractBuilder.h"
00042 #include "keyvalue/sys/exception/Exception.h"
00043 #include "keyvalue/util/IsBasic.h"
00044 #include "keyvalue/value/PtrTraits.h"
00045 #include "keyvalue/value/Variant.h"
00046
00047 namespace keyvalue {
00048
00074 #ifdef DOXYGEN
00075 template <typename ObjectType, typename InputType>
00076 class BuilderFrom {};
00077 #endif
00078
00079 template <typename ObjectType, typename InputType>
00080 class BuilderFrom;
00081
00091 template <typename ObjectType>
00092 class BuilderFrom<ObjectType, value::Variant> :
00093
00094 public AbstractBuilder {
00095
00096 public:
00097
00107 virtual typename value::PtrTraits<ObjectType>::Type_
00108 getObject(const value::Variant& data) const = 0;
00109
00110 };
00111
00112 template <typename ObjectType, typename InputType>
00113 class BuilderFrom :
00114
00115 public BuilderFrom<ObjectType, value::Variant> {
00116
00117 public:
00118
00119 typename value::PtrTraits<ObjectType>::Type_
00120 getObject(const value::Variant& data) const;
00121
00122 private:
00123
00134 virtual typename value::PtrTraits<ObjectType>::Type_
00135 getObject(const InputType& data) const = 0;
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 BOOST_STATIC_ASSERT(util::IsBasic<InputType>::value);
00146
00147 };
00148
00149
00150
00151
00152
00153 template <typename ObjectType, typename InputType>
00154 typename value::PtrTraits<ObjectType>::Type_
00155 BuilderFrom<ObjectType, InputType>::getObject(const value::Variant& data)
00156 const {
00157
00158 using frontend::LexicalToolKit;
00159
00160 if (data.is<InputType>(LexicalToolKit::input))
00161 return getObject(data.get<InputType>(LexicalToolKit::input));
00162
00163 throw RuntimeError() & "Builder '" & Processor::getName() & "' cannot "
00164 "build from input '" & data & "'!";
00165 }
00166
00167 }
00168
00169 #endif // KEYVALUE_MNGT_BUILDERFROM_H_