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

#ifndef UCHAR_H_
#define UCHAR_H_

#include "Int.h"

/**
 *  Wraps a 32-bit (4-byte) signed integer and unit for
 *  storage in a DataElement.  (Storage is in the most canonical
 *  form of the specified unit).  Provides methods for reading and
 *  writing the value to and from other DataValues, performing
 *  unit conversions as needed.

 *  Unlike the Int class, UChar objects are serialized as 1-byte
 *  numbers by casting the integer as an unsigned char.
 *
 *  Note: since these DataValues are created and destructed
 *  frequently, the new and delete operators have been overridden,
 *  so that objects can be re-used as needed.
 *
 *  UChar::MallocRing_  stores deleted objects.
 *
 * \ingroup data
 */
class UChar : public Int
{
public:

    /// Constructor
    UChar( const Unit& unit, int value, bool scaleValue = true );

    /// Constructor from binary
    UChar( const Unit& unit, const void *binary );

    /// Return a pointer to a new copy
    UChar* copy() const;

    /// Destructor
    virtual ~UChar() {}

    /// Send the data value to the indicated stream.
    /// Return the number of bytes written.
    /// For now, assume little-endian.
    virtual unsigned int toStream( OutStream& outStream ) const;

    /// Load the data from the a binary representation in the buffer
    /// Typically just a memcopy of the variable, though endianness
    /// may come into it.
    virtual void fromBinary( const void *buffer );

protected:

    /// Protected Empty constructor for use by DataEntry class
    UChar();

};

#endif /*UCHAR_H_*/
