libalvalue  1.14.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends
AL::ALValue Class Reference

ALValue is a class to manipulate differente value type. More...

#include <alvalue/alvalue.h>

List of all members.

Classes

union  unionValue
 unionValue is a union to different type of ALValue. More...

Public Types

enum  Type {
  TypeInvalid = 0, TypeArray, TypeBool, TypeInt,
  TypeFloat, TypeString, TypeObject, TypeBinary
}
 Type of ALValue. More...
typedef int TALValueInt
 Type definition to int.
typedef float TALValueFloat
 Type definition to float.
typedef double TALValueDouble
 Type definition to double.
typedef bool TALValueBool
 Type definition to bool.
typedef std::string TALValueString
 Type definition to std::string.
typedef std::vector< unsigned
char > 
TAlValueBinaryData
 Vector of unsigned char used for binary data.
typedef
TAlValueBinaryData::iterator 
ITAlValueBinaryData
 Iterator to a vector of unsigned char used for binary data.
typedef
TAlValueBinaryData::const_iterator 
CITAlValueBinaryData
 Const iterator to a vector of unsigned char used for binary data.
typedef std::vector< ALValueTAlValueArray
 Vector of ALValue.
typedef TAlValueArray::iterator ITAlValueArray
 Iterator to a vector of ALValue.
typedef
TAlValueArray::const_iterator 
CITAlValueArray
 Const iterator to a vector of ALValue.
typedef std::vector< std::string > TStringArray
 Vector of std::string.
typedef std::vector< float > TFloatArray
 Vector of float.
typedef std::vector< int > TIntArray
 Vector of int.

Public Member Functions

 ALValue ()
 Default constructor.
 ALValue (const bool &value)
 Constructor.
 ALValue (const int &value)
 Constructor.
 ALValue (const double &value)
 Constructor.
 ALValue (const float &value)
 Constructor.
 ALValue (const std::string &value)
 Constructor.
 ALValue (const char *value)
 Constructor.
 ALValue (const std::vector< std::string > &pListString)
 Constructor.
 ALValue (const std::vector< float > &pListFloat)
 Constructor.
 ALValue (const std::vector< int > &pListInt)
 Constructor.
 ALValue (const void *value, int nBytes)
 Constructor.
 ALValue (const char **pArrayOfString, int nNbrString)
 Constructor.
 ALValue (const float *pFloat, int nNbrElement)
 Constructor.
 ALValue (const int *pInt, int nNbrElement)
 Constructor.
 ALValue (const TAlValueBinaryData &rhs)
 Copy constructor form binary data.
 ALValue (ALValue const &rhs)
 Copy constructor.
virtual ~ALValue ()
 Desctuctor.
void clear ()
 Erase the current value.
ALValueoperator= (const ALValue &rhs)
 Makes a copy of rhs, discarding previous content, so that the new content of is equivalent in both type and value to rhs.
ALValueoperator= (const bool &rhs)
ALValueoperator= (const int &rhs)
ALValueoperator= (const double &rhs)
ALValueoperator= (const float &rhs)
ALValueoperator= (const char *rhs)
ALValueoperator= (const TAlValueBinaryData &rhs)
bool operator== (ALValue const &other) const
 alvalue.Type == other.alvalue.Type && alvalue.unionValue == other.alvalue.unionValue
bool operator!= (ALValue const &other) const
 alvalue.Type != other.alvalue.Type && alvalue.unionValue != other.alvalue.unionValue
 operator bool & ()
 Conversion operator to bool.
 operator const bool () const
 Conversion operator to const bool.
 operator int & ()
 Conversion operator to int.
 operator const int () const
 Conversion operator to const int.
 operator float & ()
 Conversion operator to float.
 operator const float () const
 Conversion operator to const float.
 operator const double () const
 Conversion operator to const double.
 operator std::string & ()
 Conversion operator to std::string.
 operator const std::string & () const
 Conversion operator to const std::string.
 operator TAlValueBinaryData & ()
 Conversion operator to binary data.
 operator const TAlValueBinaryData & () const
 Conversion operator to const binary data.
 operator const void * () const
 Conversion operator to const void*.
 operator TStringArray () const
 Conversion operator to a vector of stf::string.
 operator TFloatArray () const
 Conversion operator to a vector of float.
 operator TIntArray () const
 Conversion operator to a vector of int.
ALValuesetObject (const void *pData, int nDataSizeInBytes)
 Set ALValue with an object data.
void SetBinary (const void *rhs, int nDataSizeInBytes)
 Set ALValue with a binary data.
ALValueSetBinaryNoCopy (const void *rhs, int nDataSizeInBytes)
 Set ALValue with a binary data. It won't copy the data.
const void * GetBinary () const
 Explicit operator to convert to const void*.
const void * getObject () const
 Explicit operator to convert to const void*.
float * getPtrValue ()
 Get pointer on value, only allowed with 32bits variable.
void ToStringArray (TStringArray &pArrayToFill, bool bInsertDefaultOnError=false) const
 Explicit convert to vector<string>.
void ToFloatArray (TFloatArray &pArrayToFill, bool bInsertDefaultOnError=false) const
 Explicit convert to vector<float>.
void ToIntArray (TIntArray &pArrayToFill, bool bInsertDefaultOnError=false) const
 Explicit convert to vector<int>.
ALValueoperator[] (int i)
 Get a reference to the ALValue at position i in the vector.
const ALValueoperator[] (int i) const
 Get a reference to the ALValue at position i in the vector.
enum Type getType () const
 Gat the type of the stored value.
bool isValid () const
 Check if the value has been set.
bool isArray () const
 Check if the value is an array.
bool isBool () const
 Check if the value is a boolean.
bool isInt () const
 Check if the value is an integer.
bool isFloat () const
 Check if the value is a float.
bool isString () const
 Check if the value is a string.
bool isObject () const
 Check if the value is a binary object.
bool isBinary () const
 Check if the value is a binary.
unsigned int getSize () const
 Get the size for string, objectm array, binary, invalid values.
void arrayReserve (int size)
 Specify the size the array values will use.
void arraySetSize (int size)
 Specify the size of the array this will call vector::resize.
void arrayPush (const ALValue &pSrcToCopyNotOwned)
 Adds a new element at the end of the vector, after its current last element.
void arrayPopFront ()
 Pop the first element of the array. Deleting it.
std::string toString (Verbosity pnVerbosity=VerbosityMini) const
 Get a string describing this object, for debug purpose.
std::string toPythonBuffer () const
 Build python buffer from ALValue binary.
bool decodeB64 (const char *pszB64)
 Decode a buffer from B64 to binary.
bool decodeB64Object (const char *pszB64)
 Decode a buffer from B64 to binary object.
void encodeB64 (std::string &strOutput) const
 Encode a binaries alvalue to B64 (binary 64 / uuencoded).
void unSerializeFromText (const char *szInput, int nLimitToLen=0x7FFFFFFF)
 Create an ALValue from a text.
std::string serializeToText (void) const
 Create a text describing an ALValue.
const unionValue getUnionValue ()
 Get the value of the ALValue.
TAlValueArraygetArrayPtr () const
 Get pointer on array value.

Static Public Member Functions

static enum Type deduceType (const char *szInput, int nLimitToLen=0x7FFFFFFF)
 Analyses a string and try to guess the type of data describe in the string.
static bool xUnSerializeFromText_InnerTest (void)
 Internal function to validate the correct functionnality of unSerializeFromText.
template<typename T0 >
static ALValue array (const T0 &a0)
template<typename T0 , typename T1 >
static ALValue array (const T0 &a0, const T1 &a1)
template<typename T0 , typename T1 , typename T2 >
static ALValue array (const T0 &a0, const T1 &a1, const T2 &a2)
template<typename T0 , typename T1 , typename T2 , typename T3 >
static ALValue array (const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3)
template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 >
static ALValue array (const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4)
template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
static ALValue array (const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5)
template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 >
static ALValue array (const T0 &a0, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6)
template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 >
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)
template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8 >
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)
template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8 , typename T9 >
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)
static std::string TypeToString (enum Type pnType)
 Get a string with name of ALValue type.

Protected Attributes

int _type
 Type of the ALValue.
union unionValue _value
 Value of the ALValue.

Friends

class ALNetwork
void ConvertALValueToSoapXml (const ALValue *pAlValue, std::string &strToFill, bool bInAnArray)

Detailed Description

ALValue is a class to manipulate differente value type.

It's using to convert multiple value type to one type, to ease the communication or storage of differente values.

Definition at line 49 of file alvalue.h.


Member Enumeration Documentation

Type of ALValue.

Warning:
this enum order matter, it is used in paramtype.h
double support cannot be added. This would break:
     ALValue v;
     v = 0.1; 
sometime the compiler will use the double constructor instead of the float one, breaking too much user code.
Enumerator:
TypeInvalid 

Invalid type.

TypeArray 

Array type.

TypeBool 

Boolean type.

TypeInt 

Integer type.

TypeFloat 

Float type.

TypeString 

String type.

TypeObject 

Object type.

TypeBinary 

Base64 type.

Definition at line 142 of file alvalue.h.


Constructor & Destructor Documentation

AL::ALValue::ALValue ( const bool &  value)

Constructor.

Parameters:
valuevalue of the ALValue
AL::ALValue::ALValue ( const int &  value)

Constructor.

Parameters:
valuevalue of the ALValue
AL::ALValue::ALValue ( const double &  value)

Constructor.

Parameters:
valuevalue of the ALValue
AL::ALValue::ALValue ( const float &  value)

Constructor.

Parameters:
valuevalue of the ALValue
AL::ALValue::ALValue ( const std::string &  value)

Constructor.

Parameters:
valuevalue of the ALValue
AL::ALValue::ALValue ( const char *  value)

Constructor.

Parameters:
valuevalue of the ALValue
AL::ALValue::ALValue ( const std::vector< std::string > &  pListString)

Constructor.

Parameters:
pListStringvalue of the ALValue
AL::ALValue::ALValue ( const std::vector< float > &  pListFloat)

Constructor.

Parameters:
pListFloatvalue of the ALValue
AL::ALValue::ALValue ( const std::vector< int > &  pListInt)

Constructor.

Parameters:
pListIntvalue of the ALValue
AL::ALValue::ALValue ( const void *  value,
int  nBytes 
)

Constructor.

Parameters:
valuevalue of the ALValue
nBytessize of the value
AL::ALValue::ALValue ( const char **  pArrayOfString,
int  nNbrString 
)

Constructor.

Parameters:
pArrayOfStringvalue of the ALValue
nNbrStringstring's number
AL::ALValue::ALValue ( const float *  pFloat,
int  nNbrElement 
)

Constructor.

Parameters:
pFloatvalue of the ALValue
nNbrElementfloat's number
AL::ALValue::ALValue ( const int *  pInt,
int  nNbrElement 
)

Constructor.

Parameters:
pIntvalue of the ALValue
nNbrElementint's number

Copy constructor form binary data.

Parameters:
rhsvalue copied
AL::ALValue::ALValue ( ALValue const &  rhs)

Copy constructor.

Parameters:
rhsvalue copied

Member Function Documentation

Pop the first element of the array. Deleting it.

Does completely delete the first element of the array, if the AL::ALValue is an array, and if it is not empty.

void AL::ALValue::arrayPush ( const ALValue pSrcToCopyNotOwned)

Adds a new element at the end of the vector, after its current last element.

The content of this new element is initialized to a copy of pSrcToCopyNotOwned.

Parameters:
pSrcToCopyNotOwnedValue to be copied to the new element. Push a new value in the array
void AL::ALValue::arrayReserve ( int  size)

Specify the size the array values will use.

Requests that the capacity of the allocated storage space for the ALValue of the vector container be at least enough to hold size elements.

Parameters:
sizeminimum amount desired as capacity of allocated storage
Exceptions:
ALErrorif alvalue.type != TypeArray
void AL::ALValue::arraySetSize ( int  size)

Specify the size of the array this will call vector::resize.

Parameters:
sizethe new size of the array
bool AL::ALValue::decodeB64 ( const char *  pszB64)

Decode a buffer from B64 to binary.

Decode a string containing some binaries encoded in B64 (binary 64 / uuencoded)

Parameters:
pszB64the buffer to decode
Returns:
true
Warning:
public method called from FillAlValueFromXmlNodeContent...
bool AL::ALValue::decodeB64Object ( const char *  pszB64)

Decode a buffer from B64 to binary object.

Decode a string containing some binaries encoded in B64 (binary 64 / uuencoded)

Parameters:
pszB64the buffer to decode
Returns:
true
Warning:
public method called from FillAlValueFromXmlNodeContent...
static enum Type AL::ALValue::deduceType ( const char *  szInput,
int  nLimitToLen = 0x7FFFFFFF 
) [static]

Analyses a string and try to guess the type of data describe in the string.

