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

#include "UChar.h"
#include "io/OutStream.h"

/// Constructor for non-array storage
UChar::UChar( const Unit& unit, int value, bool scaleValue )
    : Int( unit, value, scaleValue )
{
    typeSize_ = sizeof( unsigned char ),
    binaryType_ = UCHAR1;
}

/// Constructor from binary
UChar::UChar( const Unit& unit, const void *binary )
    : Int( unit, 0, false )
{
    typeSize_ = sizeof( unsigned char ),
    binaryType_ = UCHAR1;
    fromBinary( binary );
}

/// Return a pointer to a new copy
UChar* UChar::copy() const
{
    return new UChar( *unit_, value_, false );
}

/// Send the data value to the indicated stream.
/// Return the number of bytes written.
/// For now, assume little-endian.
unsigned int UChar::toStream( OutStream& outStream ) const
{
    return outStream.write( ( const char* )&value_, typeSize_ ).bytesWritten();
}

void UChar::fromBinary( const void *buffer )
{
    value_ = 0;
    memcpy( ( void * ) & value_, ( const void * ) buffer, typeSize_ );
}

/// Protected Empty constructor for use bya DataEntry class
UChar::UChar()
    : Int()
{
    typeSize_ = sizeof( unsigned char ),
    binaryType_ = UCHAR1;
}

