cartobase  4.5.0
carto::DictionaryInterface Class Referenceabstract

Interface for dictionary-like objects. More...

#include <cartobase/object/object.h>

Inheritance diagram for carto::DictionaryInterface:
Collaboration diagram for carto::DictionaryInterface:

Public Member Functions

virtual ~DictionaryInterface ()
 
virtual bool isDictionary () const
 Returns false if the stored object doesn't actually implement the DictionaryInterface API (needed since all GenericObject inherit this interface whatever they actually contain) More...
 
virtual bool getProperty (const std::string &key, Object &value) const =0
 Access the element ok key key. More...
 
Object getProperty (const std::string &) const
 same as the other getProperty() functions except that the value object is returned. More...
 
Object getProperty (Object key) const
 same as the other getProperty() functions except that the key is contained in the key argument (which must implement the StringInterface). More...
 
template<typename T >
bool getProperty (const std::string &key, T &value) const
 same as the other getProperty() functions except that the value object must be of exact type T and is copied to the value argument. More...
 
virtual void setProperty (const std::string &key, Object value)=0
 Set (insert or replace) the element of key key with the value object. More...
 
void setProperty (const std::string &, const char *)
 specific specialization: C strings are stored as std::string objects More...
 
template<typename T >
void setProperty (const std::string &, const T &)
 same as the other setProperty() functions except that the value to be set is of the arbitrary type T and will possibly be stored in an Object. More...
 
virtual bool removeProperty (const std::string &)=0
 remove an element. More...
 
virtual bool hasProperty (const std::string &key) const =0
 check if an element exists under the key key More...
 
virtual void clearProperties ()
 clear the dictionary More...
 
virtual void copyProperties (Object source)
 copy all properties of the source object to this object. More...
 
virtual bool operator== (const DictionaryInterface &other) const
 equality test More...
 
virtual bool operator!= (const DictionaryInterface &other) const
 
template<>
void setProperty (const std::string &key, Object const &value)
 
template<>
bool getProperty (const std::string &key, Object &value) const
 
- Public Member Functions inherited from carto::SizeInterface
virtual ~SizeInterface ()
 
virtual size_t size () const =0
 Number of sub-elements. More...
 
- Public Member Functions inherited from carto::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from carto::IterableInterface
virtual ~IterableInterface ()
 
virtual bool isIterable () const
 Returns false if the stored object doesn't actually implement the IterableInterface API (needed since all GenericObject inherit this interface whatever they actually contain) More...
 
virtual Object objectIterator () const =0
 returns an object implementing the IteratorIntrerface More...
 
virtual bool operator== (const IterableInterface &other) const
 equality test More...
 
virtual bool operator!= (const IterableInterface &other) const
 

Detailed Description

Interface for dictionary-like objects.

DictionaryInterface is the generic interface for dictionary-like objects. This includes wrappers to STL maps with a string key, or the more specialized PropertySet.

Dictionary items are called "properties" and are stored using a string key.

Definition at line 354 of file object.h.

Constructor & Destructor Documentation

virtual carto::DictionaryInterface::~DictionaryInterface ( )
virtual

Member Function Documentation

virtual void carto::DictionaryInterface::clearProperties ( )
virtual
virtual void carto::DictionaryInterface::copyProperties ( Object  source)
virtual

copy all properties of the source object to this object.

source must implement DictionaryInterface

virtual bool carto::DictionaryInterface::getProperty ( const std::string &  key,
Object value 
) const
pure virtual

Access the element ok key key.

value is filled with a wrapper to the selected element. If it fails (key not found for instance), an exception is thrown.

Implemented in carto::TypedObject< T >, carto::TypedObject< SyntaxedInterfaceType< T > >, and carto::PropertySet.

Object carto::DictionaryInterface::getProperty ( const std::string &  ) const

same as the other getProperty() functions except that the value object is returned.

An exception is thrown in case of failure.

Object carto::DictionaryInterface::getProperty ( Object  key) const

same as the other getProperty() functions except that the key is contained in the key argument (which must implement the StringInterface).

The value object is returned. An exception is thrown in case of failure.

template<typename T >
bool carto::DictionaryInterface::getProperty ( const std::string &  key,
T &  value 
) const

same as the other getProperty() functions except that the value object must be of exact type T and is copied to the value argument.

No exception is thrown if the key is not found or the selected element is not of type T, but the return value is false if it fails. An exception is still thrown if this function is called on an object that doesn't actually implement the DictionaryInterface API.

Definition at line 1307 of file object.h.

template<>
bool carto::DictionaryInterface::getProperty ( const std::string &  key,
Object value 
) const
virtual bool carto::DictionaryInterface::hasProperty ( const std::string &  key) const
pure virtual

check if an element exists under the key key

Implemented in carto::TypedObject< T >, carto::TypedObject< SyntaxedInterfaceType< T > >, and carto::PropertySet.

virtual bool carto::DictionaryInterface::isDictionary ( ) const
virtual

Returns false if the stored object doesn't actually implement the DictionaryInterface API (needed since all GenericObject inherit this interface whatever they actually contain)

Reimplemented in carto::TypedObject< T >, and carto::TypedObject< SyntaxedInterfaceType< T > >.

virtual bool carto::DictionaryInterface::operator!= ( const DictionaryInterface other) const
inlinevirtual

Definition at line 421 of file object.h.

References operator==().

virtual bool carto::DictionaryInterface::operator== ( const DictionaryInterface other) const
virtual

equality test

Referenced by operator!=().

virtual bool carto::DictionaryInterface::removeProperty ( const std::string &  )
pure virtual

remove an element.

Note that on some dictionary implementations (PropertySet with builtin properties for instance), some properties cannot be removed.

Implemented in carto::TypedObject< T >, carto::TypedObject< SyntaxedInterfaceType< T > >, and carto::PropertySet.

virtual void carto::DictionaryInterface::setProperty ( const std::string &  key,
Object  value 
)
pure virtual

Set (insert or replace) the element of key key with the value object.

On some specific dictionary implementations (such as PropertySet with builtin properties, or maps of specific, typed values), an existing property cannot change type. In this case value must hold an object of the correct type, otherwise an exception will be thrown.

Implemented in carto::TypedObject< T >, carto::TypedObject< SyntaxedInterfaceType< T > >, and carto::PropertySet.

void carto::DictionaryInterface::setProperty ( const std::string &  ,
const char *   
)

specific specialization: C strings are stored as std::string objects

template<typename T >
void carto::DictionaryInterface::setProperty ( const std::string &  ,
const T &  value 
)

same as the other setProperty() functions except that the value to be set is of the arbitrary type T and will possibly be stored in an Object.

The same type restrictions apply as for the other setProperty() functions

Definition at line 1298 of file object.h.

template<>
void carto::DictionaryInterface::setProperty ( const std::string &  key,
Object const &  value 
)

The documentation for this class was generated from the following file: