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

#ifndef USHORT_H_
#define USHORT_H_

#include "Int.h"

/**
 *  Wraps a single precision (4-byte) floating point number 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, UShort objects are serialized as 2-byte
 *  numbers by throwing away the 16 least-significant bits of the
 *  significand.  Thus, the resulting number has the range of a regular
 *  4-byte float, but with only 2.5 decimal digits accuracy.  Such numbers
 *  would be adequate for storing scaled measurements from an 8-bit A/D,
 *  for example.
 *
 *  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.
 *
 *  UShort::MallocRing_  stores deleted objects.
 *
 * \ingroup data
 */
class UShort : public Int
{
public:

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

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

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

    /// Destructor
    virtual ~UShort() {}

    /// 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;

protected:

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

};

#endif /*USHORT_H_*/
