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

#ifndef DOUBLE4_H_
#define DOUBLE4_H_

#include "Double.h"

/**
 *  Wraps a double precision (8-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 Double class, Double4 objects are serialized as 4-byte
 *  floats by casting to float.
 *
 *  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.
 *
 *  Double4::MallocRing_  stores deleted objects.
 *
 * \ingroup data
 */
class Double4 : public Double
{
public:

    /// Constructor for non-array storage
    Double4( const Unit& unit, double value, bool scaleValue = true );

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

    /// Destructor
    virtual ~Double4()
    {}
    ;

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

    /// A quick equality check used to see if value has changed enough
    /// to matter in logging (useful for reduced resolution data storage
    virtual bool equalsForStorage( const double& compareTo ) const;

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

    /// Cast to float without floating point errors
    static float DoubleToFloat( const double& theDouble );

protected:

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

};

#endif /*DOUBLE4_H_*/
