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

#include "Short.h"
#include "io/OutStream.h"
#include <math.h>

/// Constructor for non-array storage
Short::Short( const Unit& unit, int value, bool scaleValue )
    : Int( unit, value, scaleValue )
{
    typeSize_ = 2;
    binaryType_ = SHORT2;
}

/// Constructor from binary
Short::Short( const Unit& unit, const void *binary )
    : Int( unit, 0, false )
{
    typeSize_ = 2;
    binaryType_ = SHORT2;
    fromBinary( binary );
}

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

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

/// Protected Empty constructor for use bya DataEntry class
Short::Short()
    : Int()
{
    typeSize_ = 2;
    binaryType_ = SHORT2;
}

