35 #ifndef CARTOBASE_OBJECT_PROPERTY_H
36 #define CARTOBASE_OBJECT_PROPERTY_H
81 typedef ::sigc::signal3< void,
const Object &,
const std::string&,
99 template <
typename T>
bool getProperty(
const std::string &, T & )
const;
100 template <
typename T>
void setProperty(
const std::string &,
const T & );
104 {
return _erase( key ); }
127 inline Property(
const Object &o,
bool b )
128 : object( o ), builtin( b ? &
PropertySet::_mandatoryProperty : 0 ) {}
129 inline Property(
const Object &o,
bool *b ) : object( o ), builtin( b ) {}
130 inline Property() : builtin( 0 ) {}
134 typedef std::map< std::string, Property > Properties;
135 typedef std::list< Properties::iterator > PropertiesOrder;
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>
213 Properties::iterator it = _properties.find( key );
214 if ( it == _properties.end() ) {
218 bool willemit =
false;
219 if( !_signalPropertyChanged.empty() )
222 if( !it->second.object.isNull() )
223 oldValue = it->second.object->clone();
225 if ( it->second.builtin ) {
226 it->second.object->setValue( value );
227 if( it->second.builtin != &_mandatoryProperty )
228 *it->second.builtin =
true;
234 it->first, oldValue );
240 template <
typename T>
244 Properties::iterator it = _properties.find( key );
245 if ( it == _properties.end() ) {
248 throw std::runtime_error( std::string(
"Built-in property " ) + key +
255 template <
typename T>
260 Properties::iterator it = _properties.find( key );
261 if ( it == _properties.end() ) {
264 throw std::runtime_error( std::string(
"Built-in property " ) + key +
271 template <
typename T>
275 Properties::iterator it = _properties.find( key );
276 if ( it != _properties.end() ) {
280 throw std::runtime_error( std::string(
"Built-in property " ) + key +
287 template <
typename T>
292 Properties::iterator it = _properties.find( key );
293 if ( it != _properties.end() ) {
297 throw std::runtime_error( std::string(
"Built-in property " ) + key +
304 template <
typename T>
308 Properties::const_iterator it = _properties.find( key );
309 if ( it != _properties.end() &&
310 ( !it->second.builtin || it->second.builtin == &_mandatoryProperty ) )
312 return it->second.object->value( value );
321 return iterator( _propertiesOrder.begin(), _propertiesOrder.end() );
326 inline void PropertySet::_insert(
const std::string &key,
327 const Property &value ) {
328 _propertiesOrder.push_back(
329 _properties.insert( std::pair<std::string, Property>( key, value ) ).first
346 iterator(
const PropertiesOrder::const_iterator &begin,
347 const PropertiesOrder::const_iterator &end ) :
348 _iterator( begin ), _end( end )
350 while( _iterator != end && (*_iterator)->second.builtin
351 && !*(*_iterator)->second.builtin )
std::string objectType() const
static std::string name()
std::string dataType() const
This class is just a hint to convert an actual data type to an identifier string used in input/output...
Interface for dictionary-like objects.
virtual bool getProperty(const std::string &key, Object &value) const =0
Access the element ok key key.
Specialized IteratorInterface for dictionaries.
Specialized IteratorInterface for key/value storage.
static Object reference(T &value)
factory function: builds an Object by referencing the value from a ReferenceObject storage wrapper.
static Object value()
factory function: builds an Object by using the default constructor
void next()
Point to the next element of the iterable container.
Object keyObject() const
Access the key of the current element.
std::string key() const
Access the key of the current dictionary element.
bool isValid() const
true if the iterator points to a valid value, false when the end of the iterable container has been r...
Object currentValue() const
Access the value of the element pointed to by the iterator.
A dictionary generic Object.
Signal & getSignalPropertyChanged()
::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 void clearProperties()
clear the dictionary
void setProperty(const std::string &, const T &)
virtual bool removeProperty(const std::string &key)
remove an element.
virtual bool hasProperty(const std::string &) const
check if an element exists under the key key
void addBuiltinProperty(const std::string &, T &)
PropertySet & operator=(const PropertySet &)
PropertySet(const PropertySet &)
virtual void setProperty(const std::string &, Object)
Set (insert or replace) the element of key key with the value object.
virtual size_t size() const
Number of sub-elements.
virtual void copyBuiltinProperties(const PropertySet &source)
void changeBuiltinProperty(const std::string &, T &)
change the reference to a builtin property
virtual Object objectIterator() const
returns an object implementing the IteratorIntrerface
virtual bool getProperty(const std::string &key, Object &value) const=0
Access the element ok key key.
iterator getIterator() const
virtual bool getProperty(const std::string &, Object &) const
Access the element ok key key.
Base class for reference counted objects (intrusive)
::sigc::trackable Observable
#define DECLARE_GENERIC_OBJECT_TYPE(T)