libalvalue  2.1.4.13
 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 std::string&();
354  operator const std::string&() const;
355 
363  operator TAlValueBinaryData&();
371  operator const TAlValueBinaryData&() const;
379  operator const void*() const;
380 
385  typedef std::vector<std::string> TStringArray;
390  typedef std::vector<float> TFloatArray;
395  typedef std::vector<int> TIntArray;
396 
404  operator TStringArray() const;
412  operator TFloatArray() const;
420  operator TIntArray() const;
421 
428  ALValue& setObject(const void* pData, int nDataSizeInBytes);
429 
435  void SetBinary(const void *rhs, int nDataSizeInBytes);
442  ALValue& SetBinaryNoCopy(const void *rhs, int nDataSizeInBytes);
443 
448  const void* GetBinary() const;
453  const void* getObject() const;
454 
459  void *getPtrValue();
460 
470  void ToStringArray(TStringArray &pArrayToFill,
471  bool bInsertDefaultOnError = false) const;
481  void ToFloatArray(TFloatArray &pArrayToFill,
482  bool bInsertDefaultOnError = false) const;
492  void ToIntArray(TIntArray &pArrayToFill,
493  bool bInsertDefaultOnError = false) const;
494 
495 
502  ALValue& operator[](int i);
503 
510  const ALValue& operator[](int i) const;
511 
516  enum Type getType() const;
517 
522  bool isValid () const;
527  bool isArray () const;
532  bool isBool () const;
537  bool isInt () const;
542  bool isFloat () const;
547  bool isString() const;
552  bool isObject() const;
557  bool isBinary() const;
562  std::vector<unsigned char> asRaw() const;
563 
569  unsigned int getSize() const;
570 
571 
581  void arrayReserve(int size);
582 
588  void arraySetSize(int size);
589 
599  void arrayPush(const ALValue &pSrcToCopyNotOwned);
600 
608  void arrayPopFront();
609 
620  std::string toString(Verbosity pnVerbosity = VerbosityMini) const;
621 
631  std::string toPythonBuffer() const;
632 
642  bool decodeB64(const char *pszB64);
643 
653  bool decodeB64Object(const char *pszB64);
654 
659  void encodeB64(std::string &strOutput) const;
660 
673  static enum Type deduceType(const char *szInput,
674  int nLimitToLen = 0x7FFFFFFF);
675 
684  void unSerializeFromText(const char *szInput,
685  int nLimitToLen = 0x7FFFFFFF);
686 
692  std::string serializeToText(void) const;
693 
699  static bool xUnSerializeFromText_InnerTest(void);
700 
701  template <typename T0>
702  static ALValue array(const T0 &a0);
703  template <typename T0, typename T1>
704  static ALValue array(const T0 &a0, const T1 &a1);
705  template <typename T0, typename T1, typename T2>
706  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2);
707  template <typename T0, typename T1, typename T2, typename T3>
708  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3);
709  template <typename T0, typename T1, typename T2, typename T3, typename T4>
710  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4);
711  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
712  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5);
713  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
714  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6);
715  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
716  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);
717  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
718  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);
719  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
720  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);
721 
722  protected:
724  void xInvalidate();
725  void xAssertCompatibleType(enum Type pnWantedType);
726  void xAssertType(enum Type pnWantedType) const;
727  void xAssertArraySize(int pnSize) const;
732  void assertStruct();
736  int _type;
738  union unionValue _value;
739 
740  public:
745  const unionValue getUnionValue();
746 
751  TAlValueArray *getArrayPtr() const;
752 
758  static std::string TypeToString(enum Type pnType);
759 
760  };
761 
762  template <typename T0>
763  ALValue ALValue::array(const T0 &a0)
764  {
765  ALValue result;
766  result.arraySetSize(1);
767  result[0] = a0;
768  return result;
769  }
770 
771  template <typename T0, typename T1>
772  ALValue ALValue::array(const T0 &a0, const T1 &a1)
773  {
774  ALValue result;
775  result.arraySetSize(2);
776  result[0] = a0;
777  result[1] = a1;
778  return result;
779  }
780 
781  template <typename T0, typename T1, typename T2>
782  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2)
783  {
784  ALValue result;
785  result.arraySetSize(3);
786  result[0] = a0;
787  result[1] = a1;
788  result[2] = a2;
789  return result;
790  }
791 
792  template <typename T0, typename T1, typename T2, typename T3>
793  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3)
794  {
795  ALValue result;
796  result.arraySetSize(4);
797  result[0] = a0;
798  result[1] = a1;
799  result[2] = a2;
800  result[3] = a3;
801  return result;
802  }
803 
804  template <typename T0, typename T1, typename T2, typename T3, typename T4>
805  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4)
806  {
807  ALValue result;
808  result.arraySetSize(5);
809  result[0] = a0;
810  result[1] = a1;
811  result[2] = a2;
812  result[3] = a3;
813  result[4] = a4;
814  return result;
815  }
816 
817  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
818  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5)
819  {
820  ALValue result;
821  result.arraySetSize(6);
822  result[0] = a0;
823  result[1] = a1;
824  result[2] = a2;
825  result[3] = a3;
826  result[4] = a4;
827  result[5] = a5;
828  return result;
829  }
830 
831  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
832  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6)
833  {
834  ALValue result;
835  result.arraySetSize(7);
836  result[0] = a0;
837  result[1] = a1;
838  result[2] = a2;
839  result[3] = a3;
840  result[4] = a4;
841  result[5] = a5;
842  result[6] = a6;
843  return result;
844  }
845 
846  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
847  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)
848  {
849  ALValue result;
850  result.arraySetSize(8);
851  result[0] = a0;
852  result[1] = a1;
853  result[2] = a2;
854  result[3] = a3;
855  result[4] = a4;
856  result[5] = a5;
857  result[6] = a6;
858  result[7] = a7;
859  return result;
860  }
861 
862  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
863  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)
864  {
865  ALValue result;
866  result.arraySetSize(9);
867  result[0] = a0;
868  result[1] = a1;
869  result[2] = a2;
870  result[3] = a3;
871  result[4] = a4;
872  result[5] = a5;
873  result[6] = a6;
874  result[7] = a7;
875  result[8] = a8;
876  return result;
877  }
878 
879  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
880  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)
881  {
882  ALValue result;
883  result.arraySetSize(10);
884  result[0] = a0;
885  result[1] = a1;
886  result[2] = a2;
887  result[3] = a3;
888  result[4] = a4;
889  result[5] = a5;
890  result[6] = a6;
891  result[7] = a7;
892  result[8] = a8;
893  result[9] = a9;
894  return result;
895  }
896  ALVALUE_API bool operator <(const ALValue& a, const ALValue& b);
897 } // namespace AL
898 
904 std::ostream &operator<<(std::ostream &os, const AL::ALValue &a);
905 
906 
907 #endif // _LIBALVALUE_ALVALUE_ALVALUE_H_
TAlValueArray::iterator ITAlValueArray
Iterator to a vector of ALValue.
Definition: alvalue.h:111
std::vector< std::string > TStringArray
Vector of std::string.
Definition: alvalue.h:385
TALValueFloat asFloat
Definition: alvalue.h:126
std::vector< int > TIntArray
Vector of int.
Definition: alvalue.h:395
ALValue is a class to manipulate differente value type.
Definition: alvalue.h:52
TAlValueBinaryData * asBinary
Definition: alvalue.h:129
TAlValueArray::const_iterator CITAlValueArray
Const iterator to a vector of ALValue.
Definition: alvalue.h:116
int TALValueInt
Type definition to int.
Definition: alvalue.h:64
Type
Type of ALValue.
Definition: alvalue.h:145
static ALValue array(const T0 &a0)
Definition: alvalue.h:763
double TALValueDouble
Type definition to double.
Definition: alvalue.h:74
TAlValueArray * asArray
Definition: alvalue.h:123
std::ostream & operator<<(std::ostream &os, const AL::ALValue &a)
Stream operator for ALValue.
TALValueBool asBool
Definition: alvalue.h:124
std::vector< unsigned char > TAlValueBinaryData
Vector of unsigned char used for binary data.
Definition: alvalue.h:90
void arraySetSize(int size)
Specify the size of the array this will call vector::resize.
float TALValueFloat
Type definition to float.
Definition: alvalue.h:69
TALValueInt asInt
Definition: alvalue.h:125
#define ALVALUE_API
Definition: config.h:37
std::vector< ALValue > TAlValueArray
Vector of ALValue.
Definition: alvalue.h:106
TAlValueBinaryData::iterator ITAlValueBinaryData
Iterator to a vector of unsigned char used for binary data.
Definition: alvalue.h:95
std::vector< float > TFloatArray
Vector of float.
Definition: alvalue.h:390
TALValueString * asString
Definition: alvalue.h:127
TAlValueBinaryData::const_iterator CITAlValueBinaryData
Const iterator to a vector of unsigned char used for binary data.
Definition: alvalue.h:100
bool TALValueBool
Type definition to bool.
Definition: alvalue.h:79
int _type
Type of the ALValue.
Definition: alvalue.h:736
dll import/export
std::string TALValueString
Type definition to std::string.
Definition: alvalue.h:84
unionValue is a union to different type of ALValue.
Definition: alvalue.h:122
TAlValueBinaryData * asObject
Definition: alvalue.h:128