Changing struct data handling now using std vector of characters

parent 2c0441c0
...@@ -357,7 +357,7 @@ public: ...@@ -357,7 +357,7 @@ public:
* @param[in] pData Data pointer * @param[in] pData Data pointer
* @param[in] iBytes Number of bytes * @param[in] iBytes Number of bytes
*/ */
void SetData( void* pData, const int iBytes ); void SetData( const void* pData, const int iBytes );
//! Returns a pointer to the struct value (only for datatype STRUCT) //! Returns a pointer to the struct value (only for datatype STRUCT)
/** /**
...@@ -544,7 +544,7 @@ private: ...@@ -544,7 +544,7 @@ private:
double dValue; //!< Value if type is double double dValue; //!< Value if type is double
std::string sValue; //!< Value if type is string std::string sValue; //!< Value if type is string
CVAStruct* xValue; //!< Value if type is struct CVAStruct* xValue; //!< Value if type is struct
void* pData; //!< Value if type is data std::vector< char > vcData; //!< Value if type is data
int iDataSize; //!< Value byte number if type is data int iDataSize; //!< Value byte number if type is data
CVASampleBuffer sbValue; //!< Value if type is sample buffer CVASampleBuffer sbValue; //!< Value if type is sample buffer
......
...@@ -270,17 +270,16 @@ std::string CVAStruct::ToString( const int iIndent ) const ...@@ -270,17 +270,16 @@ std::string CVAStruct::ToString( const int iIndent ) const
// ---------------------------------------------------- // ----------------------------------------------------
// Constructors // Constructors
CVAStructValue::CVAStructValue() : iDatatype( UNASSIGNED ), xValue( NULL ), pData( NULL ) {}; CVAStructValue::CVAStructValue() : iDatatype( UNASSIGNED ), xValue( NULL ) {};
CVAStructValue::CVAStructValue( const bool value ) : iDatatype( BOOL ), bValue( value ), xValue( NULL ), pData( NULL ) {}; CVAStructValue::CVAStructValue( const bool value ) : iDatatype( BOOL ), bValue( value ), xValue( NULL ) {};
CVAStructValue::CVAStructValue( const int value ) : iDatatype( INT ), iValue( value ), xValue( NULL ), pData( NULL ) {}; CVAStructValue::CVAStructValue( const int value ) : iDatatype( INT ), iValue( value ), xValue( NULL ) {};
CVAStructValue::CVAStructValue( const double value ) : iDatatype( DOUBLE ), dValue( value ), xValue( NULL ), pData( NULL ) {}; CVAStructValue::CVAStructValue( const double value ) : iDatatype( DOUBLE ), dValue( value ), xValue( NULL ) {};
CVAStructValue::CVAStructValue( const char* value ) : iDatatype( STRING ), sValue( value ), xValue( NULL ), pData( NULL ) {}; CVAStructValue::CVAStructValue( const char* value ) : iDatatype( STRING ), sValue( value ), xValue( NULL ) {};
CVAStructValue::CVAStructValue( const std::string& value ) : iDatatype( STRING ), sValue( value ), xValue( NULL ), pData( NULL ) {}; CVAStructValue::CVAStructValue( const std::string& value ) : iDatatype( STRING ), sValue( value ), xValue( NULL ) {};
CVAStructValue::CVAStructValue( const CVAStruct& value ) : iDatatype( STRUCT ), xValue( new CVAStruct( value ) ), pData( NULL ) {}; CVAStructValue::CVAStructValue( const CVAStruct& value ) : iDatatype( STRUCT ), xValue( new CVAStruct( value ) ) {};
CVAStructValue::CVAStructValue( void* pData, const int iBytes ) CVAStructValue::CVAStructValue( void* pData, const int iBytes )
: iDatatype( DATA ) : iDatatype( DATA )
, pData( NULL )
, xValue( NULL ) , xValue( NULL )
{ {
SetData( pData, iBytes ); SetData( pData, iBytes );
...@@ -291,7 +290,9 @@ CVAStructValue::CVAStructValue( const CVASampleBuffer& oSampleBuffer ) ...@@ -291,7 +290,9 @@ CVAStructValue::CVAStructValue( const CVASampleBuffer& oSampleBuffer )
, sbValue( oSampleBuffer ) , sbValue( oSampleBuffer )
{} {}
CVAStructValue::CVAStructValue( const CVAStructValue& rhs ) : iDatatype( UNASSIGNED ), xValue( NULL ), pData( NULL ) CVAStructValue::CVAStructValue( const CVAStructValue& rhs )
: iDatatype( UNASSIGNED )
, xValue( NULL )
{ {
*this = rhs; *this = rhs;
} }
...@@ -299,56 +300,70 @@ CVAStructValue::CVAStructValue( const CVAStructValue& rhs ) : iDatatype( UNASSIG ...@@ -299,56 +300,70 @@ CVAStructValue::CVAStructValue( const CVAStructValue& rhs ) : iDatatype( UNASSIG
CVAStructValue::~CVAStructValue() CVAStructValue::~CVAStructValue()
{ {
delete xValue; delete xValue;
delete[] pData;
} }
int CVAStructValue::GetDatatype() const { int CVAStructValue::GetDatatype() const
{
return iDatatype; return iDatatype;
} }
int CVAStructValue::GetDataSize() const { int CVAStructValue::GetDataSize() const
{
return iDataSize; return iDataSize;
} }
const void* CVAStructValue::GetData() const { const void* CVAStructValue::GetData() const
if( iDatatype != DATA ) VA_EXCEPT1( "Key value is no binary data" ); {
return pData; if( iDatatype != DATA )
VA_EXCEPT1( "Key value is no binary data" );
return &( vcData[ 0 ] );
} }
void* CVAStructValue::GetData() { void* CVAStructValue::GetData()
if( iDatatype != DATA ) VA_EXCEPT1( "Key value is no binary data" ); {
return pData; if( iDatatype != DATA )
VA_EXCEPT1( "Key value is no binary data" );
return &( vcData[ 0 ] );
} }
void CVAStructValue::SetData( void* pData, const int iBytes ) { void CVAStructValue::SetData( const void* pIncomingData, const int iIncomingBytes )
{
assert( iDatatype == DATA ); assert( iDatatype == DATA );
if( iDatatype != DATA ) return;
if( pData == NULL ) if( iDatatype != DATA )
return;
if( pIncomingData == NULL )
{ {
assert( iBytes == 0 ); assert( iIncomingBytes == 0 );
} }
else else
{ {
assert( iBytes > 0 ); assert( iIncomingBytes > 0 );
} }
// Free previous data // Free previous data
delete[] this->pData; vcData.clear();
this->pData = NULL;
// Allocate new buffer and copy the data // Allocate new buffer and copy the data
if( pData ) if( pIncomingData )
{ {
this->pData = new char[ iBytes ]; if( vcData.size() < iIncomingBytes )
iDataSize = iBytes; vcData.resize( iIncomingBytes );
memcpy( this->pData, pData, iBytes );
iDataSize = iIncomingBytes;
//for( size_t i = 0; i < vcData.size(); i++ )
//vcData[ i ] = pData[ i ];
memcpy( GetData(), pIncomingData, iIncomingBytes );
} }
} }
const CVAStruct& CVAStructValue::GetStruct() const const CVAStruct& CVAStructValue::GetStruct() const
{ {
if( iDatatype != STRUCT ) if( iDatatype != STRUCT )
VA_EXCEPT1( "Key value is not a structure" ); VA_EXCEPT1( "Key value is not a structure" );
assert( xValue ); assert( xValue );
return *xValue; return *xValue;
...@@ -356,7 +371,7 @@ const CVAStruct& CVAStructValue::GetStruct() const ...@@ -356,7 +371,7 @@ const CVAStruct& CVAStructValue::GetStruct() const
CVAStruct& CVAStructValue::GetStruct() CVAStruct& CVAStructValue::GetStruct()
{ {
if( iDatatype != STRUCT ) if( iDatatype != STRUCT )
VA_EXCEPT1( "Key value is not a structure" ); VA_EXCEPT1( "Key value is not a structure" );
assert( xValue ); assert( xValue );
return *xValue; return *xValue;
...@@ -414,7 +429,6 @@ CVAStructValue& CVAStructValue::operator=( const CVAStructValue& rhs ) ...@@ -414,7 +429,6 @@ CVAStructValue& CVAStructValue::operator=( const CVAStructValue& rhs )
return *this; return *this;
// Free data, if the key was of datatype DATA before // Free data, if the key was of datatype DATA before
delete[] pData;
delete xValue; delete xValue;
iDataSize = 0; iDataSize = 0;
...@@ -445,7 +459,7 @@ CVAStructValue& CVAStructValue::operator=( const CVAStructValue& rhs ) ...@@ -445,7 +459,7 @@ CVAStructValue& CVAStructValue::operator=( const CVAStructValue& rhs )
case DATA: case DATA:
// Autonome Kopie des Schssel BLOBs erzeugen // Autonome Kopie des Schssel BLOBs erzeugen
SetData( rhs.pData, rhs.iDataSize ); SetData( rhs.GetData(), rhs.iDataSize );
break; break;
case SAMPLEBUFFER: case SAMPLEBUFFER:
...@@ -535,7 +549,7 @@ CVAStructValue::operator bool() const ...@@ -535,7 +549,7 @@ CVAStructValue::operator bool() const
std::transform( s.begin(), s.end(), s.begin(), ( int( *)( int ) ) ::toupper ); std::transform( s.begin(), s.end(), s.begin(), ( int( *)( int ) ) ::toupper );
if( ( s == "no" ) || ( s == "false" ) ) if( ( s == "no" ) || ( s == "false" ) )
return false; return false;
if( ( s == "yes" ) || ( s == "true" ) ) if( ( s == "yes" ) || ( s == "true" ) )
return true; return true;
} }
...@@ -702,7 +716,7 @@ CVAStructValue::operator void*( ) const ...@@ -702,7 +716,7 @@ CVAStructValue::operator void*( ) const
VA_EXCEPT1( "Types cannot be converted" ); VA_EXCEPT1( "Types cannot be converted" );
} }
return pData; return ( void* ) GetData();
} }
CVAStructValue::operator const CVASampleBuffer&( ) const CVAStructValue::operator const CVASampleBuffer&( ) const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment