libalvalue  1.14.5
alvalue/alvalue.h
Go to the documentation of this file.
00001 
00010 #pragma once
00011 #ifndef _LIBALVALUE_ALVALUE_ALVALUE_H_
00012 #define _LIBALVALUE_ALVALUE_ALVALUE_H_
00013 
00014 # include <cstdio>
00015 # include <string>
00016 # include <vector>
00017 
00018 # include <alvalue/config.h>
00019 
00020 namespace AL
00021 {
00022 
00027 #ifndef ALVALUE_VERBOSITY
00028 # define ALVALUE_VERBOSITY
00029 
00033   typedef enum ALVALUE_API _TVerbosity {
00034     VerbosityNone=0,   
00035       VerbosityMini,   
00036       VerbosityMedium, 
00037       VerbosityFull    
00038       } Verbosity;
00039 #endif
00040 
00049   class ALVALUE_API ALValue
00050   {
00051     friend void ConvertALValueToSoapXml(const ALValue *pAlValue,
00052                                         std::string &strToFill,
00053                                         bool bInAnArray);
00054     friend class ALNetwork;
00055 
00056   public:
00061     typedef int                                TALValueInt;
00066     typedef float                              TALValueFloat;
00071     typedef double                             TALValueDouble;
00076     typedef bool                               TALValueBool;
00081     typedef std::string                        TALValueString;
00082 
00087     typedef std::vector<unsigned char>         TAlValueBinaryData;
00092     typedef TAlValueBinaryData::iterator       ITAlValueBinaryData;
00097     typedef TAlValueBinaryData::const_iterator CITAlValueBinaryData;
00098 
00103     typedef std::vector<ALValue>               TAlValueArray;
00108     typedef TAlValueArray::iterator            ITAlValueArray;
00113     typedef TAlValueArray::const_iterator      CITAlValueArray;
00114 
00119     union unionValue {
00120       TAlValueArray      *asArray;  
00121       TALValueBool       asBool;    
00122       TALValueInt        asInt;     
00123       TALValueFloat      asFloat;   
00124       TALValueString     *asString; 
00125       TAlValueBinaryData *asObject; 
00126       TAlValueBinaryData *asBinary; 
00127     };
00128 
00129   public:
00142     enum Type {
00143       TypeInvalid = 0, 
00144       TypeArray,       
00145       TypeBool,        
00146       TypeInt,         
00147       TypeFloat,       
00148       TypeString,      
00149       TypeObject,      
00150       TypeBinary       
00151     };
00152 
00153   public:
00155     ALValue();
00160     ALValue(const bool &value);
00165     ALValue(const int &value);
00170     ALValue(const double &value);
00175     ALValue(const float &value);
00180     ALValue(const std::string &value);
00185     ALValue(const char *value);
00186 
00191     ALValue(const std::vector<std::string> &pListString);
00196     ALValue(const std::vector<float> &pListFloat);
00201     ALValue(const std::vector<int> &pListInt);
00202 
00208     ALValue(const void *value, int nBytes);
00214     ALValue(const char **pArrayOfString, int nNbrString);
00220     ALValue(const float *pFloat, int nNbrElement);
00226     ALValue(const int *pInt, int nNbrElement);
00227 
00232     ALValue(const TAlValueBinaryData &rhs);
00237     ALValue(ALValue const &rhs);
00238 
00240     virtual ~ALValue();
00241 
00243     void clear();
00244 
00251     ALValue& operator=(const ALValue &rhs);
00253     ALValue& operator=(const bool &rhs);
00255     ALValue& operator=(const int &rhs);
00257     ALValue& operator=(const double &rhs);
00259     ALValue& operator=(const float &rhs);
00261     ALValue& operator=(const char *rhs);
00263     ALValue& operator=(const TAlValueBinaryData &rhs);
00264 
00270     bool operator==(ALValue const &other) const;
00276     bool operator!=(ALValue const &other) const;
00277 
00285     operator       bool&();
00293     operator const bool() const;
00301     operator       int&();
00309     operator const int() const;
00317     operator       float&();
00325     operator const float() const;
00326 
00334     operator const double() const;
00335 
00343     operator       std::string&();
00351     operator const std::string&() const;
00352 
00360     operator       TAlValueBinaryData&();
00368     operator const TAlValueBinaryData&() const;
00376     operator const void*() const;
00377 
00382     typedef std::vector<std::string> TStringArray;
00387     typedef std::vector<float>       TFloatArray;
00392     typedef std::vector<int>         TIntArray;
00393 
00401     operator TStringArray() const;
00409     operator TFloatArray() const;
00417     operator TIntArray() const;
00418 
00425     ALValue& setObject(const void* pData, int nDataSizeInBytes);
00426 
00432     void     SetBinary(const void *rhs, int nDataSizeInBytes);
00439     ALValue& SetBinaryNoCopy(const void *rhs, int nDataSizeInBytes);
00440 
00445     const void* GetBinary() const;
00450     const void* getObject() const;
00451 
00456     float *getPtrValue();
00457 
00467     void ToStringArray(TStringArray &pArrayToFill,
00468                        bool bInsertDefaultOnError = false) const;
00478     void ToFloatArray(TFloatArray &pArrayToFill,
00479                       bool bInsertDefaultOnError = false) const;
00489     void ToIntArray(TIntArray &pArrayToFill,
00490                     bool bInsertDefaultOnError = false) const;
00491 
00492 
00499     ALValue& operator[](int i);
00500 
00507     const ALValue& operator[](int i) const;
00508 
00513     enum Type getType() const;
00514 
00519     bool isValid () const;
00524     bool isArray () const;
00529     bool isBool  () const;
00534     bool isInt   () const;
00539     bool isFloat () const;
00544     bool isString() const;
00549     bool isObject() const;
00554     bool isBinary() const;
00555 
00556 
00562     unsigned int getSize() const;
00563 
00564 
00574     void arrayReserve(int size);
00575 
00581     void arraySetSize(int size);
00582 
00592     void arrayPush(const ALValue &pSrcToCopyNotOwned);
00593 
00601     void arrayPopFront();
00602 
00613     std::string toString(Verbosity pnVerbosity = VerbosityMini) const;
00614 
00624     std::string toPythonBuffer() const;
00625 
00635     bool decodeB64(const char *pszB64);
00636 
00646     bool decodeB64Object(const char *pszB64);
00647 
00652     void encodeB64(std::string &strOutput) const;
00653 
00666     static enum Type deduceType(const char *szInput,
00667                                 int nLimitToLen = 0x7FFFFFFF);
00668 
00677     void unSerializeFromText(const char *szInput,
00678                              int nLimitToLen = 0x7FFFFFFF);
00679 
00685     std::string serializeToText(void) const;
00686 
00692     static bool xUnSerializeFromText_InnerTest(void);
00693 
00694     template <typename T0>
00695       static ALValue array(const T0 &a0);
00696     template <typename T0, typename T1>
00697       static ALValue array(const T0 &a0, const T1 &a1);
00698     template <typename T0, typename T1, typename T2>
00699       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2);
00700     template <typename T0, typename T1, typename T2, typename T3>
00701       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3);
00702     template <typename T0, typename T1, typename T2, typename T3, typename T4>
00703       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4);
00704     template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00705       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5);
00706     template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00707       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6);
00708     template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00709       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7);
00710     template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00711       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8);
00712     template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00713       static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8, const T9 &a9);
00714 
00715   protected:
00717     void xInvalidate();
00718     void xAssertCompatibleType(enum Type pnWantedType);
00719     void xAssertType(enum Type pnWantedType) const;
00720     void xAssertArraySize(int pnSize) const;
00725     void assertStruct();
00729     int              _type;
00731     union unionValue _value;
00732 
00733   public:
00738     const unionValue getUnionValue();
00739 
00744     TAlValueArray *getArrayPtr() const;
00745 
00751     static std::string TypeToString(enum Type pnType);
00752 
00753   };
00754 
00755   template <typename T0>
00756   ALValue ALValue::array(const T0 &a0)
00757   {
00758     ALValue result;
00759     result.arraySetSize(1);
00760     result[0] = a0;
00761     return result;
00762   }
00763 
00764   template <typename T0, typename T1>
00765   ALValue ALValue::array(const T0 &a0, const T1 &a1)
00766   {
00767     ALValue result;
00768     result.arraySetSize(2);
00769     result[0] = a0;
00770     result[1] = a1;
00771     return result;
00772   }
00773 
00774   template <typename T0, typename T1, typename T2>
00775   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2)
00776   {
00777     ALValue result;
00778     result.arraySetSize(3);
00779     result[0] = a0;
00780     result[1] = a1;
00781     result[2] = a2;
00782     return result;
00783   }
00784 
00785   template <typename T0, typename T1, typename T2, typename T3>
00786   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3)
00787   {
00788     ALValue result;
00789     result.arraySetSize(4);
00790     result[0] = a0;
00791     result[1] = a1;
00792     result[2] = a2;
00793     result[3] = a3;
00794     return result;
00795   }
00796 
00797   template <typename T0, typename T1, typename T2, typename T3, typename T4>
00798   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4)
00799   {
00800     ALValue result;
00801     result.arraySetSize(5);
00802     result[0] = a0;
00803     result[1] = a1;
00804     result[2] = a2;
00805     result[3] = a3;
00806     result[4] = a4;
00807     return result;
00808   }
00809 
00810   template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00811   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5)
00812   {
00813     ALValue result;
00814     result.arraySetSize(6);
00815     result[0] = a0;
00816     result[1] = a1;
00817     result[2] = a2;
00818     result[3] = a3;
00819     result[4] = a4;
00820     result[5] = a5;
00821     return result;
00822   }
00823 
00824   template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00825   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6)
00826   {
00827     ALValue result;
00828     result.arraySetSize(7);
00829     result[0] = a0;
00830     result[1] = a1;
00831     result[2] = a2;
00832     result[3] = a3;
00833     result[4] = a4;
00834     result[5] = a5;
00835     result[6] = a6;
00836     return result;
00837   }
00838 
00839   template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00840   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7)
00841   {
00842     ALValue result;
00843     result.arraySetSize(8);
00844     result[0] = a0;
00845     result[1] = a1;
00846     result[2] = a2;
00847     result[3] = a3;
00848     result[4] = a4;
00849     result[5] = a5;
00850     result[6] = a6;
00851     result[7] = a7;
00852     return result;
00853   }
00854 
00855   template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
00856   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8)
00857   {
00858     ALValue result;
00859     result.arraySetSize(9);
00860     result[0] = a0;
00861     result[1] = a1;
00862     result[2] = a2;
00863     result[3] = a3;
00864     result[4] = a4;
00865     result[5] = a5;
00866     result[6] = a6;
00867     result[7] = a7;
00868     result[8] = a8;
00869     return result;
00870   }
00871 
00872   template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
00873   ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6, const T7 &a7, const T8 &a8, const T9 &a9)
00874   {
00875     ALValue result;
00876     result.arraySetSize(10);
00877     result[0] = a0;
00878     result[1] = a1;
00879     result[2] = a2;
00880     result[3] = a3;
00881     result[4] = a4;
00882     result[5] = a5;
00883     result[6] = a6;
00884     result[7] = a7;
00885     result[8] = a8;
00886     result[9] = a9;
00887     return result;
00888   }
00889 } // namespace AL
00890 
00896 std::ostream &operator<<(std::ostream &os, const AL::ALValue &a);
00897 
00898 #endif  // _LIBALVALUE_ALVALUE_ALVALUE_H_
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines