/** \file
 *
 *  Contains the DataValue class implementation.
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 *
 */

#include "DataValue.h"

#include "StrValue.h"
#include "UChar.h"
#include "Short.h"
#include "UShort.h"
#include "Float2.h"
#include "Float3.h"
#include "Int.h"
#include "Float.h"
#include "Double4.h"
#include "Double6.h"
#include "Double.h"
#include <stdio.h>

/// Override delete
void DataValue::operator delete( void* p )
{
    switch( ( ( DataValue* )p )->binaryType_ )
    {
    case MULTIVALUE:
        printf( "Delete strValue\n" );
        delete( StrValue* )p;
        break;
    case UCHAR1:
        printf( "Delete uchar\n" );
        delete( UChar* )p;
        break;
    case SHORT2:
        printf( "Delete short\n" );
        delete( Short* )p;
        break;
    case USHORT2:
        printf( "Delete ushort\n" );
        delete( UShort* )p;
        break;
    case FLOAT2:
        printf( "Delete float2\n" );
        delete( Float2* )p;
        break;
    case FLOAT3:
        printf( "Delete float3\n" );
        delete( Float3* )p;
        break;
    case INT4:
        printf( "Delete int\n" );
        delete( Int* )p;
        break;
    case FLOAT4:
        printf( "Delete float\n" );
        delete( Float* )p;
        break;
    case DOUBLE4:
        printf( "Delete double4\n" );
        delete( Double4* )p;
        break;
    case DOUBLE6:
        printf( "Delete double6\n" );
        delete( Double6* )p;
        break;
    case DOUBLE8:
        printf( "Delete double\n" );
        delete( Double* )p;
        break;
    default:
        break;
    }
}

/// Copy value to bool
bool DataValue::copyTo( const Unit& unit, bool& assignTo ) const
{
    int temp;
    if( copyTo( unit, temp ) )
    {
        assignTo = temp;
        return true;
    }
    return false;
}

/// Comparison with bool
int DataValue::compare( const Unit& unit, const bool& compareTo ) const
{
    return compare( unit, ( int )compareTo );
}

/// Equality test with with bool
bool DataValue::equals( const Unit& unit, const bool& compareTo ) const
{
    return equals( unit, ( int )compareTo );
}

/// set from bool value
bool DataValue::setFrom( const Unit& unit, bool value )
{
    return setFrom( unit, ( int )value );
}

