Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

DataEntry.h

Go to the documentation of this file.
00001 #ifndef _RDA_DATA_ENTRY_H_
00002 #define _RDA_DATA_ENTRY_H_
00003 //
00004 // 22 Mar 2001, N.Trofimov
00005 // 18 Sep 2001 NNT
00006 //    - added support for long long
00007 // 13 May 2002 NNT
00008 //    - fully rewritten to use union instead of Any as the data store
00009 //    - added put/get methods for arrays
00010 // 09 Jul 2002 NNT
00011 //    - added print methods and os<<, asciiDump deprecated
00012 //    - added getTypeName
00013 //    - added message to rdaTypeMismatch
00014 // 18 Mar 2004 NNT
00015 //    - added documentation for put/get methods
00016 //
00017 
00018 #include <stdio.h>
00019 #include <stddef.h>
00020 
00034 #ifdef CMW_WIN
00035 // For Windows/VC++
00036 typedef __int64 longlong;
00037 #else
00038 // For Unix/GCC
00039 typedef long long longlong;
00040 #endif
00041 
00174 class rdaDataEntry
00175 {
00176    //
00177    // Allow Data access private constructor and destructor
00178    //
00179    friend class rdaData;
00180 
00181    const char* tag_;
00182    
00183    //
00184    // PRIVATE constructors and desctructor.
00185    //
00186    // The C++ implementation, unlike the Java implementation, does not
00187    // support "independent" data entries. The life cycle of a data entry
00188    // is fully managed by the rdaData object in which it is contained.
00189    //
00190    rdaDataEntry(const char* tag);
00191    rdaDataEntry(const rdaDataEntry& de);
00192    ~rdaDataEntry();
00193 
00194    public:
00195        
00200       rdaDataEntry& operator=(const rdaDataEntry& de);
00201 
00207       const char* tag() const;
00208 
00216 
00223       void print(FILE* fp, unsigned long maxElements) const;
00224 
00230       void print(unsigned long maxElements) const;
00231 
00235       void print() const;
00237 
00244       void asciiDump(unsigned long maxElements=5) const;
00245          
00246       //
00247       // COMPARISON
00248       // ==========
00249       //
00250 
00257      
00261       bool operator==(const rdaDataEntry&) const;
00265       bool operator!=(const rdaDataEntry&) const;
00267       
00268       //
00269       // VALUE TYPE
00270       // ==========
00272       //  
00273       enum ValueType
00274       {
00276          TYPE_NULL,
00278          TYPE_BOOLEAN,
00280          TYPE_BOOLEAN_ARRAY,
00282          TYPE_BYTE, 
00284          TYPE_BYTE_ARRAY,
00286          TYPE_SHORT, 
00288          TYPE_SHORT_ARRAY,
00290          TYPE_INT, 
00292          TYPE_INT_ARRAY,
00294          TYPE_LONG, 
00296          TYPE_LONG_ARRAY,
00298          TYPE_FLOAT, 
00300          TYPE_FLOAT_ARRAY,
00302          TYPE_DOUBLE, 
00304          TYPE_DOUBLE_ARRAY,
00306          TYPE_STRING, 
00308          TYPE_STRING_ARRAY
00309       };
00313       ValueType getValueType() const;
00314 
00369       static const char* getTypeName(ValueType typeCode);
00370 
00371       //
00372       // EXTRACTION
00373       // ==========
00374       //
00375 
00382 
00389       bool   extractBoolean() const;
00397       bool*  extractBooleanArray(unsigned long& size) const;
00405       const bool*  getBooleanArray(unsigned long& size) const;
00412       signed char extractByte() const;
00419       signed char*  extractByteArray(unsigned long& size) const;
00426       const signed char*  getByteArray(unsigned long& size) const;
00433       short  extractShort() const;
00440       short* extractShortArray(unsigned long& size) const;
00447       const short* getShortArray(unsigned long& size) const;
00454       long   extractInt() const;
00461       long*  extractIntArray(unsigned long& size) const;
00468       const long*  getIntArray(unsigned long& size) const;
00469 
00476       longlong extractLong() const;
00483       longlong*  extractLongArray(unsigned long& size) const;
00490       const longlong*  getLongArray(unsigned long& size) const;
00497       float  extractFloat() const;
00504       float* extractFloatArray(unsigned long& size) const;
00511       const float* getFloatArray(unsigned long& size) const;
00518       double  extractDouble() const;
00525       double* extractDoubleArray(unsigned long& size) const;
00532       const double* getDoubleArray(unsigned long& size) const;
00540       char*  extractString() const;
00548       const char* getString() const;
00556       char** extractStringArray(unsigned long& size) const;
00564       const char** getStringArray(unsigned long& size) const;
00566 
00567       
00568       //
00569       // INSERTION
00570       // =========
00571       //
00578 
00582       void insert(bool value);
00588       void insert(const bool* value, unsigned long size);
00594       void put(const bool* value, unsigned long size);
00598       void insert(signed char value);
00604       void insert(const signed char* value, unsigned long size);
00610       void put(const signed char* value, unsigned long size);
00614       void insert(short value);
00620       void insert(const short* value, unsigned long size);
00626       void put(const short* value, unsigned long size);
00630       void insert(long value);
00636       void insert(const long* value, unsigned long size);
00642       void put(const long* value, unsigned long size);
00643 
00647       void insert(longlong value);
00653       void insert(const longlong* value, unsigned long size);
00659       void put(const longlong* value, unsigned long size);
00660 
00664       void insert(float value);
00670       void insert(const float* value, unsigned long size);
00676       void put(const float* value, unsigned long size);
00680       void insert(double value);
00686       void insert(const double* value, unsigned long size);
00692       void put(const double* value, unsigned long size);
00699       void insert(const char* value);
00706       void put(const char* value);
00715       void insert(const char** value, unsigned long size);
00724       void put(const char** value, unsigned long size);
00725 
00727 
00728    //
00729    // Private attributes and methods with ValueType args
00730    //
00731    private:
00732 
00733       //
00734       // Value store
00735       //
00736       union
00737       {
00738          // scalar values
00739          bool boolValue;
00740          signed char byteValue;
00741          short shortValue;
00742          long intValue;
00743          longlong longValue;
00744          float floatValue;
00745          double doubleValue;
00746          // strings
00747          char* stringValue;
00748          // arrays of primitive types
00749          void* arrayValue;
00750          // string arrays
00751          char** stringArrayValue;
00752       };
00753 
00754       //
00755       // Identifies the type of a contained value
00756       //
00757       ValueType type;
00758 
00759       //
00760       // The number of elements for array values.
00761       // size = 0 for scalar values
00762       //
00763       unsigned long size;
00764 
00765       //
00766       // If true, indicates that the memory pointed to by
00767       // stringValue, arrayValue, or stringArrayValue needs
00768       // to be released before inserting a new value or
00769       // deleting the data entry.
00770       //
00771       bool rel;
00772 
00773    void release();
00774    size_t elementSize(ValueType type) const;
00775    void* extractArray(ValueType type, unsigned long& size, bool copy) const;
00776    void replace(ValueType type, const void* v, unsigned long size, bool copy);
00777    void throwTypeMismatch(rdaDataEntry::ValueType expected) const;
00778 };
00779 
00780 #ifndef RDA_HAS_NO_IOSTREAM
00781    #ifndef RDA_HAS_NO_STD_IOSTREAM
00782       #include <iostream>
00783       using std::ostream;
00784       using std::endl;
00785    #else
00786       #include <iostream.h>
00787    #endif
00788 
00792 ostream& operator<<(ostream& os, const rdaDataEntry& dataEntry);
00793 #endif
00794 
00795 #endif

RDA-2.3 documentation - 27 Jun 2007 - N.Trofimov