34 #ifndef CARTOBASE_OBJECT_OBJECT_H 35 #define CARTOBASE_OBJECT_OBJECT_H 52 #endif // #ifdef CARTO_DEBUG 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 & ); \ 119 virtual bool isScalar()
const;
124 virtual double getScalar()
const = 0;
130 virtual void setScalar(
double ) = 0;
153 virtual bool isString()
const;
158 virtual std::string getString()
const = 0;
164 virtual void setString(
const std::string & ) = 0;
187 virtual size_t size()
const = 0;
206 virtual bool isIterable()
const;
208 virtual Object objectIterator()
const = 0;
245 virtual bool isIterator()
const;
248 virtual bool isValid()
const = 0;
250 virtual Object currentValue()
const = 0;
252 virtual void next() = 0;
274 virtual bool isKeyIterator()
const;
276 virtual Object keyObject()
const = 0;
298 virtual bool isDictionaryIterator()
const;
300 virtual std::string key()
const = 0;
322 virtual bool isIntKeyIterator()
const;
324 virtual long intKey()
const = 0;
345 virtual bool isArray()
const;
353 virtual Object getArrayItem(
int index )
const = 0;
354 virtual void setArrayItem(
int,
Object ) = 0;
355 virtual size_t size()
const = 0;
374 virtual bool isDynArray()
const;
377 virtual void reserveArray(
size_t ) = 0;
381 virtual void resizeArray(
size_t ) = 0;
384 virtual void removeArrayItem(
int ) = 0;
387 virtual void insertArrayItem(
int,
Object ) = 0;
414 virtual bool isDictionary()
const;
419 virtual bool getProperty(
const std::string & key,
420 Object & value )
const = 0;
423 Object getProperty(
const std::string & )
const;
436 template <
typename T>
bool getProperty(
const std::string & key,
446 virtual void setProperty(
const std::string & key,
Object value ) = 0;
448 void setProperty(
const std::string &,
const char * );
453 template <
typename T>
void setProperty(
const std::string &,
const T & );
459 virtual bool removeProperty(
const std::string & ) = 0;
462 virtual bool hasProperty(
const std::string & key )
const = 0;
464 virtual void clearProperties();
467 virtual void copyProperties(
Object source );
490 virtual std::string getSyntax()
const = 0;
491 virtual bool hasSyntax()
const = 0;
492 virtual void setSyntax(
const std::string& syntactic ) = 0;
516 virtual bool isNone()
const = 0;
541 virtual Object clone()
const = 0;
543 virtual std::string type()
const = 0;
548 template<
typename T>
const T & value()
const;
552 template<
typename T> T & value();
556 template <
typename T>
bool value( T & )
const;
560 template<
typename T>
void setValue(
const T &val );
561 virtual void setValue(
Object val ) = 0;
563 virtual size_t size()
const = 0;
584 template <
typename T>
587 template <
typename T>
588 const T *getInterface()
const;
596 virtual Interface *_getGenericInterface() = 0;
597 virtual const void *_getAddressOfValue()
const = 0;
616 template <
typename T>
617 static inline Object value();
621 template <
typename T>
622 static inline Object value(
const T & );
628 template <
typename T>
629 static inline Object reference( T & value );
634 template <
typename T>
635 static inline Object reference(
const T & value );
638 bool isSameObject(
const Object & )
const;
651 inline bool operator != (
const Object & other )
const 660 template <
typename T>
670 virtual T &getValue();
671 inline const T &getValue()
const;
672 virtual void setValue(
Object val );
677 virtual Object clone()
const;
679 virtual std::string type()
const;
682 virtual bool isScalar()
const;
683 virtual double getScalar()
const;
684 virtual void setScalar(
double );
687 virtual bool isString()
const;
688 virtual std::string getString()
const;
689 virtual void setString(
const std::string & );
692 virtual bool isArray()
const;
693 virtual Object getArrayItem(
int index )
const;
694 virtual void setArrayItem(
int,
Object );
695 virtual size_t size()
const;
698 virtual bool isDynArray()
const;
699 virtual void reserveArray(
size_t );
700 virtual void resizeArray(
size_t );
701 virtual void removeArrayItem(
int );
702 virtual void insertArrayItem(
int,
Object );
705 virtual bool getProperty(
const std::string &,
Object & )
const;
706 virtual bool isDictionary()
const;
709 virtual void setProperty(
const std::string &,
Object );
712 virtual bool removeProperty(
const std::string & );
713 virtual bool hasProperty(
const std::string & )
const;
714 virtual void clearProperties();
717 virtual bool isIterable()
const;
718 virtual Object objectIterator()
const;
721 virtual bool isIterator()
const;
722 virtual bool isValid()
const;
723 virtual Object currentValue()
const;
727 virtual bool isKeyIterator()
const;
728 virtual Object keyObject()
const;
731 virtual bool isDictionaryIterator()
const;
732 virtual std::string key()
const;
735 virtual bool isIntKeyIterator()
const;
736 virtual long intKey()
const;
739 virtual bool isNone()
const;
745 const void *_getAddressOfValue()
const;
747 static bool _debugInstantiation;
748 #endif // ifdef CARTO_DEBUG 755 template <
typename T>
758 static inline void check( T *x = NULL )
760 you_must_use_DECLARE_GENERIC_OBJECT_TYPE( x );
766 template <
typename T>
777 template <
typename T>
778 class PrintInstantiation
782 static bool doIt(
bool * );
786 template <
typename T>
787 class PrintInstantiation<const T>
791 static bool doIt(
bool * );
793 #endif // ifdef CARTO_DEBUG 802 template <
typename T,
bool B>
803 class CompileErrorIfFalse
805 static inline void check() {}
808 template <
typename T>
809 class CompileErrorIfFalse<T,false>
811 static inline void check()
813 T::cannot_compile_this_code();
817 template <
typename T,
typename U>
818 class ForbidInheritance : CompileErrorIfFalse< T, SUPERSUBCLASS( T, U ) >
828 template <
typename T>
836 virtual T &getValue();
838 virtual Object clone()
const;
866 template <
typename T>
872 virtual T &getValue();
874 virtual Object clone()
const;
887 template <
typename T>
893 virtual T &getValue();
895 virtual Object clone()
const;
917 template <
typename T>
925 template <
typename T>
971 Object const &GenericObject::value< Object >()
const;
973 Object &GenericObject::value< Object >();
1041 #define _TMP_ std::map< std::string, int > 1044 #define _TMP_ std::map< std::string, unsigned > 1047 #define _TMP_ std::map< std::string, char > 1050 #define _TMP_ std::map< std::string, signed char > 1053 #define _TMP_ std::map< std::string, unsigned char > 1056 #define _TMP_ std::map< std::string, short > 1059 #define _TMP_ std::map< std::string, unsigned short > 1062 #define _TMP_ std::map< std::string, long > 1065 #define _TMP_ std::map< std::string, unsigned long > 1068 #define _TMP_ std::map< std::string, long long > 1071 #define _TMP_ std::map< std::string, unsigned long long > 1074 #define _TMP_ std::map< std::string, float > 1077 #define _TMP_ std::map< std::string, double > 1080 #define _TMP_ std::map< std::string, bool > 1083 #define _TMP_ std::map< std::string, std::string > 1086 #define _TMP_ std::map< std::string, Object > 1089 #define TMP std::map< int, Object > 1092 #define TMP std::map< float, Object > 1095 #define TMP std::map< Object, Object > 1099 #define _TMP_ std::map< std::string, std::vector<int> > 1102 #define _TMP_ std::map< std::string, std::vector<unsigned> > 1105 #define _TMP_ std::map< std::string, std::vector<char> > 1108 #define _TMP_ std::map< std::string, std::vector<signed char> > 1111 #define _TMP_ std::map< std::string, std::vector<unsigned char> > 1114 #define _TMP_ std::map< std::string, std::vector<short> > 1117 #define _TMP_ std::map< std::string, std::vector<unsigned short> > 1120 #define _TMP_ std::map< std::string, std::vector<long> > 1123 #define _TMP_ std::map< std::string, std::vector<unsigned long> > 1126 #define _TMP_ std::map< std::string, std::vector<long long> > 1129 #define _TMP_ std::map< std::string, std::vector<unsigned long long> > 1132 #define _TMP_ std::map< std::string, std::vector<float> > 1135 #define _TMP_ std::map< std::string, std::vector<double> > 1138 #define _TMP_ std::map< std::string, std::vector<std::string> > 1141 #define _TMP_ std::map< std::string, std::vector<Object> > 1161 #define _TMP_ rc_ptr< std::map< std::string, int > > 1164 #define _TMP_ rc_ptr< std::map< std::string, unsigned > > 1167 #define _TMP_ rc_ptr< std::map< std::string, char > > 1170 #define _TMP_ rc_ptr< std::map< std::string, signed char > > 1173 #define _TMP_ rc_ptr< std::map< std::string, unsigned char > > 1176 #define _TMP_ rc_ptr< std::map< std::string, short > > 1179 #define _TMP_ rc_ptr< std::map< std::string, unsigned short > > 1182 #define _TMP_ rc_ptr< std::map< std::string, long > > 1185 #define _TMP_ rc_ptr< std::map< std::string, unsigned long > > 1188 #define _TMP_ rc_ptr< std::map< std::string, long long > > 1191 #define _TMP_ rc_ptr< std::map< std::string, unsigned long long > > 1194 #define _TMP_ rc_ptr< std::map< std::string, float > > 1197 #define _TMP_ rc_ptr< std::map< std::string, double > > 1200 #define _TMP_ rc_ptr< std::map< std::string, bool > > 1203 #define _TMP_ rc_ptr< std::map< std::string, std::string > > 1206 #define _TMP_ rc_ptr< std::map< std::string, Object > > 1209 #define _TMP_ rc_ptr< std::map< int, Object > > 1212 #define _TMP_ rc_ptr< std::map< float, Object > > 1215 #define TMP rc_ptr< std::map< Object, Object > > 1219 #define _TMP_ rc_ptr< std::map< std::string, std::vector<int> > > 1222 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned> > > 1225 #define _TMP_ rc_ptr< std::map< std::string, std::vector<char> > > 1228 #define _TMP_ rc_ptr< std::map< std::string, std::vector<signed char> > > 1231 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned char> > > 1234 #define _TMP_ rc_ptr< std::map< std::string, std::vector<short> > > 1237 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned short> > > 1240 #define _TMP_ rc_ptr< std::map< std::string, std::vector<long> > > 1243 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned long> > > 1246 #define _TMP_ rc_ptr< std::map< std::string, std::vector<long long> > > 1249 #define _TMP_ rc_ptr< std::map< std::string, std::vector<unsigned long long> > > 1252 #define _TMP_ rc_ptr< std::map< std::string, std::vector<float> > > 1255 #define _TMP_ rc_ptr< std::map< std::string, std::vector<double> > > 1258 #define _TMP_ rc_ptr< std::map< std::string, std::vector<std::string> > > 1261 #define _TMP_ rc_ptr< std::map< std::string, std::vector<Object> > > 1270 template <
typename T>
1271 inline void object_to( Object o, T & r );
1275 void object_to( Object o,
unsigned char &r );
1277 void object_to( Object o,
signed char &r );
1279 inline void object_to( Object o,
char &r );
1281 void object_to( Object o,
unsigned short &r );
1285 void object_to( Object o,
unsigned &r );
1291 inline void object_to( Object o,
double &r );
1293 void object_to( Object o, std::string &r );
1295 inline void object_to( Object o, Object & r );
1304 template <
typename T>
1307 r = o->GenericObject::value<T>();
1315 template <
typename T>
1318 throw std::runtime_error( std::string(
"cannot convert object to const " ) +
1335 #ifdef __CHAR_UNSIGNED__ 1336 object_to<unsigned char>( o,
reinterpret_cast<unsigned char &
>( r ) );
1338 object_to<signed char>( o,
reinterpret_cast<signed char &
>( r ) );
1359 template <
typename T>
1363 you_must_use_DECLARE_GENERIC_OBJECT_TYPE( value );
1368 template <
typename T>
1371 return you_must_use_DECLARE_GENERIC_OBJECT_TYPE( value );
1383 return dynamic_cast<T *
>( _getGenericInterface() );
1394 return dynamic_cast<T *
>(
const_cast<GenericObject *
>( this )
1395 ->_getGenericInterface() );
1429 if (
this != &other ) {
1440 if (
this == &other || ( !
get() && !other.
get() ) )
1442 if( !
get() || !other.
get() )
1444 return *
get() == *other.
get();
1450 template <
typename T,
bool>
1451 class ObjectValueTrait
1465 template <
typename T>
1466 class ObjectValueTrait<T,true>
1481 template <
typename T>
1490 template <
typename T>
1508 template <
typename T,
bool>
1509 class ObjectReferenceTrait
1519 template <
typename T>
1520 class ObjectReferenceTrait<T,true>
1531 template <
typename T>
1540 template <
typename T>
1559 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 1565 {
return "ValueObject"; }
1615 return "genericobject";
1622 return "genericobject";
1631 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 1637 {
return "ReferenceObject"; }
#define DECLARE_GENERIC_OBJECT_TYPE(T)
Objects whose value may be represented as a character string.
std::map< Object, Object > ObjectDictionary
virtual bool getProperty(const std::string &key, Object &value) const =0
Access the element ok key key.
T * getInterface()
Obtain a specific Interface subclass.
base abstract generic object class.
std::map< int, Object > IntDictionary
Specialized NoneInterface for empty objects (null, None).
static std::string name()
ArrayInterface represents any container whose elements can be accessed via an integer index...
static std::string objectType()
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)
Container objects which can be iterated.
storage wrapper, derived and instanciable template class
static void check(T *x=NULL)
static Object reference(T &value)
factory function: builds an Object by referencing the value from a ReferenceObject storage wrapper...
static std::string dataType()
Specialized IteratorInterface for key/value storage.
bool operator==(const carto::block< T, N > &b1, const carto::block< T, N > &b2)
Specialized IteratorInterface for dictionaries.
storage wrapper, derived but still abstract template class
bool isNone() const
check if we hold a "none" object.
static std::string name()
std::map< std::string, Syntax > SyntaxSet
This lookup table associates a syntactic attribute with its syntax.
bool operator==(const Object &other) const
Reference-counting pointer.
static std::string objectType()
All scalar numbers implement the ScalarInterface (all ints, float, double...)
void object_to(Object o, T &r)
Specialized IteratorInterface for dictionaries.
static std::string name()
A Syntaxed object is an object containing an additional character string giving it a kind of type (a ...
void setValue(const T &val)
Store value in object by copying it.
static std::string objectType()
std::vector< Object > ObjectVector
Common type used for ArrayInterface implementation.
static std::string dataType()
Class to force a compilation error when a generic object.
SemanticSet Syntax
Specify syntax for syntactic attributes.
virtual void setProperty(const std::string &key, Object value)=0
Set (insert or replace) the element of key key with the value object.
All container objects inherit the SizeInterface.
storage wrapper, derived and instanciable template class
static Object value()
factory function: builds an Object by using the default constructor
const T & value() const
Retreive value in object, const reference.
std::map< std::string, Object > Dictionary
Common type used for DictionaryInterface implementation.
static std::string dataType()
Void does not contain anything.
Object none()
An empty singleton object (holds a null pointer)
A dynamic array has resize and insertion capabilities (like a STL vector)
Object & operator=(const Object &)
uses the reference-counting so the underlying GenericObject is shared
An iterator object is a reference to another object.
Interface for dictionary-like objects.