//----------------------- CSPVariant.h ------------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************


#ifndef _CSPVARIANT
#define _CSPVARIANT

#include "CSPConf.h"
#include "CSPLib.h"
#include "CSPString.h"
#include "CSPWString.h"
#include "CSPTime.h"
#include "CSPBuffer.h"

class CSPVarArray;

class CSPLIB_CLASS_EXPORT CSPVariant : public CSPObject
{
public:
	enum Types
	{
		TYPE_EMPTY,
		TYPE_NULL,
		TYPE_UINT,
		TYPE_INT,
		TYPE_UINT64,
		TYPE_INT64,
		TYPE_ULONG,
		TYPE_LONG,
		TYPE_USHORT,
		TYPE_SHORT,
		TYPE_CHAR,
		TYPE_UCHAR,
		TYPE_DOUBLE,
		TYPE_LDOUBLE,
		TYPE_FLOAT,
		TYPE_BOOL,
		TYPE_TIME,
		TYPE_DATE,
		TYPE_DATETIME,
		TYPE_STRING,
		TYPE_WSTRING,
		TYPE_VAR_ARRAY,
		TYPE_BINARY
	 };

	CSPVariant();
	virtual ~CSPVariant();
	CSPVariant( const CSPVariant& varVariant );

	CSPVariant( const CSPVarArray& VarArray );

	CSPVariant( const CSPString& strString );
	CSPVariant( const char* pszString );
	CSPVariant( const CSPWString& wstrString );
	CSPVariant( const wchar_t* pwszString );
	CSPVariant( const CSPTime& tTime );
	CSPVariant( const CSPDate& dDate );		
	CSPVariant( const CSPDateTime& dtDateTime );
	
	CSPVariant( unsigned long ulULongVal );
	CSPVariant( long lLongVal );
	CSPVariant( unsigned int uiUIntVal );
	CSPVariant( int iIntVal );
	CSPVariant( unsigned __int64 ui64UIntVal );
	CSPVariant( __int64 i64IntVal );
	CSPVariant( unsigned short ushUShortVal );
	CSPVariant( short shShortVal );
	CSPVariant( unsigned char uchUCharVal );
	CSPVariant( char chCharVal );
	CSPVariant( bool bBoolVal );
	CSPVariant( long double ldblLDoubleVal );
	CSPVariant( double dblDoubleVal );
	CSPVariant( float fFloatVal );
	

	CSPVariant& operator = ( const CSPVariant& varVariant );

	CSPVariant& operator = ( const CSPVarArray& VarArray );

	CSPVariant& operator = ( const CSPString& strString );
	CSPVariant& operator = ( const char* strString );
	CSPVariant& operator = ( const CSPWString& wstrString );
	CSPVariant& operator = ( const wchar_t* wstrString );
	CSPVariant& operator = ( const CSPTime& tTime );
	CSPVariant& operator = ( const CSPDate& dDate );		
	CSPVariant& operator = ( const CSPDateTime& dtDateTime );
	
	CSPVariant& operator = ( unsigned long ulULongVal );
	CSPVariant& operator = ( long lLongVal );
	CSPVariant& operator = ( unsigned int uiUIntVal );
	CSPVariant& operator = ( int iIntVal );
	CSPVariant& operator = ( unsigned __int64 ui64UIntVal );
	CSPVariant& operator = ( __int64 i64IntVal );
	CSPVariant& operator = ( unsigned short ushUShortVal );
	CSPVariant& operator = ( short shShortVal );
	CSPVariant& operator = ( unsigned char uchUCharVal );
	CSPVariant& operator = ( char chCharVal );
	CSPVariant& operator = ( bool bBoolVal );
	CSPVariant& operator = ( long double ldblLDoubleVal );
	CSPVariant& operator = ( double dblDoubleVal );
	CSPVariant& operator = ( float fFloatVal );

	void SetVariant( const CSPVariant& varVariant );
	void SetVarArray( const CSPVarArray& VarArray );
	void SetString( const CSPString& strString = CSPString() );
	void SetWString( const CSPWString& wstrString = CSPWString() );
	void SetTime( const CSPTime& tTime = CSPTime() );
	void SetDate( const CSPDate& dDate = CSPDate() );
	void SetDateTime( const CSPDateTime& dtDateTime = CSPDateTime() );

	void SetULong( unsigned long ulULongVal = 0 );
	void SetLong( long lLongVal = 0 );
	void SetUInt( unsigned int uiUIntVal = 0 );
	void SetInt( int iIntVal = 0 );
	void SetUInt64( unsigned __int64 ui64UIntVal = 0 );
	void SetInt64( __int64 i64IntVal = 0 );
	void SetUShort( unsigned short ushShortVal = 0 );
	void SetShort( short shUShortVal = 0 );
	void SetUChar( unsigned char uchUCharVal = 0 );
	void SetChar( char chCharVal = 0 );
	void SetBool( bool bBoolVal = 0 );
	void SetLongDouble( long double ldblLDoubleVal = 0.0 );
	void SetDouble( double dblDoubleVal = 0.0 );
	void SetFloat( float fFloatVal = 0.0 );

	operator CSPVarArray() const;

	//operator CSPString() const;
	//operator CSPWString() const;
	operator CSPTime() const;
	operator CSPDate() const;
	operator CSPDateTime() const;

	operator unsigned long () const;
	operator long () const;
	operator unsigned int () const;
	operator int() const;
	operator unsigned __int64 () const;
	operator __int64 () const;
	operator unsigned short () const;
	operator short () const;
	operator unsigned char () const;
	operator char () const;
	operator bool () const;
	operator long double () const;
	operator double () const;
	operator float () const;

	CSPVarArray GetVarArray() const;

	CSPString GetString() const;
	CSPWString GetWString() const;
	CSPTime GetTime() const;
	CSPDate GetDate() const;
	CSPDateTime GetDateTime() const;

	unsigned long GetULong() const;
	long GetLong() const;
	unsigned int GetUInt() const;
	int GetInt() const;
	unsigned __int64 GetUInt64() const;
	__int64 GetInt64() const;
	unsigned short GetUShort() const;
	short GetShort() const;
	unsigned char GetUChar() const;
	char GetChar() const;
	bool GetBool() const;
	long double GetLongDouble() const;
	double GetDouble() const;
	float GetFloat() const;


	bool operator == ( const CSPVariant& varVariant ) const;
	bool operator != ( const CSPVariant& varVariant ) const;
	

	unsigned long GetType() const;
	void Clear();
	bool IsEmpty() const;
	void SetNull();
	bool IsNull() const;
	void GetBinaryData( CSPBuffer& Data ) const;
	void SetBinaryData( const CSPBuffer& Data );
	unsigned long GetBinaryDataSize() const;


protected:
	unsigned long ulDataType;
	unsigned long ulBinarySize;
	
	union
	{
		void* pvData;		
		long lLong;
		unsigned long ulULong;
		int iInt;
		unsigned int uiUInt;
		__int64 i64Int;
		unsigned __int64 ui64UInt;
		short shShort;
		unsigned short ushUShort;
		char chChar;
		unsigned char uchUChar;
		double dblDouble;
		float fFloat;
		long double ldblLDouble;
		bool bBool;
	};
};

#endif
