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()))
619 catch(XNotImplemented&)
630 const std::string& versionString) {
642 bool acceptDesiredVersion =
false) {
650 template <
typename T>
652 return this->
version(version, typeName<T>(),
false);
665 template <
typename T>
667 return this->
version(version, typeName<T>(),
true);
691 template <
typename T>
692 void write(
const T* data, std::size_t count) {
701 template <
typename T>
713 template <
typename T>
721 assert(name != NULL);
733 template<
typename R,
typename... Args,
typename F,
typename... Description>
735 method(
const char*, F&&, Description&&...)
740 template<
typename F,
typename... Description>
742 method(
const char*, F&&, Description&&...)
747 template<
typename R,
typename Class,
typename... Args,
typename... Description>
754 template<
typename R,
typename Class,
typename... Args,
typename... Description>
761 template<
typename R,
typename... Args,
typename F,
typename... Description>
763 method(
const char* name, F&& fn, Description&&... descriptions)
766 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
769 template<
typename F,
typename... Description>
771 method(
const char* name, F&& fn, Description&&... descriptions)
773 concreteMethodMetaHelper<typename Private::FunctionTraits<F>::ReturnValue>(
775 std::forward<Description>(descriptions)...);
778 template<
typename R,
typename Class,
typename... Args,
typename... Description>
782 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
785 template<
typename R,
typename Class,
typename... Args,
typename... Description>
790 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
797 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
808 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
819 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
834 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
862 static const std::string context =
"invokeOverwrite " + typeName<T>();
876 static const std::string context =
"invokeOverwrite PlainArray<" + typeName<T>() +
">";
882 collectionItems<T>(
"@itemcount",
true);
894 const std::string& n =
type->getIdentifier();
911 template<
typename T,
bool>
937 template<
typename T,
bool>
962 template <
typename T>
998 return createMeta<Type>();
1003 template<
typename T>
1006 return createMeta<T>();
1016 template<
typename R,
typename... Args,
typename... Description>
1018 Description&&... descriptions)
1020 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
1023 template<
typename R,
typename ... Args,
typename Comment,
typename ...Descriptions>
1027 m->returnType = createMetaOrVoidHelper<R>();
1028 addParameterDescription<Args...>(*m, std::forward<Descriptions>(args)...);
1033 template<
typename... RECURSIONSTOP>
1034 typename std::enable_if<(
sizeof...(RECURSIONSTOP)) == 0>
::type addParameterDescription(
MethodMeta& m)
1038 template<
typename ParameterType,
typename... Args>
1039 void addParameterDescription(MethodMeta& m)
1041 m.parameters.push_back(MethodMeta::Parameter(createMetaHelper<ParameterType>()));
1042 addParameterDescription<Args...>(m);
1045 template<
typename ParameterType,
typename... Args,
class Name,
class Description,
typename... Tail,
1046 typename =
typename std::enable_if<(
sizeof...(Args)) * 2 ==
sizeof...(Tail)>::
type>
1047 void addParameterDescription(MethodMeta& m, Name&& name, Description&& description, Tail&&... tail)
1049 m.parameters.push_back(MethodMeta::Parameter(createMetaHelper<ParameterType>(),
1050 std::forward<Name>(name),
1051 std::forward<Description>(description)));
1052 addParameterDescription<Args...>(m, std::forward<Tail>(tail)...);
1055 template<
typename ParameterType,
typename... Args,
class Name,
class Description,
class Example,
1057 typename =
typename std::enable_if<(
sizeof...(Args)) * 3 ==
sizeof...(Tail)>::
type>
1058 void addParameterDescription(MethodMeta& m, Name&& name, Description&& description, Example&& example,
1061 m.parameters.push_back(MethodMeta::Parameter(createMetaHelper<ParameterType>(),
1062 std::forward<Name>(name),
1063 std::forward<Description>(description)));
1064 addParameterDescription<Args...>(m, std::forward<Tail>(tail)...);
1071 template<
typename T>
1079 template<
typename T>
1087 template<
typename T>
1091 Base::property<T>(name,
member,
setter,comment,std::move(hint), flags);
1095 template<
typename T>
1103 template<
typename T,
typename U>
1111 template<
typename T,
typename U>
1113 const char* comment,
const U& defaultValue,
1120 template<
typename T,
typename U>
1122 const char* comment,
const U& defaultValue,
1129 template<
typename T>
1139 template<
typename T>
1148 template<
typename T>
1157 template<
typename T>
1167 mParentMeta->members.back().name =
"@items_blockdump";
1193 template<
typename T>
1196 template<
typename T>
1197 class IsTransparentSerializableHelper<serialization::PlainArray<T>, MetaSerializer> :
public std::true_type {};
1199 namespace serialization {
1211 template<
typename Container>
1212 struct ReflectCollectionItems<MetaSerializer, Container>
1214 static void reflect(MetaSerializer& r, Container& c)
1216 typedef typename Container::value_type rawtype;
1219 r.template collectionItems<type>(
"@itemcount");
1223 template<
typename Allocator>
1224 struct ReflectReadBoolVectorItems<MetaSerializer, Allocator>
1226 static void reflect(MetaSerializer& r, std::vector<bool, Allocator>& c)
1228 r.template collectionItems<bool>(
"@itemcount");
1232 template<
typename Container>
1233 struct ReflectReadSetItems<MetaSerializer, Container>
1235 typedef typename Container::value_type rawtype;
1238 static void reflect(MetaSerializer& r, Container& c)
1240 r.template collectionItems<type>(
"@itemcount");
1244 template<
typename Container>
1245 struct ReflectReadMapItems<MetaSerializer, Container>
1247 typedef typename Container::key_type rawkeytype;
1248 typedef typename Container::mapped_type rawmappedtype;
1252 static void reflect(MetaSerializer& r, Container& c)
1254 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:321
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:883
#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:83
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:985
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:82
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:479
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:295
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:674
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:269
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