35 #ifndef CARTOBASE_OBJECT_PROPERTY_H 36 #define CARTOBASE_OBJECT_PROPERTY_H 81 typedef ::sigc::signal3< void,
const Object &,
const std::string&,
98 template <
typename T>
bool getProperty(
const std::string &, T & )
const;
99 template <
typename T>
void setProperty(
const std::string &,
const T & );
100 virtual bool getProperty(
const std::string &, Object & )
const;
101 virtual void setProperty(
const std::string &, Object );
105 {
return _erase( key ); }
106 virtual bool hasProperty(
const std::string & )
const;
107 virtual size_t size()
const;
128 inline Property(
const Object &o,
bool b )
129 : object( o ), builtin( b ? &PropertySet::_mandatoryProperty : 0 ) {}
130 inline Property(
const Object &o,
bool *b ) : object( o ), builtin( b ) {}
131 inline Property() : builtin( 0 ) {}
135 typedef std::map< std::string, Property > Properties;
136 typedef std::list< Properties::iterator > PropertiesOrder;
146 bool isValid()
const;
147 std::string key()
const;
148 Object currentValue()
const;
155 inline iterator(
const PropertiesOrder::const_iterator &begin,
156 const PropertiesOrder::const_iterator &end );
158 PropertiesOrder::const_iterator _iterator;
159 PropertiesOrder::const_iterator _end;
165 inline void _insert(
const std::string &key,
const Property &value );
166 bool _erase(
const std::string &key,
bool force_builtin =
false );
168 Properties _properties;
169 PropertiesOrder _propertiesOrder;
170 Signal _signalPropertyChanged;
172 static bool _mandatoryProperty;
181 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 187 {
return(
"PropertySet" ); }
189 {
return std::string(
"Object" ); }
192 return std::string(
"PropertySet" );
209 template <
typename T>
212 Properties::iterator it = _properties.find( key );
213 if ( it == _properties.end() ) {
217 bool willemit =
false;
218 if( !_signalPropertyChanged.empty() )
221 if( !it->second.object.isNull() )
222 oldValue = it->second.object->clone();
224 if ( it->second.builtin ) {
225 it->second.object->setValue( value );
226 if( it->second.builtin != &_mandatoryProperty )
227 *it->second.builtin =
true;
233 it->first, oldValue );
239 template <
typename T>
242 Properties::iterator it = _properties.find( key );
243 if ( it == _properties.end() ) {
246 throw std::runtime_error( std::string(
"Built-in property " ) + key +
253 template <
typename T>
257 Properties::iterator it = _properties.find( key );
258 if ( it == _properties.end() ) {
261 throw std::runtime_error( std::string(
"Built-in property " ) + key +
268 template <
typename T>
271 Properties::iterator it = _properties.find( key );
272 if ( it != _properties.end() ) {
276 throw std::runtime_error( std::string(
"Built-in property " ) + key +
283 template <
typename T>
287 Properties::iterator it = _properties.find( key );
288 if ( it != _properties.end() ) {
292 throw std::runtime_error( std::string(
"Built-in property " ) + key +
299 template <
typename T>
302 Properties::const_iterator it = _properties.find( key );
303 if ( it != _properties.end() &&
304 ( !it->second.builtin || it->second.builtin == &_mandatoryProperty ) )
306 return it->second.object->value( value );
315 return iterator( _propertiesOrder.begin(), _propertiesOrder.end() );
320 inline void PropertySet::_insert(
const std::string &key,
321 const Property &value ) {
322 _propertiesOrder.push_back(
323 _properties.insert( std::pair<std::string, Property>( key, value ) ).first
340 iterator(
const PropertiesOrder::const_iterator &begin,
341 const PropertiesOrder::const_iterator &end ) :
342 _iterator( begin ), _end( end )
344 while( _iterator != end && (*_iterator)->second.builtin
345 && !*(*_iterator)->second.builtin )
#define DECLARE_GENERIC_OBJECT_TYPE(T)
virtual bool getProperty(const std::string &key, Object &value) const =0
Access the element ok key key.
Signal & getSignalPropertyChanged()
void addBuiltinProperty(const std::string &, T &)
virtual size_t size() const
Number of sub-elements.
PropertySet & operator=(const PropertySet &)
This class is just a hint to convert an actual data type to an identifier string used in input/output...
Base class for reference counted objects (intrusive)
virtual bool removeProperty(const std::string &key)
remove an element.
std::string dataType() const
static Object reference(T &value)
factory function: builds an Object by referencing the value from a ReferenceObject storage wrapper...
virtual void clearProperties()
clear the dictionary
::sigc::signal3< void, const Object &, const std::string &, const Object &> Signal
This signal type informs the slots about the sender (this), the property name and its old value...
virtual Object objectIterator() const
returns an object implementing the IteratorIntrerface
void setProperty(const std::string &, const T &)
virtual bool hasProperty(const std::string &) const
check if an element exists under the key key
Specialized IteratorInterface for dictionaries.
A dictionary generic Object.
virtual void setProperty(const std::string &key, Object value)=0
Set (insert or replace) the element of key key with the value object.
static std::string name()
static Object value()
factory function: builds an Object by using the default constructor
void changeBuiltinProperty(const std::string &, T &)
change the reference to a builtin property
iterator getIterator() const
::sigc::trackable Observable
bool getProperty(const std::string &, T &) const
std::string objectType() const
virtual void copyBuiltinProperties(const PropertySet &source)
Interface for dictionary-like objects.