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;
137 FIRST_TYPE_QUALIFIER = 0x20,
138 TYPE_COLLECTION = FIRST_TYPE_QUALIFIER,
147 template<
typename Reflector>
150 if(getType()==TYPE_ATOMIC || getType()==TYPE_CLASS)
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>
159 if(getType()==TYPE_ATOMIC || getType()==TYPE_CLASS)
160 r.
member(
"Identifier", mPlainIdentifier,
"The identifier of the class " 163 if (getType()==TYPE_CLASS)
164 mIdentifier += mPlainIdentifier +
" @v0";
166 mIdentifier = mPlainIdentifier;
170 template<
typename BinaryStream>
173 if(getType()==TYPE_ATOMIC || getType()==TYPE_CLASS)
174 r.
member(
"Identifier", mPlainIdentifier,
"The identifier of the class " 183 assert(Base::size()>=1);
184 push_back(qualifier);
191 assert(
type!=TYPE_CLASS &&
type!=TYPE_ATOMIC &&
type!=TYPE_INVALID);
192 assert(Base::size()==0);
201 void setAtomicType(
const std::string& typenam);
206 template <
typename T>
213 assert(Base::size()==0);
214 push_back(TYPE_CLASS);
215 mIdentifier = identifier;
216 mPlainIdentifier = mIdentifier;
223 template <
typename T>
228 setClassType(typeName<T>());
235 if(empty() || front() >= LAST_TYPE_FIELD)
237 return (
Type)front();
244 return Base::size()>1;
251 return std::max(size()-1,0);
260 if(i>=qualifierCount())
272 if(n>qualifierCount())
274 return Base::resize(size()-n);
289 std::string getTypename()
const;
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");
387 type(iType), name(iName), comment(iComment) {}
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");
417 version[
""] = *optVersion;
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;
431 if (!version.empty())
432 optVersion = version.cbegin()->second;
435 r.
member(
"Version",optVersion,
"The version of the serialization format");
437 r.
member(
"Members",members,
"The members of the compound");
438 r.
member(
"Interfaces",interfaces,
"The supported interfaces");
439 r.
member(
"Methods",methods,
"The reflected methods");
449 addMember(name,
"",
type);
454 members.push_back(
Member(
type, name, comment));
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))
475 interfaces.push_back(iface);
480 methods.push_back(method);
484 this->version[
""] = version;
488 this->version[
type] = version;
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);
602 mMetaDatabase(database) {}
607 #ifdef CHECK_FORCE_SERIALIZE_BINARY_VERSION 609 if ((vf >= 0) && (vf < BinaryBufferSerializer::getSerializerFormatVersion()))
614 mCurrentMeta.reset();
616 serialize(MIRA_REFLECTOR_TOPLEVEL_NAME, v);
619 catch(XNotImplemented&)
630 const std::string& versionString) {
632 mParentMeta->setVersion(
type, version);
634 mCurrentVersion->name = versionString;
635 mCurrentVersion->comment =
"";
642 bool acceptDesiredVersion =
false) {
643 version = this->queryDesiredClassVersion(version,
type, acceptDesiredVersion);
644 setVersion(version,
type,
"@version[" +
type +
"]");
650 template <
typename T>
652 return this->version(version, typeName<T>(),
false);
658 mParentMeta->setVersion(version);
660 mCurrentVersion->name = std::string(
"@version");
665 template <
typename T>
667 return this->version(version, typeName<T>(),
true);
679 mParentMeta->addMember(
"@version_default", std::string(
"implicit: ") + context, mCurrentMeta);
680 mCurrentVersion = &(mParentMeta->members.back());
688 mCurrentVersion = prev;
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);
723 mParentMeta->addInterface(name);
730 mParentMeta->addMethod(method);
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>
780 method(
const char* name, R (
Class::*fn)(Args...),
Class* This, Description&&... descriptions)
782 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
785 template<
typename R,
typename Class,
typename... Args,
typename... Description>
787 method(
const char* name, R (
Class::*fn)(Args...)
const,
Class* This, Description&&... descriptions)
790 createMethodMeta<R, Args...>(name, std::forward<Description>(descriptions)...);
797 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
800 mCurrentMeta->setAtomicType<T>();
801 addCurrentAsMemberToParent();
808 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
812 addCurrentAsMemberToParent();
819 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
822 Base::pointer(pointer);
826 assert(mCurrentMeta);
834 MIRA_THROW(XNotImplemented,
"Type " << typeName<T>() <<
" is not meta-serializable");
837 mCurrentMeta->setClassType(typeName<T>());
838 addCurrentAsMemberToParent();
847 mParentMeta = compound;
849 Base::object(member);
852 mCurrentMeta = prevCurrentMeta;
853 mParentMeta = prevParentMeta;
862 static const std::string context =
"invokeOverwrite " + typeName<T>();
865 Base::invokeOverwrite(
object);
876 static const std::string context =
"invokeOverwrite PlainArray<" + typeName<T>() +
">";
880 Base::invokeOverwrite(array);
882 collectionItems<T>(
"@itemcount",
true);
885 postReflect(prevState);
894 const std::string& n =
type->getIdentifier();
896 if(mMetaDatabase.count(n)>0)
900 mMetaDatabase[n] = compound;
907 mParentMeta->addMember(getCurrentMemberMeta(), mCurrentMeta);
911 template<
typename T,
bool>
937 template<
typename T,
bool>
962 template <
typename T>
979 mCurrentMeta = prevCurrentMeta;
980 mParentMeta = prevParentMeta;
990 return createMetaHelper(dummy);
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)...);
1029 addMethod(std::move(m));
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>
1072 void property(
const char* name, T& member,
const char* comment,
1075 Base::property(name,member,comment,std::move(hint), flags);
1079 template<
typename T>
1080 void property(
const char* name,
const std::string&
id, T& member,
1083 Base::property(name,
id,member,comment,std::move(hint), flags);
1087 template<
typename T>
1091 Base::property<T>(name,member,
setter,comment,std::move(hint), flags);
1095 template<
typename T>
1099 Base::property(name,
getter,
setter,comment,std::move(hint), flags);
1103 template<
typename T,
typename U>
1104 void property(
const char* name, T& member,
const char* comment,
1107 Base::property(name,member,comment,defaultValue,std::move(hint), flags);
1111 template<
typename T,
typename U>
1113 const char* comment,
const U& defaultValue,
1116 Base::property(name,member,
setter,comment,defaultValue, std::move(hint), flags);
1120 template<
typename T,
typename U>
1122 const char* comment,
const U& defaultValue,
1125 Base::property(name,
getter,
setter,comment,defaultValue,std::move(hint), flags);
1129 template<
typename T>
1132 this->This()->pushObjectTrackingStore();
1133 this->invokeMember(member,
ReflectMemberMeta(
"@transparent",
"@transparent",
"delegated") );
1134 this->This()->popObjectTrackingStore();
1136 this->invokeMember(member,
ReflectMemberMeta(
"@transparent",
"@transparent",
"delegated") );
1139 template<
typename T>
1143 this->This()->pushObjectTrackingStore();
1144 this->invokeMember(a,
ReflectMemberMeta(
"@transparent",
"@transparent",
"delegated") );
1145 this->This()->popObjectTrackingStore();
1148 template<
typename T>
1152 this->This()->pushObjectTrackingStore();
1153 this->invokeMember(a,
ReflectMemberMeta(
"@transparent",
"@transparent",
"delegated") );
1154 this->This()->popObjectTrackingStore();
1157 template<
typename T>
1162 assert(mCurrentMeta);
1165 assert(mParentMeta);
1167 mParentMeta->members.back().name =
"@items_blockdump";
1168 mParentMeta->members.back().comment = countName;
1170 mParentMeta->members.back().name =
"@items";
1171 mParentMeta->members.back().comment = countName;
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:324
Definition: RPCPatternCheck.h:82
Class for in place stream formatting.
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:862
#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:991
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
uint8 VersionType
Definition: ReflectorInterface.h:72
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
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
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:256
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
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:617
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
Definition: BinarySerializer.h:257
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
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