47 #ifndef _MIRA_PROPERTYNODE_H_ 48 #define _MIRA_PROPERTYNODE_H_ 51 #include <serialization/adapters/std/pair> 63 class PropertySerializer;
64 class RootPropertyNode;
105 template<
typename Reflector>
109 r.member(
"ID",
mID,
"");
110 r.member(
"Name",
mName,
"");
112 r.member(
"Type",
mType,
"The typename");
118 template<
typename Reflector>
126 template<
typename Reflector>
140 const std::string&
id()
const {
return mID; }
156 template <
typename T>
157 T
getHint(
const std::string& attribute,
const T& defaultValue = T())
const {
158 return mHint.
get(attribute, defaultValue);
162 bool hasHint(
const std::string& attribute)
const {
215 bool isReadOnly,
bool isVolatile) :
217 mParent(NULL), mUpdated(true) {}
245 const PropertyNode* findChildNode(
const std::vector<std::string>& ids,
246 std::size_t level = 0)
const;
252 PropertyNode* findChildNode(
const std::vector<std::string>& ids,
253 std::size_t level = 0);
266 const PropertyNode* findChildNode(
const std::string&
id)
const;
285 std::string s = id();
286 boost::algorithm::replace_all(s,
".",
"\\");
288 s = boost::algorithm::replace_all_copy(n->id(),
".",
"\\") +
"." + s;
298 virtual void setFromJSON(
const json::Value& value) = 0;
310 virtual void setFromString(
const std::string& value);
315 virtual std::string getAsString()
const;
323 template <
typename T>
330 template <
typename T>
338 virtual void synchronize() = 0;
371 void removeChild(
int index, NodeList::iterator it);
379 void removeChildren(
int index, NodeList::iterator it,
int count);
385 void removeAllChildren();
392 moveChild(index, std::next(mChildren.begin(), index),
393 destination, std::next(mChildren.begin(), destination)); }
400 void moveChild(
int index, NodeList::iterator it,
int destination, NodeList::iterator destIt);
413 virtual void beginMoveChildren(
PropertyNodeListenerList& listeners,
int index, NodeList::iterator it,
int count,
int destination);
461 void removeChild(
int index, NodeList::iterator it);
468 virtual void setFromJSON(
const json::Value& value);
470 virtual void synchronize();
498 boost::timed_mutex mMutex;
515 template <
typename T>
527 assert(info.
type()==typeName<value_type>());
539 virtual void set(
const value_type& value) = 0;
556 template <
typename NodeType,
typename ValueType>
561 root(
p->isVolatile() ? parent->getRootNode() : NULL),
570 std::swap(
p, other.p);
571 std::swap(
root, other.root);
582 std::swap(
p, other.p);
584 std::swap(
root, other.root);
596 template <
typename NodeType,
typename ValueType,
597 bool ValueTypePointer =
false,
bool UseBackup =
false>
607 MIRA_THROW(XIO,
"Property is not available (yet?)")
617 return const_cast<ValueType&
>(this->
r);
622 template <
typename NodeType,
typename ValueType>
624 static_assert(
sizeof(ValueType)==0,
625 "LockedPropertyNodeAccess: combination ValueTypePointer=false, UseBackup=true not implemented");
629 template <
typename NodeType,
typename ValueType>
643 MIRA_THROW(XIO,
"Property is not available (yet?)")
653 return const_cast<ValueType&
>(*this->
r);
658 template <
typename NodeType,
typename ValueType>
669 this->
p->mBackupValue.reset(
new ValueType(*this->
r));
676 if (this->
p->mBackupValue)
677 return *this->
p->mBackupValue;
679 MIRA_THROW(XIO,
"Property is not available (yet?)")
689 return const_cast<ValueType&
>(*this->
r);
695 template <
typename T>
715 return LockedAccess(const_cast<TypedPropertyNodeImplGetSetMixinBase*>(
this), mValue);
741 std::unique_ptr<value_type> mBackupValue;
749 template <
typename T,
bool >
781 template <
typename T>
796 MIRA_THROW(XLogical,
"Cannot set value of property, since the underlying class does not provide an assignment operator");
802 MIRA_THROW(XLogical,
"Cannot get value of property, since the underlying class does not provide an assignment operator");
810 template <
typename T>
825 MIRA_THROW(XLogical,
"Cannot set value of read-only property.");
841 virtual void set(
const value_type&
value) {
843 MIRA_THROW(XLogical,
"Cannot set value of read-only property.");
860 virtual void synchronize();
869 template <
typename T>
877 const std::string& comment,
const value_type& value,
878 bool isReadOnly,
bool isVolatile) :
879 Base(id, name, comment, isReadOnly, isVolatile), mPointer(value) {}
887 return LockedAccess(const_cast<TypedPropertyNodeImpl*>(
this), mPointer);
896 if(this->isReadOnly())
897 MIRA_THROW(XLogical,
"Cannot set value of read-only property.");
911 if(this->isReadOnly())
912 MIRA_THROW(XLogical,
"Cannot set value of read-only property.");
933 virtual void synchronize();
944 template <
typename Getter,
typename Setter>
965 return LockedAccess(const_cast<TypedPropertyNodeImpl*>(
this), mAccessor);
976 MIRA_THROW(XLogical,
"Cannot set value of read-only property.");
994 MIRA_THROW(XLogical,
"Cannot set value of read-only property.");
996 (*accessor()).
set(
value);
1003 return (*accessor()).
get();
1018 virtual void synchronize();
1020 AccessorType mAccessor;
1066 template <
typename T>
1096 template <
typename T>
1106 Base(*node), mNode(node) {}
1122 MIRA_THROW(XNotImplemented,
"TypedRemotePropertyNode::synchronize() not implemented!");
1135 }
catch(std::exception& ex) {
1136 MIRA_THROW(XIO,
"Failed to convert value to json: " << ex.what())
1150 }
catch(std::exception& ex) {
1151 MIRA_THROW(XIO,
"Failed to obtain remote value: " << ex.what())
1163 template <
typename T>
1173 if(remoteNode!=NULL)
1174 return remoteNode->
toTyped<T>();
1177 MIRA_THROW(XBadCast,
"Cannot cast PropertyNode which is of " 1178 "type '" <<
mType <<
"' to requested type '" 1179 << typeName<T>() <<
"'");
1182 template <
typename T>
1190 template <
typename T>
1196 MIRA_THROW(XBadCast,
"Cannot cast PropertyNode which is of " 1197 "type '" <<
mType <<
"' to requested type '" 1198 << typeName<T>() <<
"'");
1201 if(
mType != typeName<T>())
1202 MIRA_THROW(XBadCast,
"Cannot cast remote PropertyNode which is of " 1203 "type '" <<
mType <<
"' to requested type '" 1204 << typeName<T>() <<
"'");
Serializer for serializing objects in JSON format.
Definition: JSONSerializer.h:93
This object can use object tracking internally, but the object tracking system's state remains unchan...
Definition: ReflectControlFlags.h:82
virtual void setFromJSON(const json::Value &node)
Sets the value of the property, where the value is described as JSON value.
Definition: PropertyNode.h:895
virtual void endRemoveChildren()=0
void deserialize(T &value)
Definition: JSONSerializer.h:427
LockedPropertyNodeAccess(NodeType *parent, const ValueType &ref)
Definition: PropertyNode.h:601
void fromList(const AttributeValueList &list)
Sets the property hints from the specified list of attribute/value pairs.
Definition: PropertyHint.h:115
const ValueType & operator*() const
Definition: PropertyNode.h:641
Abstract base class for all derived property node classes.
Definition: PropertyNode.h:202
Base::value_type value_type
Definition: PropertyNode.h:952
virtual ~PropertyNodeListener()
Definition: PropertyNode.h:433
Definition: PropertyNode.h:696
std::string mID
the unique id of the property
Definition: PropertyNode.h:178
void registerListener(PropertyNodeListener *listener)
void setValue(const value_type &value)
Definition: PropertyNode.h:763
LockedAccess pointer()
Definition: PropertyNode.h:890
std::vector< PropertyNode * > NodeList
Definition: PropertyNode.h:207
Base::value_type value_type
Definition: PropertyNode.h:700
virtual PropertyNode * parent()
Returns the parent property node (or NULL, if this is a root node)
Definition: PropertyNode.h:224
Type trait that evaluates to true if a type is copy assignable, false otherwise.
Definition: IsCopyAssignable.h:71
Definition: PropertyNode.h:72
virtual void beginRemoveChildren(const PropertyNode *node, int index, int count)=0
virtual const PropertyNode * parent() const
Returns the parent property node (or NULL, if this is a root node)
Definition: PropertyNode.h:227
Special derived class of PropertyNode, that allows to handle "remote properties" transparently.
Definition: PropertyNode.h:1046
virtual void setFromJSON(const json::Value &node)
Sets the value of the property, where the value is described as JSON value.
Definition: PropertyNode.h:1111
ValueType * PointerType
Definition: PropertyNode.h:663
ValueType & operator*()
Definition: PropertyNode.h:685
virtual PropertyNode::NodeList & children()
Returns a vector with all child property nodes.
Definition: PropertyNode.h:1119
const ValueType & operator*() const
Definition: PropertyNode.h:673
virtual void setFromJSON(const json::Value &value)=0
Sets the value of the property, where the value is described as JSON value.
TypedPropertyNode(const std::string &id, const std::string &name, const std::string &comment, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:530
TypedPropertyNodeImpl(const std::string &id, const std::string &name, const std::string &comment, const value_type &value, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:876
LockedPropertyNodeAccess< TypedPropertyNodeImplGetSetMixinBase< T >, value_type, true, IsCopyAssignable< value_type >::value > LockedAccess
Definition: PropertyNode.h:711
void reflectCommon(Reflector &r)
Definition: PropertyNode.h:106
LockedPropertyNodeAccess(NodeType *parent, const PointerType &ref)
Definition: PropertyNode.h:637
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void setValue(const value_type &value)
Definition: PropertyNode.h:795
std::string Typename
Definition: Typename.h:60
void setName(const std::string &name)
For internal use by PropertySerializer only: Overrides the name of the property.
Definition: PropertyNode.h:173
virtual void beginMoveChildren(const PropertyNode *node, int index, int count, int destination)=0
Base::value_type value_type
Definition: PropertyNode.h:815
LockedPropertyNodeAccessCommon & operator=(LockedPropertyNodeAccessCommon &&other) noexcept
Definition: PropertyNode.h:581
void setValue(const value_type &value)
Definition: PropertyNode.h:724
virtual ~AbstractRemotePropertyNode()
Definition: PropertyNode.h:1052
#define MIRA_SPLIT_REFLECT_MEMBER
Macro that insert a class member reflect() method just splitting reflection into a reflectRead() and ...
Definition: SplitReflect.h:209
Type trait to check if a class is copy assignable.
Provides property hints and attributes.
Definition: PropertyNode.h:430
virtual NodeList & children()
Returns a vector with all child property nodes.
Definition: PropertyNode.h:230
Grants thread-safe access to an object (the Protectee) that should be protected from concurrent acces...
Definition: ScopedAccess.h:119
const ValueType & r
Definition: PropertyNode.h:591
Holds a boost::function object to a special setter function that must meet the signature "void method...
Definition: GetterSetter.h:395
Definition: PropertyNode.h:598
virtual json::Value getAsJSON() const
Returns the value of the property as JSON value.
Definition: PropertyNode.h:985
std::list< std::pair< std::string, std::string > > AttributeValueList
Definition: PropertyHint.h:86
Get compiler and platform independent typenames.
Provides MIRA_SPLIT_REFLECT macros.
void removeChild(int index)
Removes child at specific index (without deleting it).
Definition: PropertyNode.h:358
NodeType * p
Definition: PropertyNode.h:590
bool has(const std::string &attribute) const
Returns true if the specified attribute exists.
Definition: PropertyHint.h:158
AttributeValueList toList() const
Returns the attributes/value list containing the property hints.
Definition: PropertyHint.h:110
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
PropertyNode(const std::string &id, const std::string &name, const std::string &comment, const Typename &type, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:213
void addChild(PropertyNode *child, int index=-1)
Adds the specified property node as child node.
Definition: PropertyNode.h:1059
uint8 VersionType
Definition: ReflectorInterface.h:72
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
A property hint gives optional instructions to the property editor, i.e.
Definition: PropertyHint.h:82
virtual const PropertyNode::NodeList & children() const
Returns a vector with all child property nodes.
Definition: PropertyNode.h:1120
void moveChild(int index, int destination)
Moves a child node from index to before element at destination.
Definition: PropertyNode.h:391
virtual void synchronize()
Synchronize with the reflected object (update PropertyNode when reflected content changes) ...
Definition: PropertyNode.h:1121
LockedPropertyNodeAccessCommon(NodeType *parent, const ValueType &ref)
Definition: PropertyNode.h:559
LockedPropertyNodeAccess< TypedPropertyNodeImpl< T * >, value_type > LockedAccess
Definition: PropertyNode.h:884
virtual void setFromJSON(const json::Value &node)
Sets the value of the property, where the value is described as JSON value.
Definition: PropertyNode.h:974
PropertyNodeInfo & operator=(const PropertyNodeInfo &info)
Definition: PropertyNode.h:90
void addChild(PropertyNode *child, int index=-1)
PropertyNodeInfo()
Definition: PropertyNode.h:75
const Typename & type() const
Returns the type of this property as Typename.
Definition: PropertyNode.h:149
Special TypedPropertyNode for remote properties.
Definition: PropertyNode.h:1097
Deserializer for serializing objects from JSON format.
Definition: JSONSerializer.h:400
T getHint(const std::string &attribute, const T &defaultValue=T()) const
Returns the specified value for the given property hint attribute.
Definition: PropertyNode.h:157
Base::value_type value_type
Definition: PropertyNode.h:786
Base::value_type value_type
Definition: PropertyNode.h:754
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
bool lockFailed
Definition: PropertyNode.h:593
A special node that acts only as (empty) root node for a property tree.
Definition: PropertyNode.h:448
friend LockedAccess
Definition: PropertyNode.h:712
LockedAccess accessor()
Definition: PropertyNode.h:968
virtual void setFromJSON(const json::Value &node)
Sets the value of the property, where the value is described as JSON value.
Definition: PropertyNode.h:823
LockedAccess value()
Definition: PropertyNode.h:718
PropertyNodeInfo(const PropertyNodeInfo &info)
Definition: PropertyNode.h:84
virtual const PropertyNode * parent() const
Returns the parent property node (or NULL, if this is a root node)
Definition: PropertyNode.h:1118
LockedPropertyNodeAccess(NodeType *parent, const PointerType &ref)
Definition: PropertyNode.h:666
Implementation of TypedPropertyNode.
Definition: PropertyNode.h:811
std::string fullID(PropertyNode *p=NULL) const
Returns the full qualified ID of this property, including the names of the parent properties separate...
Definition: PropertyNode.h:283
void update(T &value)
Is called by PropertySerializer to update the internal representation of the value of the property...
Definition: PropertyNode.h:735
void update(AccessorType &value)
Is called by PropertySerializer to update the internal representation of the value of the property...
Definition: PropertyNode.h:1013
bool isReadOnly() const
Returns true, if this property is read-only and hence, can not be modified.
Definition: PropertyNode.h:167
A special PropertyReflector that creates a PropertyNode for each reflected property.
Definition: PropertySerializer.h:67
void update(T *value)
Is called by PropertySerializer to update the internal representation of the value of the property...
Definition: PropertyNode.h:929
PropertyNode(const PropertyNodeInfo &info)
Definition: PropertyNode.h:210
virtual json::Value getAsJSON() const
Returns the value of the property as JSON value.
Definition: PropertyNode.h:1112
Base::value_type value_type
Definition: PropertyNode.h:1101
TypedPropertyNodeImpl(const std::string &id, const std::string &name, const std::string &comment, const AccessorType &value, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:954
bool mIsVolatile
indicates whether the property is volatile
Definition: PropertyNode.h:184
RootPropertyNode * root
Definition: PropertyNode.h:592
TypedPropertyNodeImplGetSetMixin(const std::string &id, const std::string &name, const std::string &comment, value_type &value, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:788
ProtecteeMixin< PropertyNodeListenerList > ProtectedListenerList
Definition: PropertyNode.h:490
json_spirit::mValue Value
A value is an abstract description of data in JSON (underlying data can either be one of the JSON bas...
Definition: JSON.h:176
The Accessor class is used as an adapter to reduce the code bloat within the reflection and serializa...
Definition: Accessor.h:244
Partial Implementations of the get/set of TypedPropertyNode specialized for normal classes / for clas...
Definition: PropertyNode.h:750
const std::string & comment() const
Returns the comment that is associated with this property.
Definition: PropertyNode.h:146
ScopedAccess< ProtectedListenerList > getListeners(bool alreadyLocked=false)
const LockedAccess value() const
Definition: PropertyNode.h:714
virtual json::Value getAsJSON() const
Returns the value of the property as JSON value.
Definition: PropertyNode.h:834
Base::value_type value_type
Definition: PropertyNode.h:874
virtual RootPropertyNode * getRootNode()
Holds a boost::function object to a special getter function that must meet the signature "T method()"...
Definition: GetterSetter.h:87
void removeChildren(int index, int count)
Removes contiguous children, starting at index (without deleting them).
Definition: PropertyNode.h:364
void addChild(PropertyNode *child, int index=-1)
Adds the specified property node as child node.
virtual PropertyNode * parent()
Returns the parent property node (or NULL, if this is a root node)
Definition: PropertyNode.h:1117
T value_type
The type of the property.
Definition: PropertyNode.h:521
std::string mComment
the comment that is associated to the property
Definition: PropertyNode.h:180
bool mIsReadOnly
indicates whether the property is read-only
Definition: PropertyNode.h:183
~LockedPropertyNodeAccessCommon()
Definition: PropertyNode.h:575
ValueType & operator*()
Definition: PropertyNode.h:613
ValueType & operator*()
Definition: PropertyNode.h:649
std::string mName
the name of the property (mostly equal to mID)
Definition: PropertyNode.h:179
TypedPropertyNodeImplGetSetMixinBase(const std::string &id, const std::string &name, const std::string &comment, value_type &value, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:702
PropertyHint mHint
the specified property hints
Definition: PropertyNode.h:181
Typename mType
the type of the property
Definition: PropertyNode.h:182
AbstractRemotePropertyNode(const PropertyNodeInfo &info)
Definition: PropertyNode.h:1049
Grants thread-safe access to an object that should be protected from concurrent access.
virtual json::Value getAsJSON() const
Returns the value of the property as JSON value.
Definition: PropertyNode.h:905
TypedPropertyNode(const PropertyNodeInfo &info)
Definition: PropertyNode.h:525
const LockedAccess pointer() const
Definition: PropertyNode.h:886
virtual const NodeList & children() const
Returns a vector with all child property nodes.
Definition: PropertyNode.h:233
void removeChild(int index, NodeList::iterator it)
bool isVolatile() const
Returns true, if this property is volatile and hence, must be locked for access.
Definition: PropertyNode.h:170
LockedPropertyNodeAccess< TypedPropertyNodeImpl< Accessor< Getter, Setter > >, AccessorType > LockedAccess
Definition: PropertyNode.h:962
virtual void endAddChildren()=0
void reflectWrite(Reflector &r)
Definition: PropertyNode.h:127
TypedPropertyNode< T > Base
Definition: PropertyNode.h:1100
PropertyNodeInfo(const std::string &id, const std::string &name, const std::string &comment, const Typename &type, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:76
const std::string & name() const
Returns the name of this property as specified in the reflect() method.
Definition: PropertyNode.h:143
TypedPropertyNode< T > * toTyped()
Casts this property node to a typed property node, or returns NULL if the types do not match...
Definition: PropertyNode.h:1164
TypedRemotePropertyNode(AbstractRemotePropertyNode *node)
Definition: PropertyNode.h:1105
bool hasHint(const std::string &attribute) const
Returns true if a hint with the specified attribute exists.
Definition: PropertyNode.h:162
Proxy class that is returned/set by the getter and setter methods of ChannelProperty.
Definition: ChannelProperty.h:154
LockedPropertyNodeAccessCommon(LockedPropertyNodeAccessCommon &&other) noexcept
Definition: PropertyNode.h:569
PropertyHint clone() const
Creates an explicit copy as replacement for the copy constructor.
Definition: PropertyHint.h:145
TypedPropertyNodeImpl(const std::string &id, const std::string &name, const std::string &comment, value_type &value, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:817
TypedPropertyNode< T > * toTyped()
Specialized method that creates a TypedRemotePropertyNode.
Definition: PropertyNode.h:1191
T get(const std::string &attribute, const T &defaultValue=T()) const
Returns the specified value for the given attribute.
Definition: PropertyHint.h:175
virtual void beginAddChildren(const PropertyNode *node, int index, int count)=0
std::set< PropertyNodeListener * > PropertyNodeListenerList
Definition: PropertyNode.h:66
Typename typeName(bool cvqualify=true)
Returns a compiler and platform independent typename of T.
Definition: Typename.h:103
void unregisterListener(PropertyNodeListener *listener)
ValueType * PointerType
Definition: PropertyNode.h:634
Abstract base class for all typed property nodes.
Definition: PropertyNode.h:70
Serializer and Deserializer for JSON format.
const ValueType & operator*() const
Definition: PropertyNode.h:605
const LockedAccess accessor() const
Definition: PropertyNode.h:964
virtual void endMoveChildren()=0
void reflectRead(Reflector &r)
Definition: PropertyNode.h:119
virtual json::Value getAsJSON() const =0
Returns the value of the property as JSON value.
const std::string & id() const
Returns the unique id of this property.
Definition: PropertyNode.h:140
Definition: PropertyNode.h:557
TypedPropertyNodeImplGetSetMixin(const std::string &id, const std::string &name, const std::string &comment, value_type &value, bool isReadOnly, bool isVolatile)
Definition: PropertyNode.h:756