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

#include "Double6.h"
#include "io/OutStream.h"
#include "utils/AuvMath.h"
#include "utils/RingBuffer.h"

/// Constructor for non-array storage
Double6::Double6( const Unit& unit, double value, bool scaleValue )
    : Double( unit, value, scaleValue )
{
    typeSize_ = 6;
    binaryType_ = DOUBLE6;
}

/// Constructor from binary
Double6::Double6( const Unit& unit, const void *binary )
    : Double( unit, 0, false )
{
    typeSize_ = 6;
    binaryType_ = DOUBLE6;
    fromBinary( binary );
}

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

/// A quick equality check used to see if value has changed enough
/// to matter in logging (useful for reduced resolution data storage
bool Double6::equalsForStorage( const double& compareTo ) const
{
    return ( *( unsigned long long* )&value_ & 0xFFFFFFFFFFFFFF00LL )
           == ( *( unsigned long long* )&compareTo & 0xFFFFFFFFFFFFFF00LL )
           || ( isnan( value_ ) && isnan( compareTo ) );
}

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

void Double6::fromBinary( const void *buffer )
{
    value_ = 0;
    memcpy( ( ( unsigned char * ) & value_ ) + 2, ( const void * ) buffer, typeSize_ );
}

/// Protected Empty constructor for use bya DataEntry class
Double6::Double6()
    : Double()
{
    typeSize_ = 6;
    binaryType_ = DOUBLE6;
}


