libalvalue  2.8.7.4
 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  ~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 
475  int *getIntPtr();
476 
483  float *getFloatPtr();
484 
494  void ToStringArray(TStringArray &pArrayToFill,
495  bool bInsertDefaultOnError = false) const;
505  void ToFloatArray(TFloatArray &pArrayToFill,
506  bool bInsertDefaultOnError = false) const;
516  void ToIntArray(TIntArray &pArrayToFill,
517  bool bInsertDefaultOnError = false) const;
518 
519 
526  ALValue& operator[](int i);
527 
534  const ALValue& operator[](int i) const;
535 
540  enum Type getType() const;
541 
546  bool isValid () const;
551  bool isArray () const;
556  bool isBool () const;
561  bool isInt () const;
566  bool isFloat () const;
571  bool isString() const;
576  bool isObject() const;
581  bool isBinary() const;
586  std::vector<unsigned char> asRaw() const;
587 
593  unsigned int getSize() const;
594 
595 
605  void arrayReserve(int size);
606 
612  void arraySetSize(int size);
613 
623  void arrayPush(const ALValue &pSrcToCopyNotOwned);
624 
632  void arrayPopFront();
633 
644  std::string toString(Verbosity pnVerbosity = VerbosityMini) const;
645 
655  std::string toPythonBuffer() const;
656 
666  bool decodeB64(const char *pszB64);
667 
677  bool decodeB64Object(const char *pszB64);
678 
683  void encodeB64(std::string &strOutput) const;
684 
697  static enum Type deduceType(const char *szInput,
698  int nLimitToLen = 0x7FFFFFFF);
699 
708  void unSerializeFromText(const char *szInput,
709  int nLimitToLen = 0x7FFFFFFF);
710 
716  std::string serializeToText(void) const;
717 
723  static bool xUnSerializeFromText_InnerTest(void);
724 
725  template <typename T0>
726  static ALValue array(const T0 &a0);
727  template <typename T0, typename T1>
728  static ALValue array(const T0 &a0, const T1 &a1);
729  template <typename T0, typename T1, typename T2>
730  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2);
731  template <typename T0, typename T1, typename T2, typename T3>
732  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3);
733  template <typename T0, typename T1, typename T2, typename T3, typename T4>
734  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4);
735  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
736  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5);
737  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
738  static ALValue array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6);
739  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
740  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);
741  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
742  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);
743  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
744  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);
745 
746  protected:
748  void xInvalidate();
749  void xAssertCompatibleType(enum Type pnWantedType);
750  void xAssertType(enum Type pnWantedType) const;
751  void xAssertArraySize(int pnSize) const;
756  void assertStruct();
760  int _type;
762  union unionValue _value;
763 
764  public:
769  const unionValue getUnionValue();
770 
775  TAlValueArray *getArrayPtr() const;
776 
782  static std::string TypeToString(enum Type pnType);
783 
784  };
785 
786  template <typename T0>
787  ALValue ALValue::array(const T0 &a0)
788  {
789  ALValue result;
790  result.arraySetSize(1);
791  result[0] = a0;
792  return result;
793  }
794 
795  template <typename T0, typename T1>
796  ALValue ALValue::array(const T0 &a0, const T1 &a1)
797  {
798  ALValue result;
799  result.arraySetSize(2);
800  result[0] = a0;
801  result[1] = a1;
802  return result;
803  }
804 
805  template <typename T0, typename T1, typename T2>
806  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2)
807  {
808  ALValue result;
809  result.arraySetSize(3);
810  result[0] = a0;
811  result[1] = a1;
812  result[2] = a2;
813  return result;
814  }
815 
816  template <typename T0, typename T1, typename T2, typename T3>
817  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3)
818  {
819  ALValue result;
820  result.arraySetSize(4);
821  result[0] = a0;
822  result[1] = a1;
823  result[2] = a2;
824  result[3] = a3;
825  return result;
826  }
827 
828  template <typename T0, typename T1, typename T2, typename T3, typename T4>
829  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4)
830  {
831  ALValue result;
832  result.arraySetSize(5);
833  result[0] = a0;
834  result[1] = a1;
835  result[2] = a2;
836  result[3] = a3;
837  result[4] = a4;
838  return result;
839  }
840 
841  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
842  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5)
843  {
844  ALValue result;
845  result.arraySetSize(6);
846  result[0] = a0;
847  result[1] = a1;
848  result[2] = a2;
849  result[3] = a3;
850  result[4] = a4;
851  result[5] = a5;
852  return result;
853  }
854 
855  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
856  ALValue ALValue::array(const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6)
857  {
858  ALValue result;
859  result.arraySetSize(7);
860  result[0] = a0;
861  result[1] = a1;
862  result[2] = a2;
863  result[3] = a3;
864  result[4] = a4;
865  result[5] = a5;
866  result[6] = a6;
867  return result;
868  }
869 
870  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
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)
872  {
873  ALValue result;
874  result.arraySetSize(8);
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  return result;
884  }
885 
886  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
887  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)
888  {
889  ALValue result;
890  result.arraySetSize(9);
891  result[0] = a0;
892  result[1] = a1;
893  result[2] = a2;
894  result[3] = a3;
895  result[4] = a4;
896  result[5] = a5;
897  result[6] = a6;
898  result[7] = a7;
899  result[8] = a8;
900  return result;
901  }
902 
903  template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
904  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)
905  {
906  ALValue result;
907  result.arraySetSize(10);
908  result[0] = a0;
909  result[1] = a1;
910  result[2] = a2;
911  result[3] = a3;
912  result[4] = a4;
913  result[5] = a5;
914  result[6] = a6;
915  result[7] = a7;
916  result[8] = a8;
917  result[9] = a9;
918  return result;
919  }
920  ALVALUE_API bool operator <(const ALValue& a, const ALValue& b);
921 } // namespace AL
922 
928 std::ostream &operator<<(std::ostream &os, const AL::ALValue &a);
929 
930 
931 #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:787
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:760
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