eg: "5" => int; "'toto'" => string; [3,5] => array ...

Parameters:
szInputa text to analyse, eg: "[36, 3, "toto", 3.5, [1,2,3]]"
nLimitToLenlimit analysis to nLimitToLen first characters
Returns:
type of the value
Exceptions:
ALERROR
void AL::ALValue::encodeB64 ( std::string &  strOutput) const

Encode a binaries alvalue to B64 (binary 64 / uuencoded).

Parameters:
strOutputthe buffer to receive or data encoded in B64

Get pointer on array value.

Returns:
a pointer on the array
const void* AL::ALValue::GetBinary ( ) const

Explicit operator to convert to const void*.

Returns:
A pointer on value.
const void* AL::ALValue::getObject ( ) const

Explicit operator to convert to const void*.

Returns:
A pointer on value.

Get pointer on value, only allowed with 32bits variable.

Returns:
A pointer on value.
unsigned int AL::ALValue::getSize ( ) const

Get the size for string, objectm array, binary, invalid values.

Returns:
the size of the ALValue (0 if alvalue.type == InvalidType)
Exceptions:
ALERRORif the value is null
enum Type AL::ALValue::getType ( ) const

Gat the type of the stored value.

See also:
Type.
Returns:
the type of the value.

Get the value of the ALValue.

Returns:
the value
bool AL::ALValue::isArray ( ) const

Check if the value is an array.

Returns:
true if alvalue.type == TypeArray, false otherswise
bool AL::ALValue::isBinary ( ) const

Check if the value is a binary.

Returns:
true if alvalue.type == TypeBinary, false otherswise
bool AL::ALValue::isBool ( ) const

Check if the value is a boolean.

Returns:
true if alvalue.type == TypeBool, false otherswise
bool AL::ALValue::isFloat ( ) const

Check if the value is a float.

Returns:
true if alvalue.type == TypeFloat, false otherswise
bool AL::ALValue::isInt ( ) const

Check if the value is an integer.

Returns:
true if alvalue.type == TypeInt, false otherswise
bool AL::ALValue::isObject ( ) const

Check if the value is a binary object.

Returns:
true if alvalue.type == TypeObject, false otherswise
bool AL::ALValue::isString ( ) const

Check if the value is a string.

Returns:
true if alvalue.type == TypeString, false otherswise
bool AL::ALValue::isValid ( ) const

Check if the value has been set.

Returns:
true if alvalue.type != TypeInvalid, false otherswise
AL::ALValue::operator bool & ( )

Conversion operator to bool.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator const bool ( ) const

Conversion operator to const bool.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator const double ( ) const

Conversion operator to const double.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator const float ( ) const

Conversion operator to const float.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator const int ( ) const

Conversion operator to const int.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator const std::string & ( ) const

Conversion operator to const std::string.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator const TAlValueBinaryData & ( ) const

Conversion operator to const binary data.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator const void * ( ) const

Conversion operator to const void*.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator float & ( )

Conversion operator to float.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator int & ( )

Conversion operator to int.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator std::string & ( )

Conversion operator to std::string.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator TAlValueBinaryData & ( )

Conversion operator to binary data.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator TFloatArray ( ) const

Conversion operator to a vector of float.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator TIntArray ( ) const

Conversion operator to a vector of int.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
AL::ALValue::operator TStringArray ( ) const

Conversion operator to a vector of stf::string.

Assert the object is compatible with a wanted type. If the object is unitialiazed, it will be changed to the good type

Exceptions:
ALERROR
bool AL::ALValue::operator!= ( ALValue const &  other) const

alvalue.Type != other.alvalue.Type && alvalue.unionValue != other.alvalue.unionValue

Returns:
true if not equal ALValue, false otherwise
ALValue& AL::ALValue::operator= ( const ALValue rhs)

Makes a copy of rhs, discarding previous content, so that the new content of is equivalent in both type and value to rhs.

Parameters:
rhsvalue copied
ALValue& AL::ALValue::operator= ( const bool &  rhs)
=

ALValue& AL::ALValue::operator= ( const int &  rhs)
=

ALValue& AL::ALValue::operator= ( const double &  rhs)
=

ALValue& AL::ALValue::operator= ( const float &  rhs)
=

ALValue& AL::ALValue::operator= ( const char *  rhs)
=

ALValue& AL::ALValue::operator= ( const TAlValueBinaryData rhs)
=

