libalvalue  2.4.3.28-r2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
alvalue.h
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef _LIBALVALUE_ALVALUE_ALVALUE_H_
12 #define _LIBALVALUE_ALVALUE_ALVALUE_H_
13 
14 # include <cstdio>
15 # include <string>
16 # include <vector>
17 
18 # include <alvalue/config.h>
19 
20 namespace AL
21 {
22 
27 #ifndef ALVALUE_VERBOSITY
28 # define ALVALUE_VERBOSITY
29 
35  typedef enum ALVALUE_API _TVerbosity
36  {
37  VerbosityNone=0,
38  VerbosityMini,
39  VerbosityMedium,
40  VerbosityFull
41  } Verbosity;
42 #endif
43 
53  {
54  friend void ConvertALValueToSoapXml(const ALValue *pAlValue,
55  std::string &strToFill,
56  bool bInAnArray);
57  friend class ALNetwork;
58 
59  public:
64  typedef int TALValueInt;
69  typedef float TALValueFloat;
74  typedef double TALValueDouble;
79  typedef bool TALValueBool;
84  typedef std::string TALValueString;
85 
90  typedef std::vector<unsigned char> TAlValueBinaryData;
95  typedef TAlValueBinaryData::iterator ITAlValueBinaryData;
100  typedef TAlValueBinaryData::const_iterator CITAlValueBinaryData;
101 
106  typedef std::vector<ALValue> TAlValueArray;
111  typedef TAlValueArray::iterator ITAlValueArray;
116  typedef TAlValueArray::const_iterator CITAlValueArray;
117 
122  union unionValue {
130  };
131 
132  public:
145  enum Type {
146  TypeInvalid = 0,
153  TypeBinary
154  };
155 
156  public:
158  ALValue();
163  ALValue(const bool &value);
168  ALValue(const int &value);
173  ALValue(const double &value);
178  ALValue(const float &value);
183  ALValue(const std::string &value);
188  ALValue(const char *value);
189 
194  ALValue(const std::vector<std::string> &pListString);
199  ALValue(const std::vector<float> &pListFloat);
204  ALValue(const std::vector<int> &pListInt);
205 
211  ALValue(const void *value, int nBytes);
217  ALValue(const char **pArrayOfString, int nNbrString);
223  ALValue(const float *pFloat, int nNbrElement);
229  ALValue(const int *pInt, int nNbrElement);
230 
235  ALValue(const TAlValueBinaryData &rhs);
240  ALValue(ALValue const &rhs);
241 
243  virtual ~ALValue();
244 
246  void clear();
247 
254  ALValue& operator=(const ALValue &rhs);
256  ALValue& operator=(const bool &rhs);
258  ALValue& operator=(const int &rhs);
260  ALValue& operator=(const double &rhs);
262  ALValue& operator=(const float &rhs);
264  ALValue& operator=(const char *rhs);
266  ALValue& operator=(const TAlValueBinaryData &rhs);
267 
273  bool operator==(ALValue const &other) const;
279  bool operator!=(ALValue const &other) const;
280 
288  operator bool&();
296  operator const bool() const;
304  operator int&();
312  operator const int() const;
320  operator float&();
328  operator const float() const;
329 
337  operator const double() const;
338 
346  operator long long() const;
347 
354  operator std::string&();
362  operator const std::string&() const;
363 
371  operator TAlValueBinaryData&();
379  operator const TAlValueBinaryData&() const;
387  operator const void*() const;
388 
393  typedef std::vector<std::string> TStringArray;
398  typedef std::vector<float> TFloatArray;
403  typedef std::vector<int> TIntArray;
404 
412  operator TStringArray() const;
420  operator TFloatArray() const;
428  operator TIntArray() const;
429 
436  ALValue& setObject(const void* pData, int nDataSizeInBytes);
437 
443  void SetBinary(const void *rhs, int nDataSizeInBytes);
450  ALValue& SetBinaryNoCopy(const void *rhs, int nDataSizeInBytes);
451 
456  const void* GetBinary() const;
461  const void* getObject() const;
462 
467  void *getPtrValue();
468 
478  void ToStringArray(TStringArray &pArrayToFill,
479  bool bInsertDefaultOnError = false) const;
489  void ToFloatArray(TFloatArray &pArrayToFill,
490  bool bInsertDefaultOnError = false) const;
500  void ToIntArray(TIntArray &pArrayToFill,
501  bool bInsertDefaultOnError = false) const;
502 
503 
510  ALValue& operator[](int i);
511 
518  const ALValue& operator[](int i) const;
519 
524  enum Type getType() const;
525 
530  bool isValid () const;
535  bool isArray () const;
540  bool isBool () const;
545  bool isInt () const;
550  bool isFloat () const;
555  bool isString() const;
560  bool isObject() const;
565  bool isBinary() const;
570  std::vector<unsigned char> asRaw() const;
571 
577  unsigned int getSize() const;
578 
579 
589  void arrayReserve(int size);
590 
596  void arraySetSize(int size);
597 
607  void arrayPush(const ALValue &pSrcToCopyNotOwned);
608 
616  void arrayPopFront();
617 
628  std::string toString(Verbosity pnVerbosity = VerbosityMini) const;
629 
639  std::string toPythonBuffer() const;
640 
650  bool decodeB64(const char *pszB64);
651 
661  bool decodeB64Object(const char *pszB64);
662 
667  void encodeB64(std::string &strOutput) const;
668 
681  static enum Type deduceType(const char *szInput,
682  int nLimitToLen = 0x7FFFFFFF);
683 
692  void unSerializeFromText(const char *szInput,
693  int nLimitToLen = 0x7FFFFFFF);
694 
700  std::string serializeToText(void) const;
701 
707  static bool xUnSerializeFromText_InnerTest(void);
708 
709  template <typename T0>
710  static ALValue array(const T0 &a0);
711  template <typename T0, typename T1>
712  static ALValue array(const T0 &a0, const T1 &a1);
713  template <typename T0, typename T1, typename T2>
714  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2);
715  template <typename T0, typename T1, typename T2, typename T3>
716  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3);
717  template <typename T0, typename T1, typename T2, typename T3, typename T4>
718  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4);
719  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
720  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5);
721  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
722  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6);
723  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
724  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);
725  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
726  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);
727  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
728  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);
729 
730  protected:
732  void xInvalidate();
733  void xAssertCompatibleType(enum Type pnWantedType);
734  void xAssertType(enum Type pnWantedType) const;
735  void xAssertArraySize(int pnSize) const;
740  void assertStruct();
744  int _type;
746  union unionValue _value;
747 
748  public:
753  const unionValue getUnionValue();
754 
759  TAlValueArray *getArrayPtr() const;
760 
766  static std::string TypeToString(enum Type pnType);
767 
768  };
769 
770  template <typename T0>
771  ALValue ALValue::array(const T0 &a0)
772  {
773  ALValue result;
774  result.arraySetSize(1);
775  result[0] = a0;
776  return result;
777  }
778 
779  template <typename T0, typename T1>
780  ALValue ALValue::array(const T0 &a0, const T1 &a1)
781  {
782  ALValue result;
783  result.arraySetSize(2);
784  result[0] = a0;
785  result[1] = a1;
786  return result;
787  }
788 
789  template <typename T0, typename T1, typename T2>
790  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2)
791  {
792  ALValue result;
793  result.arraySetSize(3);
794  result[0] = a0;
795  result[1] = a1;
796  result[2] = a2;
797  return result;
798  }
799 
800  template <typename T0, typename T1, typename T2, typename T3>
801  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3)
802  {
803  ALValue result;
804  result.arraySetSize(4);
805  result[0] = a0;
806  result[1] = a1;
807  result[2] = a2;
808  result[3] = a3;
809  return result;
810  }
811 
812  template <typename T0, typename T1, typename T2, typename T3, typename T4>
813  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4)
814  {
815  ALValue result;
816  result.arraySetSize(5);
817  result[0] = a0;
818  result[1] = a1;
819  result[2] = a2;
820  result[3] = a3;
821  result[4] = a4;
822  return result;
823  }
824 
825  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
826  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5)
827  {
828  ALValue result;
829  result.arraySetSize(6);
830  result[0] = a0;
831  result[1] = a1;
832  result[2] = a2;
833  result[3] = a3;
834  result[4] = a4;
835  result[5] = a5;
836  return result;
837  }
838 
839  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
840  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6)
841  {
842  ALValue result;
843  result.arraySetSize(7);
844  result[0] = a0;
845  result[1] = a1;
846  result[2] = a2;
847  result[3] = a3;
848  result[4] = a4;
849  result[5] = a5;
850  result[6] = a6;
851  return result;
852  }
853 
854  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
855  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)
856  {
857  ALValue result;
858  result.arraySetSize(8);
859  result[0] = a0;
860  result[1] = a1;
861  result[2] = a2;
862  result[3] = a3;
863  result[4] = a4;
864  result[5] = a5;
865  result[6] = a6;
866  result[7] = a7;
867  return result;
868  }
869 
870  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
871  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)
872  {
873  ALValue result;
874  result.arraySetSize(9);
875  result[0] = a0;
876  result[1] = a1;
877  result[2] = a2;
878  result[3] = a3;
879  result[4] = a4;
880  result[5] = a5;
881  result[6] = a6;
882  result[7] = a7;
883  result[8] = a8;
884  return result;
885  }
886 
887  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
888  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)
889  {
890  ALValue result;
891  result.arraySetSize(10);
892  result[0] = a0;
893  result[1] = a1;
894  result[2] = a2;
895  result[3] = a3;
896  result[4] = a4;
897  result[5] = a5;
898  result[6] = a6;
899  result[7] = a7;
900  result[8] = a8;
901  result[9] = a9;
902  return result;
903  }
904  ALVALUE_API bool operator <(const ALValue& a, const ALValue& b);
905 } // namespace AL
906 
912 std::ostream &operator<<(std::ostream &os, const AL::ALValue &a);
913 
914 
915 #endif // _LIBALVALUE_ALVALUE_ALVALUE_H_
std::string TALValueString
Type definition to std::string.
Definition: alvalue.h:84
static ALValue array(const T0 &a0)
Definition: alvalue.h:771
TAlValueBinaryData * asObject
Definition: alvalue.h:128
TAlValueBinaryData::iterator ITAlValueBinaryData
Iterator to a vector of unsigned char used for binary data.
Definition: alvalue.h:95
std::ostream & operator<<(std::ostream &os, const AL::ALValue &a)
Stream operator for ALValue.
TALValueInt asInt
Definition: alvalue.h:125
TAlValueArray * asArray
Definition: alvalue.h:123
TALValueString * asString
Definition: alvalue.h:127
dll import/export
int TALValueInt
Type definition to int.
Definition: alvalue.h:64
int _type
Type of the ALValue.
Definition: alvalue.h:744
unionValue is a union to different type of ALValue.
Definition: alvalue.h:122
std::vector< unsigned char > TAlValueBinaryData
Vector of unsigned char used for binary data.
Definition: alvalue.h:90
#define ALVALUE_API
Definition: config.h:37
TAlValueBinaryData * asBinary
Definition: alvalue.h:129
TALValueBool asBool
Definition: alvalue.h:124
std::vector< std::string > TStringArray
Vector of std::string.
Definition: alvalue.h:393
TAlValueArray::iterator ITAlValueArray
Iterator to a vector of ALValue.
Definition: alvalue.h:111
void arraySetSize(int size)
Specify the size of the array this will call vector::resize.
double TALValueDouble
Type definition to double.
Definition: alvalue.h:74
ALValue is a class to manipulate differente value type.
Definition: alvalue.h:52
float TALValueFloat
Type definition to float.
Definition: alvalue.h:69
TAlValueBinaryData::const_iterator CITAlValueBinaryData
Const iterator to a vector of unsigned char used for binary data.
Definition: alvalue.h:100
TAlValueArray::const_iterator CITAlValueArray
Const iterator to a vector of ALValue.
Definition: alvalue.h:116
std::vector< float > TFloatArray
Vector of float.
Definition: alvalue.h:398
bool TALValueBool
Type definition to bool.
Definition: alvalue.h:79
Type
Type of ALValue.
Definition: alvalue.h:145
std::vector< ALValue > TAlValueArray
Vector of ALValue.
Definition: alvalue.h:106
TALValueFloat asFloat
Definition: alvalue.h:126
std::vector< int > TIntArray
Vector of int.
Definition: alvalue.h:403