Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Property.hpp

Go to the documentation of this file.
00001 /*==========================================================================
00002  *
00003  *  Original source copyright (c) 2003, Carnegie Mellon University.
00004  *  See copyright.cmu for details.
00005  *  Modifications copyright (c) 2003, University of Massachusetts.
00006  *  See copyright.umass for details.
00007  *
00008  *==========================================================================
00009 */
00010 
00011 #ifndef _PROPERTY_HPP
00012 #define _PROPERTY_HPP
00013 
00014 #define INITBUFFSIZE 128
00015 #define INITNAMESIZE 32
00016 
00029 #include <cstring>
00030 
00031 class Property {
00032 public:
00033   enum DataType {EMPTY = 0, INT = 1, STRING = 2, DOUBLE = 3, UNKNOWN = 4};
00034 
00035   Property();
00036   Property(const char * name);
00037   ~Property();
00038 
00039   void setName(const char * name);
00040   void copyValue(const Property * property);
00042   const char * getName() const;
00044   const void * getValue() const;
00046   DataType getType() const;
00047   int getSize() const;
00048   int getLength() const;
00049 
00053   template<typename T>
00054   void setObjectValue( const T& value ) {
00055     dataSize = sizeof(T);
00056     void* memory = allocate( dataSize );
00057     setDestructor( &Property::destruct<T> );
00058     new(memory) T(value);
00059     setType( Property::UNKNOWN );
00060   }
00061 
00063   template<typename T>
00064   void setFundamentalValue( T value, DataType t ) {
00065     dataSize = sizeof(T);
00066     void* memory = allocate( sizeof(T) );
00067     setDestructor( 0 );
00068     memcpy( memory, &value, sizeof(T) );
00069     setType( t );
00070   }
00071 
00073   template<typename T>
00074   void setArrayValue( T* value, DataType t, int length ) {
00075     dataSize = sizeof(T) * length;
00076     void* memory = allocate( dataSize );
00077     setDestructor( 0 );
00078     memcpy( memory, value, length );
00079     setType( t );
00080   }
00081 
00087   template<typename T>
00088   void setValue( T value ) {
00089     setObjectValue( value );
00090   }
00091 
00093   void setValue( const char* value ) {
00094     setArrayValue( value, STRING, strlen(value)+1 );
00095   }
00096 
00098   void setValue( char* value ) {
00099     setArrayValue( value, STRING, strlen(value)+1 );
00100   }
00101 
00103   void setValue( int value ) {
00104     setFundamentalValue( value, INT );
00105   }
00106 
00108   void setValue( double value ) {
00109     setFundamentalValue( value, DOUBLE );
00110   }
00111 
00112   template<class T>
00113   void destruct( void* value ) {
00114     ( (T*) value )->~T();
00115   }
00116 
00117 protected:
00118   void (Property::*destructor)( void* object );
00120   void* allocate( int size );
00121   void setDestructor( void (Property::*destructor)(void* object) );
00122   void setType( DataType type );
00123 
00124   DataType type;
00125   int bufferSize;
00126   int dataSize;
00127   char * buffer;
00128 
00129   int nameSize;
00130   char * name;
00131   bool nullName;
00132 };
00133 
00134 
00135 #endif //_PROPERTY_HPP

Generated on Wed Nov 3 12:59:01 2004 for Lemur Toolkit by doxygen1.2.18