bool AL::ALValue::operator== ( ALValue const &  other) const

alvalue.Type == other.alvalue.Type && alvalue.unionValue == other.alvalue.unionValue

Returns:
true if equal ALValue, false otherwise
ALValue& AL::ALValue::operator[] ( int  i)

Get a reference to the ALValue at position i in the vector.

Parameters:
iposition in the vector
Returns:
a reference to the ALValue
Exceptions:
ALERRORif alvalue.type != TypeArray || i out of range.
const ALValue& AL::ALValue::operator[] ( int  i) const

Get a reference to the ALValue at position i in the vector.

Parameters:
iposition in the vector
Returns:
a reference to the ALValue
Exceptions:
ALERRORif alvalue.type != TypeArray || i out of range.
std::string AL::ALValue::serializeToText ( void  ) const

Create a text describing an ALValue.

Returns:
the new string
Exceptions:
ALERROR
void AL::ALValue::SetBinary ( const void *  rhs,
int  nDataSizeInBytes 
)

Set ALValue with a binary data.

Parameters:
rhspointer to data
nDataSizeInBytesdata's size
ALValue& AL::ALValue::SetBinaryNoCopy ( const void *  rhs,
int  nDataSizeInBytes 
)

Set ALValue with a binary data. It won't copy the data.

Parameters:
rhspointer to data
nDataSizeInBytes(unused)
Returns:
ALValue with the data.
ALValue& AL::ALValue::setObject ( const void *  pData,
int  nDataSizeInBytes 
)

Set ALValue with an object data.

Parameters:
pDatapointer to data
nDataSizeInBytesdata's size
Returns:
ALValue with the data.
void AL::ALValue::ToFloatArray ( TFloatArray pArrayToFill,
bool  bInsertDefaultOnError = false 
) const

Explicit convert to vector<float>.

Parameters:
pArrayToFillthe value to fill with string value from the ALValue
bInsertDefaultOnErrora flag to inform what to do on a not wanted type. If set to false, invalid value are skipped, on true empty string will be inserted in the vector
void AL::ALValue::ToIntArray ( TIntArray pArrayToFill,
bool  bInsertDefaultOnError = false 
) const

Explicit convert to vector<int>.

Parameters:
pArrayToFillthe value to fill with string value from the ALValue
bInsertDefaultOnErrora flag to inform what to do on a not wanted type. If set to false, invalid value are skipped, on true empty string will be inserted in the vector
std::string AL::ALValue::toPythonBuffer ( ) const

Build python buffer from ALValue binary.

Decode a string containing some binaries encoded in B64 (binary 64 / uuencoded).

Returns:
python compatible string
Warning:
public method called from FillAlValueFromXmlNodeContent...
std::string AL::ALValue::toString ( Verbosity  pnVerbosity = VerbosityMini) const

Get a string describing this object, for debug purpose.

Parameters:
pnVerbositystyle of ouput format
Warning:
the VerbosityMini style is used in some code, it's the minimal description of the contents of an alvalue, with [] to describe array.
it's done to be directly evaluatable in script language (tested with: urbi and ruby)
Exceptions:
ALERROR
void AL::ALValue::ToStringArray ( TStringArray pArrayToFill,
bool  bInsertDefaultOnError = false 
) const

Explicit convert to vector<string>.

Parameters:
pArrayToFillthe value to fill with string value from the ALValue
bInsertDefaultOnErrora flag to inform what to do on a not wanted type. If set to false, invalid value are skipped, on true empty string will be inserted in the vector
static std::string AL::ALValue::TypeToString ( enum Type  pnType) [static]

Get a string with name of ALValue type.

Returns:
"Invalid", "Array", "Bool", "Int", "Float", "String", "Object", "Binary"
void AL::ALValue::unSerializeFromText ( const char *  szInput,
int  nLimitToLen = 0x7FFFFFFF 
)

Create an ALValue from a text.

Parameters:
szInputthe source analysed to construct the alvalue, eg: "1" or "[36,3,"toto",3.5,[1,2,3]]"
nLimitToLenlimit analysis to nLimitToLen first characters (used in recursion)
Exceptions:
ALERROR
static bool AL::ALValue::xUnSerializeFromText_InnerTest ( void  ) [static]

Internal function to validate the correct functionnality of unSerializeFromText.

Returns:
true if test ok, false othewise

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines