34 #ifndef CARTOBASE_OBJECT_OBJECT_H
35 #define CARTOBASE_OBJECT_OBJECT_H
56 #define DECLARE_GENERIC_OBJECT_TYPE( T ) \
58 struct GenericObjectTypeDeclared< T > \
60 static inline void check() {} \
63 void DictionaryInterface::setProperty( const std::string &key, \
66 bool DictionaryInterface::getProperty( const std::string &key, T &value ) const; \
67 extern template class TypedObject< T >; \
68 extern template class ValueObject< T >; \
69 extern template class ReferenceObject< T >; \
70 extern template class PointerObject< T >; \
72 T const &GenericObject::value< T >() const; \
74 T &GenericObject::value< T >(); \
76 bool GenericObject::value( T &dest ) const; \
78 void GenericObject::setValue( T const & x ); \
79 extern template bool DictionaryInterface:: \
80 getProperty( const std::string &, T & ) const; \
81 extern template void DictionaryInterface:: \
82 setProperty( const std::string &, T const & ); \
88 template <
typename T>
class TypedObject;
187 virtual size_t size()
const = 0;
300 virtual std::string
key()
const = 0;
364 virtual size_t size()
const = 0;
429 Object & value )
const = 0;
462 template <
typename T>
void setProperty(
const std::string &,
const T & );
501 virtual void setSyntax(
const std::string& syntactic ) = 0;
552 virtual std::string
type()
const = 0;
557 template<
typename T>
const T & value()
const;
561 template<
typename T> T & value();
565 template <
typename T>
bool value( T & )
const;
569 template<
typename T>
void setValue(
const T &val );
572 virtual size_t size()
const = 0;
593 template <
typename T>
596 template <
typename T>
597 const T *getInterface()
const;
625 template <
typename T>
630 template <
typename T>
637 template <
typename T>
643 template <
typename T>
669 template <
typename T>
688 virtual std::string
type()
const;
698 virtual void setString(
const std::string & );
703 virtual bool hasItem(
int index )
const;
706 virtual size_t size()
const;
724 virtual bool hasProperty(
const std::string & )
const;
743 virtual std::string
key()
const;
747 virtual long intKey()
const;
750 virtual bool isNone()
const;
756 const void *_getAddressOfValue()
const;
758 static bool _debugInstantiation;
766 template <
typename T>
769 static inline void check( T *x = NULL )
771 you_must_use_DECLARE_GENERIC_OBJECT_TYPE( x );
777 template <
typename T>
788 template <
typename T>
789 class PrintInstantiation
793 static bool doIt(
bool * );
797 template <
typename T>
798 class PrintInstantiation<const T>
802 static bool doIt(
bool * );
813 template <
typename T,
bool B>
814 class CompileErrorIfFalse
816 static inline void check() {}
819 template <
typename T>
820 class CompileErrorIfFalse<T,false>
822 static inline void check()
824 T::cannot_compile_this_code();
828 template <
typename T,
typename U>
829 class ForbidInheritance : CompileErrorIfFalse< T, SUPERSUBCLASS( T, U ) >
839 template <
typename T>
877 template <
typename T>
898 template <
typename T>
928 template <
typename T>
936 template <
typename T>
982 Object const &GenericObject::value< Object >()
const;
984 Object &GenericObject::value< Object >();
996 extern template class TypedObject< GenericObject >;
997 extern template class ReferenceObject< GenericObject >;
998 extern template class PointerObject< GenericObject >;
1055 #define _TMP_ std::map< std::string, int >
1058 #define _TMP_ std::map< std::string, unsigned >
1061 #define _TMP_ std::map< std::string, char >
1064 #define _TMP_ std::map< std::string, signed char >
1067 #define _TMP_ std::map< std::string, unsigned char >
1070 #define _TMP_ std::map< std::string, short >
1073 #define _TMP_ std::map< std::string, unsigned short >
1076 #define _TMP_ std::map< std::string, long >
1079 #define _TMP_ std::map< std::string, unsigned long >
1082 #define _TMP_ std::map< std::string, long long >
1085 #define _TMP_ std::map< std::string, unsigned long long >
1088 #define _TMP_ std::map< std::string, float >
1091 #define _TMP_ std::map< std::string, double >
1094 #define _TMP_ std::map< std::string, bool >
1097 #define _TMP_ std::map< std::string, std::string >
1100 #define _TMP_ std::map< std::string, Object >
1103 #define TMP std::map< int, Object >
1106 #define TMP std::map< float, Object >
1109 #define TMP std::map< Object, Object >
1113 #define _TMP_ std::map< std::string, std::vector<int> >
1116 #define _TMP_ std::map< std::string, std::vector<unsigned> >
1119 #define _TMP_ std::map< std::string, std::vector<char> >
1122 #define _TMP_ std::map< std::string, std::vector<signed char> >
1125 #define _TMP_ std::map< std::string, std::vector<unsigned char> >
1128 #define _TMP_ std::map< std::string, std::vector<short> >
1131 #define _TMP_ std::map< std::string, std::vector<unsigned short> >
1134 #define _TMP_ std::map< std::string, std::vector<long> >
1137 #define _TMP_ std::map< std::string, std::vector<unsigned long> >
1140 #define _TMP_ std::map< std::string, std::vector<long long> >
1143 #define _TMP_ std::map< std::string, std::vector<unsigned long long> >
1146 #define _TMP_ std::map< std::string, std::vector<float> >
1149 #define _TMP_ std::map< std::string, std::vector<double> >
1152 #define _TMP_ std::map< std::string, std::vector<std::string> >
1155 #define _TMP_ std::map< std::string, std::vector<Object> >
1175 #define _TMP_ rc_ptr< std::map< std::string, int > >
1178 #define _TMP_ rc_ptr< std::map< std::string, unsigned > >
1181 #define _TMP_ rc_ptr< std::map< std::string, char > >
1184 #define _TMP_ rc_ptr< std::map< std::string, signed char > >
1187 #define _TMP_ rc_ptr< std::map< std::string, unsigned char > >
1190 #define _TMP_ rc_ptr< std::map< std::string, short > >
1193 #define _TMP_ rc_ptr< std::map< std::string, unsigned short > >
1196 #define _TMP_ rc_ptr< std::map< std::string, long > >
1199 #define _TMP_ rc_ptr< std::map< std::string, unsigned long > >
1202 #define _TMP_ rc_ptr< std::map< std::string, long long > >
1205 #define _TMP_ rc_ptr< std::map< std::string, unsigned long long > >
1208 #define _TMP_ rc_ptr< std::map< std::string, float > >
1211 #define _TMP_ rc_ptr< std::map< std::string, double > >
1214 #define _TMP_ rc_ptr< std::map< std::string, bool > >
1217 #define _TMP_ rc_ptr< std::map< std::string, std::string > >
1220 #define _TMP_ rc_ptr< std::map< std::string, Object > >
1223 #define _TMP_ rc_ptr< std::map< int, Object > >
1226 #define _TMP_ rc_ptr< std::map< float, Object > >
1229 #define TMP rc_ptr< std::map< Object, Object > >
1233 #define _TMP_ rc_ptr< std::map< std::string, std::vector<int> > >
1236 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned> > >
1239 #define _TMP_ rc_ptr< std::map< std::string, std::vector<char> > >
1242 #define _TMP_ rc_ptr< std::map< std::string, std::vector<signed char> > >
1245 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned char> > >
1248 #define _TMP_ rc_ptr< std::map< std::string, std::vector<short> > >
1251 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned short> > >
1254 #define _TMP_ rc_ptr< std::map< std::string, std::vector<long> > >
1257 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned long> > >
1260 #define _TMP_ rc_ptr< std::map< std::string, std::vector<long long> > >
1263 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned long long> > >
1266 #define _TMP_ rc_ptr< std::map< std::string, std::vector<float> > >
1269 #define _TMP_ rc_ptr< std::map< std::string, std::vector<double> > >
1272 #define _TMP_ rc_ptr< std::map< std::string, std::vector<std::string> > >
1275 #define _TMP_ rc_ptr< std::map< std::string, std::vector<Object> > >
1284 template <
typename T>
1285 inline void object_to( Object o, T & r );
1318 template <
typename T>
1321 r = o->GenericObject::value<T>();
1329 template <
typename T>
1332 throw std::runtime_error( std::string(
"cannot convert object to const " ) +
1349 #ifdef __CHAR_UNSIGNED__
1350 object_to<unsigned char>( o,
reinterpret_cast<unsigned char &
>( r ) );
1352 object_to<signed char>( o,
reinterpret_cast<signed char &
>( r ) );
1373 template <
typename T>
1377 you_must_use_DECLARE_GENERIC_OBJECT_TYPE( value );
1382 template <
typename T>
1385 return you_must_use_DECLARE_GENERIC_OBJECT_TYPE( value );
1408 return dynamic_cast<T *
>(
const_cast<GenericObject *
>( this )
1443 if (
this != &other ) {
1454 if (
this == &other || ( !
get() && !other.
get() ) )
1456 if( !
get() || !other.
get() )
1458 return *
get() == *other.
get();
1464 template <
typename T,
bool>
1465 class ObjectValueTrait
1468 static inline Object value()
1472 static inline Object value(
const T &v )
1474 return Object(
static_cast<GenericObject *
>(
new ValueObject<T>( v ) ) );
1479 template <
typename T>
1480 class ObjectValueTrait<T,true>
1483 static inline Object value()
1485 return Object( (GenericObject *)
new T );
1487 static inline Object value(
const T &v )
1495 template <
typename T>
1504 template <
typename T>
1522 template <
typename T,
bool>
1523 class ObjectReferenceTrait
1526 static inline Object reference( T &v )
1533 template <
typename T>
1534 class ObjectReferenceTrait<T,true>
1537 static inline Object reference( T &v )
1539 return Object( &v );
1545 template <
typename T>
1554 template <
typename T>
1580 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
1586 {
return "ValueObject"; }
1636 return "genericobject";
1643 return "genericobject";
1652 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
1658 {
return "ReferenceObject"; }
bool operator==(const carto::block< T, N > &b1, const carto::block< T, N > &b2)
Void does not contain anything.
ArrayInterface represents any container whose elements can be accessed via an integer index.
virtual bool hasItem(int index) const =0
Tells if array item index actually exists.
virtual Object getArrayItem(int index) const =0
Get the element of index index.
virtual bool isContiguous() const =0
Tells if array indices are contiguous (as in a vector), contrarily to an int key dictionary.
virtual void setArrayItem(int, Object)=0
virtual bool isArray() const
Returns false if the stored object doesn't actually implement the ArrayInterface API (needed since al...
virtual size_t size() const =0
Number of sub-elements.
virtual ~ArrayInterface()
static std::string name()
static std::string objectType()
static std::string dataType()
static std::string name()
static std::string dataType()
static std::string objectType()
This class is just a hint to convert an actual data type to an identifier string used in input/output...
static std::string name()
static std::string objectType()
static std::string dataType()
Interface for dictionary-like objects.
virtual bool hasProperty(const std::string &key) const =0
check if an element exists under the key key
virtual ~DictionaryInterface()
virtual bool removeProperty(const std::string &)=0
remove an element.
virtual bool getProperty(const std::string &key, Object &value) const =0
Access the element ok key key.
void setProperty(const std::string &, const char *)
specific specialization: C strings are stored as std::string objects
virtual void copyProperties(Object source)
copy all properties of the source object to this object.
virtual void clearProperties()
clear the dictionary
virtual bool operator!=(const DictionaryInterface &other) const
Object getProperty(Object key) const
same as the other getProperty() functions except that the key is contained in the key argument (which...
Object getProperty(const std::string &) const
same as the other getProperty() functions except that the value object is returned.
virtual bool operator==(const DictionaryInterface &other) const
equality test
virtual bool isDictionary() const
Returns false if the stored object doesn't actually implement the DictionaryInterface API (needed sin...
virtual void setProperty(const std::string &key, Object value)=0
Set (insert or replace) the element of key key with the value object.
Specialized IteratorInterface for dictionaries.
virtual std::string key() const =0
Access the key of the current dictionary element.
virtual ~DictionaryIteratorInterface()
virtual bool isDictionaryIterator() const
Returns false if the stored object doesn't actually implement the DictionaryIteratorInterface API (ne...
A dynamic array has resize and insertion capabilities (like a STL vector)
virtual ~DynArrayInterface()
virtual void removeArrayItem(int)=0
removes an element from the array.
virtual void resizeArray(size_t)=0
resize the array.
virtual bool isDynArray() const
Returns false if the stored object doesn't actually implement the DynArrayInterface API (needed since...
virtual void reserveArray(size_t)=0
like the STL vector::reserve(), memory is reserved but no element is stored
virtual void insertArrayItem(int, Object)=0
inserts an element into the array.
base abstract generic object class.
const T & value() const
Retrieve value in object, const reference.
void setValue(const T &val)
Store value in object by copying it.
virtual Interface * _getGenericInterface()=0
virtual Object clone() const =0
cloning copy
virtual std::string type() const =0
type() returns the DataTypeCode::name() of the underlying object type
virtual void setValue(Object val)=0
T * getInterface()
Obtain a specific Interface subclass.
virtual const void * _getAddressOfValue() const =0
virtual size_t size() const =0
Number of sub-elements.
Specialized IteratorInterface for dictionaries.
virtual bool isIntKeyIterator() const
Returns false if the stored object doesn't actually implement the DictionaryIteratorInterface API (ne...
virtual ~IntKeyIteratorInterface()
virtual long intKey() const =0
Access the key of the current dictionary element.
Container objects which can be iterated.
virtual bool isIterable() const
Returns false if the stored object doesn't actually implement the IterableInterface API (needed since...
virtual ~IterableInterface()
virtual Object objectIterator() const =0
returns an object implementing the IteratorIntrerface
virtual bool operator==(const IterableInterface &other) const
equality test
virtual bool operator!=(const IterableInterface &other) const
An iterator object is a reference to another object.
virtual ~IteratorInterface()
virtual bool isIterator() const
Returns false if the stored object doesn't actually implement the IteratorInterface API (needed since...
virtual Object currentValue() const =0
Access the value of the element pointed to by the iterator.
virtual void next()=0
Point to the next element of the iterable container.
virtual bool isValid() const =0
true if the iterator points to a valid value, false when the end of the iterable container has been r...
Specialized IteratorInterface for key/value storage.
virtual Object keyObject() const =0
Access the key of the current element.
virtual bool isKeyIterator() const
Returns false if the stored object doesn't actually implement the DictionaryIteratorInterface API (ne...
virtual ~KeyIteratorInterface()
Specialized NoneInterface for empty objects (null, None).
virtual bool isNone() const =0
Returns false if the stored object doesn't actually implement the NoneInterface API (needed since all...
Object & operator=(const Object &)
uses the reference-counting so the underlying GenericObject is shared
static Object reference(T &value)
factory function: builds an Object by referencing the value from a ReferenceObject storage wrapper.
bool operator!=(const Object &other) const
bool isSameObject(const Object &) const
compares the addresses of the underlying GenericObjects
static Object value()
factory function: builds an Object by using the default constructor
bool operator==(const Object &other) const
bool isNone() const
check if we hold a "none" object.
PointerObject(T &x, bool owner)
virtual Object clone() const
cloning copy
Base class for reference counted objects (intrusive)
storage wrapper, derived and instanciable template class
virtual Object clone() const
cloning copy
virtual ~ReferenceObject()
All scalar numbers implement the ScalarInterface (all ints, float, double...)
virtual bool isScalar() const
Returns false if the stored object doesn't actually implement the ScalarInterface API (needed since a...
virtual bool operator!=(const ScalarInterface &other) const
virtual double getScalar() const =0
Obtain a scalar value, possibly after a conversion.
virtual ~ScalarInterface()
virtual bool operator==(const ScalarInterface &other) const
equality test
virtual void setScalar(double)=0
The double value will be converted to the actual storage type before it is set in the contained objec...
All container objects inherit the SizeInterface.
virtual size_t size() const =0
Number of sub-elements.
Objects whose value may be represented as a character string.
virtual bool isString() const
Returns false if the stored object doesn't actually implement the StringInterface API (needed since a...
virtual void setString(const std::string &)=0
The string value may be converted to the actual storage type before it is set in the contained object...
virtual bool operator==(const StringInterface &other) const
equality test
virtual bool operator!=(const StringInterface &other) const
virtual ~StringInterface()
virtual std::string getString() const =0
Obtain a string value, possibly after a conversion.
A Syntaxed object is an object containing an additional character string giving it a kind of type (a ...
virtual ~SyntaxedInterface()
virtual bool operator==(const SyntaxedInterface &other) const
equality test
virtual bool hasSyntax() const =0
virtual bool operator!=(const SyntaxedInterface &other) const
virtual void setSyntax(const std::string &syntactic)=0
virtual std::string getSyntax() const =0
storage wrapper, derived but still abstract template class
virtual long intKey() const
Access the key of the current dictionary element.
virtual bool isContiguous() const
Tells if array indices are contiguous (as in a vector), contrarily to an int key dictionary.
virtual Object objectIterator() const
returns an object implementing the IteratorIntrerface
virtual bool isKeyIterator() const
Returns false if the stored object doesn't actually implement the DictionaryIteratorInterface API (ne...
virtual Object keyObject() const
Access the key of the current element.
virtual Object clone() const
cloning copy
virtual bool isDynArray() const
Returns false if the stored object doesn't actually implement the DynArrayInterface API (needed since...
virtual void setValue(Object val)
virtual Object currentValue() const
Access the value of the element pointed to by the iterator.
virtual void insertArrayItem(int, Object)
inserts an element into the array.
virtual void removeArrayItem(int)
removes an element from the array.
virtual void setScalar(double)
The double value will be converted to the actual storage type before it is set in the contained objec...
virtual bool isIterator() const
Returns false if the stored object doesn't actually implement the IteratorInterface API (needed since...
virtual Object getArrayItem(int index) const
Get the element of index index.
virtual std::string key() const
Access the key of the current dictionary element.
virtual bool isIntKeyIterator() const
Returns false if the stored object doesn't actually implement the DictionaryIteratorInterface API (ne...
virtual std::string getString() const
Obtain a string value, possibly after a conversion.
virtual void clearProperties()
clear the dictionary
virtual void reserveArray(size_t)
like the STL vector::reserve(), memory is reserved but no element is stored
virtual bool isDictionaryIterator() const
Returns false if the stored object doesn't actually implement the DictionaryIteratorInterface API (ne...
virtual bool isIterable() const
Returns false if the stored object doesn't actually implement the IterableInterface API (needed since...
virtual void resizeArray(size_t)
resize the array.
virtual void setString(const std::string &)
The string value may be converted to the actual storage type before it is set in the contained object...
virtual bool isArray() const
Returns false if the stored object doesn't actually implement the ArrayInterface API (needed since al...
virtual size_t size() const
Number of sub-elements.
virtual bool removeProperty(const std::string &)
remove an element.
virtual bool operator==(const GenericObject &other) const
virtual bool hasItem(int index) const
Tells if array item index actually exists.
virtual bool hasProperty(const std::string &) const
check if an element exists under the key key
virtual bool isDictionary() const
Returns false if the stored object doesn't actually implement the DictionaryInterface API (needed sin...
virtual bool isString() const
Returns false if the stored object doesn't actually implement the StringInterface API (needed since a...
virtual double getScalar() const
Obtain a scalar value, possibly after a conversion.
virtual bool isValid() const
true if the iterator points to a valid value, false when the end of the iterable container has been r...
virtual void setProperty(const std::string &key, Object value)=0
Set (insert or replace) the element of key key with the value object.
virtual bool getProperty(const std::string &key, Object &value) const=0
Access the element ok key key.
virtual void next()
Point to the next element of the iterable container.
virtual std::string type() const
type() returns the DataTypeCode::name() of the underlying object type
virtual bool isScalar() const
Returns false if the stored object doesn't actually implement the ScalarInterface API (needed since a...
virtual bool isNone() const
Returns false if the stored object doesn't actually implement the NoneInterface API (needed since all...
virtual void setArrayItem(int, Object)
storage wrapper, derived and instanciable template class
virtual Object clone() const
cloning copy
Reference-counting pointer.
GenericObject * get() const
std::map< int, Object > IntDictionary
void object_to(Object o, T &r)
std::map< std::string, Object > Dictionary
Common type used for DictionaryInterface implementation.
std::map< std::string, Syntax > SyntaxSet
This lookup table associates a syntactic attribute with its syntax.
std::map< Object, Object > ObjectDictionary
std::vector< Object > ObjectVector
Common type used for ArrayInterface implementation.
Object none()
An empty singleton object (holds a null pointer)
SemanticSet Syntax
Specify syntax for syntactic attributes.
#define DECLARE_GENERIC_OBJECT_TYPE(T)
Class to force a compilation error when a generic object.
static void check(T *x=NULL)