48 #ifndef _MIRA_METASERIALIZER_H_ 49 #define _MIRA_METASERIALIZER_H_ 53 #include <type_traits> 61 #include <serialization/adapters/boost/optional.hpp> 62 #include <serialization/adapters/std/list> 63 #include <serialization/adapters/std/vector> 70 namespace serialization {
99 typedef std::vector<uint8> Base;
147 template<
typename Reflector>
151 r.member(
"Identifier", mIdentifier,
"The identifier of the class " 152 "or 'complex' atomic type");
153 r.member(
"Version", mVersion,
"The metatype format version", 2);
156 template<
typename BinaryStream>
160 r.
member(
"Identifier", mPlainIdentifier,
"The identifier of the class " 164 mIdentifier += mPlainIdentifier +
" @v0";
166 mIdentifier = mPlainIdentifier;
170 template<
typename BinaryStream>
174 r.
member(
"Identifier", mPlainIdentifier,
"The identifier of the class " 183 assert(Base::size()>=1);
184 push_back(qualifier);
192 assert(Base::size()==0);
206 template <
typename T>
213 assert(Base::size()==0);
215 mIdentifier = identifier;
216 mPlainIdentifier = mIdentifier;
223 template <
typename T>
237 return (
Type)front();
244 return Base::size()>1;
251 return std::max(
size()-1,0);
274 return Base::resize(
size()-n);
298 int size()
const {
return (
int)Base::size(); }
304 std::string mIdentifier;
305 std::string mPlainIdentifier;
324 const std::string& iName,
325 const std::string& iDescription) :
330 template<
typename Reflector>
333 r.member(
"Type",
type,
"The meta type info of the parameter");
334 r.member(
"Name",
name,
"The name of the parameter");
335 r.member(
"Description",
description,
"The description for the parameter");
348 const std::string& iComment) :
352 template<
typename Reflector>
355 r.member(
"Name",
name,
"The name of the method");
356 r.member(
"Comment",
comment,
"The user defined comment");
357 r.member(
"ReturnType",
returnType,
"The meta type info of the return type");
358 r.member(
"Parameters",
parameters,
"A list with type infos for each parameter");
389 template<
typename Reflector>
392 r.member(
"Type",
type,
"The type of the member");
393 r.member(
"Name",
name,
"The name of the member");
394 r.member(
"Comment",
comment,
"The user defined comment");
407 template<
typename Reflector>
413 boost::optional<int> optVersion;
414 r.member(
"Version",optVersion,
"The version of the serialization format");
419 r.member(
"Version",
version,
"The version of the serialization format");
421 r.member(
"Members",
members,
"The members of the compound");
422 r.member(
"Interfaces",
interfaces,
"The supported interfaces");
423 r.member(
"Methods",
methods,
"The reflected methods");
426 template<
typename BinaryStream>
430 boost::optional<int> optVersion;
432 optVersion =
version.cbegin()->second;
435 r.
member(
"Version",optVersion,
"The version of the serialization format");
459 std::list<Member>::iterator pos =
members.begin();
460 while ((pos !=
members.end()) && (index-- > 0))
467 std::list<Member>::iterator pos =
members.begin();
468 while ((pos !=
members.end()) && (pos->name != before))
511 typedef std::map<std::string, CompoundMetaPtr> Base;
519 Base::operator=(other);
523 template<
typename Reflector>
529 template<
typename BinaryStream>
536 foreach (
auto p, *
this)
537 db[p.first+
" @v0"] = p.second;
543 template<
typename BinaryStream>
547 foreach (
auto p, *
this) {
549 size_t s = p.first.size();
550 if (p.first.substr(s-4, std::string::npos) ==
" @v0")
551 db[p.first.substr(0, s-4)] = p.second;
554 r.template reflectBase<Base>(db);
562 this->insert(other.begin(), other.end());
572 generateDependentTypesDB(
type, db);
607 #ifdef CHECK_FORCE_SERIALIZE_BINARY_VERSION 609 if ((vf >= 0) && (vf < BinaryBufferSerializer::getSerializerFormatVersion()))
627 catch(XNotImplemented&)
638 const std::string& versionString) {
650 bool acceptDesiredVersion =
false) {
658 template <
typename T>
660 return this->
version(version, typeName<T>(),
false);
673 template <
typename T>
675 return this->
version(version, typeName<T>(),
true);
699 template <
typename T>
700 void write(
const T* data, std::size_t count) {
709 template <
typename T>
721 template <
typename T>
729 assert(name != NULL);
741 template<
typename R,
typename... Args,
typename F,
typename... Description>
743 method(
const char*, F&&, Description&&...)
748 template<
typename F,
typename... Description>
750 method(
const char*, F&&, Description&&...)
755 template<
typename R,
typename Class,
typename... Args,
typename... Description>
762 template<
typename R,
typename Class,
typename... Args,
typename... Description>
769 template<
typename R,
typename... Args,
typename F,
typename... Description>
771 method(
const char* name, F&& fn, Description&&... descriptions)
774 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
777 template<
typename F,
typename... Description>
779 method(
const char* name, F&& fn, Description&&... descriptions)
781 concreteMethodMetaHelper<typename Private::FunctionTraits<F>::ReturnValue>(
783 std::forward<Description>(descriptions)...);
786 template<
typename R,
typename Class,
typename... Args,
typename... Description>
790 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
793 template<
typename R,
typename Class,
typename... Args,
typename... Description>
798 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
805 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
816 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
827 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
842 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
870 static const std::string context =
"invokeOverwrite " + typeName<T>();
884 static const std::string context =
"invokeOverwrite PlainArray<" + typeName<T>() +
">";
890 collectionItems<T>(
"@itemcount",
true);
902 const std::string& n =
type->getIdentifier();
919 template<
typename T,
bool>
945 template<
typename T,
bool>
970 template <
typename T>
1002 template<
typename T>
1006 return createMeta<Type>();
1011 template<
typename T>
1014 return createMeta<T>();
1024 template<
typename R,
typename... Args,
typename... Description>
1026 Description&&... descriptions)
1028 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
1031 template<
typename R,
typename ... Args,
typename Comment,
typename ...Descriptions>
1035 m->returnType = createMetaOrVoidHelper<R>();
1036 addParameterDescription<Args...>(*m, std::forward<Descriptions>(args)...);
1041 template<
typename... RECURSIONSTOP>
1042 typename std::enable_if<(
sizeof...(RECURSIONSTOP)) == 0>
::type addParameterDescription(
MethodMeta& m)
1046 template<
typename ParameterType,
typename... Args>
1047 void addParameterDescription(MethodMeta& m)
1049 m.parameters.push_back(MethodMeta::Parameter(createMetaHelper<ParameterType>()));
1050 addParameterDescription<Args...>(m);
1053 template<
typename ParameterType,
typename... Args,
class Name,
class Description,
typename... Tail,
1054 typename =
typename std::enable_if<(
sizeof...(Args)) * 2 ==
sizeof...(Tail)>::
type>
1055 void addParameterDescription(MethodMeta& m, Name&& name, Description&& description, Tail&&... tail)
1057 m.parameters.push_back(MethodMeta::Parameter(createMetaHelper<ParameterType>(),
1058 std::forward<Name>(name),
1059 std::forward<Description>(description)));
1060 addParameterDescription<Args...>(m, std::forward<Tail>(tail)...);
1063 template<
typename ParameterType,
typename... Args,
class Name,
class Description,
class Example,
1065 typename =
typename std::enable_if<(
sizeof...(Args)) * 3 ==
sizeof...(Tail)>::
type>
1066 void addParameterDescription(MethodMeta& m, Name&& name, Description&& description, Example&& example,
1069 m.parameters.push_back(MethodMeta::Parameter(createMetaHelper<ParameterType>(),
1070 std::forward<Name>(name),
1071 std::forward<Description>(description)));
1072 addParameterDescription<Args...>(m, std::forward<Tail>(tail)...);
1079 template<
typename T>
1087 template<
typename T>
1095 template<
typename T>
1099 Base::property<T>(name,
member,
setter,comment,std::move(hint), flags);
1103 template<
typename T>
1111 template<
typename T,
typename U>
1119 template<
typename T,
typename U>
1121 const char* comment,
const U& defaultValue,
1128 template<
typename T,
typename U>
1130 const char* comment,
const U& defaultValue,
1137 template<
typename T>
1147 template<
typename T>
1156 template<
typename T>
1165 template<
typename T>
1175 mParentMeta->members.back().name =
"@items_blockdump";
1202 template<
typename T>
1205 template<
typename T>
1206 class IsTransparentSerializableHelper<serialization::PlainArray<T>, MetaSerializer> :
public std::true_type {};
1208 namespace serialization {
1220 template<
typename Container>
1221 struct ReflectCollectionItems<MetaSerializer, Container>
1223 static void reflect(MetaSerializer& r, Container& c)
1225 typedef typename Container::value_type rawtype;
1228 r.template collectionItems<type>(
"@itemcount");
1232 template<
typename Allocator>
1233 struct ReflectReadBoolVectorItems<MetaSerializer, Allocator>
1235 static void reflect(MetaSerializer& r, std::vector<bool, Allocator>& c)
1237 r.template collectionItems<bool>(
"@itemcount");
1241 template<
typename Container>
1242 struct ReflectReadSetItems<MetaSerializer, Container>
1244 typedef typename Container::value_type rawtype;
1247 static void reflect(MetaSerializer& r, Container& c)
1249 r.template collectionItems<type>(
"@itemcount");
1253 template<
typename Container>
1254 struct ReflectReadMapItems<MetaSerializer, Container>
1256 typedef typename Container::key_type rawkeytype;
1257 typedef typename Container::mapped_type rawmappedtype;
1261 static void reflect(MetaSerializer& r, Container& c)
1263 r.template collectionItems<type>(
"@itemcount");
This object can use object tracking internally, but the object tracking system's state remains unchan...
Definition: ReflectControlFlags.h:82
boost::shared_ptr< CompoundMeta > CompoundMetaPtr
Definition: MetaSerializer.h:503
Definition: BinarySerializer.h:316
void object(T &member)
Is called for each complex object.
Definition: RecursiveMemberReflector.h:385
Definition: RPCPatternCheck.h:82
Class for in place stream formatting.
void invokeOverwrite(T &object)
The actual invoke implementation, that may also be overwritten in derived classes to add additional f...
Definition: AbstractReflector.h:271
void popObjectTrackingStore()
Definition: Serializer.h:452
static void reflect(Reflector &r, Container &c)
Definition: StlCollections.h:142
typename ReflectorInterface< MetaSerializer >::AcceptDesiredVersion AcceptDesiredVersion
Definition: AbstractReflector.h:195
Type trait that indicates whether a type can be serialized bitwise by just copying the data buffer...
Definition: IsBitwiseSerializable.h:70
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:947
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
Class object which supports some kind of class reflection.
Definition: Class.h:97
Setter< T > setter(void(*f)(const T &))
Creates a Setter for global or static class methods taking the argument by const reference.
Definition: GetterSetter.h:443
Definition: BinarySerializer.h:980
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
Type trait that indicates whether a type can be serialized as an atomic value.
Definition: IsAtomicSerializable.h:85
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:1049
void serialize(const std::string &name, const T &value, const std::string &comment="")
Serializes the specified object value under the given name.
Definition: Serializer.h:204
uint8 VersionType
Definition: ReflectorInterface.h:72
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
Type trait to check if a class is default constructible.
A property hint gives optional instructions to the property editor, i.e.
Definition: PropertyHint.h:83
MetaSerializer * This()
"Curiously recurring template pattern" (CRTP).
Definition: AbstractReflector.h:246
const ReflectMemberMeta & getCurrentMemberMeta() const
Returns the meta-information of the current member that is reflected.
Definition: RecursiveMemberReflector.h:543
Binary serializer and deserializer.
static void reflect(Reflector &r, Container &c)
Definition: StlCollections.h:343
No flags.
Definition: ReflectControlFlags.h:65
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:296
Container::value_type type
Definition: ReflectCollection.h:87
Getter< T > getter(T(*f)())
Creates a Getter for global or static class methods returning the result by value.
Definition: GetterSetter.h:136
void reflect(Reflector &r, LogRecord &record)
Non-intrusive reflector for LogRecord.
Definition: LoggingCore.h:137
static void reflect(Reflector &r, Container &c)
Definition: ReflectCollection.h:89
boost::shared_ptr< TypeMeta > TypeMetaPtr
Definition: MetaSerializer.h:309
void pushObjectTrackingStore()
Definition: Serializer.h:447
typename std::enable_if< Private::rpc::isValid< F, Description... >()>::type ValidRPCDescription
Definition: RPCPatternCheck.h:307
typename std::enable_if<!Private::rpc::isValid< F, Description... >()>::type InvalidRPCDescription
Definition: RPCPatternCheck.h:310
VersionType version(VersionType version, const T *caller=NULL)
Definition: BinarySerializer.h:609
static int forcedSerializeVersion()
Returns either the version number from value of environment variable 'MIRA_FORCE_SERIALIZE_VERSION', or -1 (= do not force a version).
Definition: Serializer.h:145
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
Definition: RPCPatternCheck.h:88
void pointer(T *&pointer)
Definition: Serializer.h:232
void invokeMember(T &member, const ReflectMemberMeta &meta)
Is called to invoke this Reflector on the member with the specified meta information.
Definition: RecursiveMemberReflector.h:738
Definition: BinarySerializer.h:257
static constexpr auto MIRA_REFLECTOR_TOPLEVEL_NAME
Use this when a reflector needs to choose a name for serializing an object.
Definition: RecursiveMemberReflector.h:333
ReflectCtrlFlags
Control Flags that can modify the behavior of certain reflectors.
Definition: ReflectControlFlags.h:63
Type trait that indicates whether a type is a collection.
Definition: IsCollection.h:63
Definition: IsTransparentSerializable.h:84
Accessor< Getter, Setter > makeAccessor(const Getter &getter, const Setter &setter)
Helper method that creates an accessor from a different combination of either direct access to a vari...
Definition: Accessor.h:300
void invoke(T &object)
Invokes this reflector on the specified object.
Definition: AbstractReflector.h:259
VersionType queryDesiredClassVersion(VersionType version, const std::string &type, bool acceptDesiredVersion=false)
Definition: Serializer.h:162
constexpr std::enable_if<!FunctionTraits< F >::isFunction >::type invalidAssertion()
Definition: RPCPatternCheck.h:282
boost::shared_ptr< MethodMeta > MethodMetaPtr
Definition: MetaSerializer.h:371
Container::value_type type
Definition: StlCollections.h:140