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

#include "SimpleDataElement.h"

#include "component/Component.h"
#include "logger/Logger.h"
#include "units/Unit.h"

SimpleDataElement::SimpleDataElement( const ElementURI& name,
                                      DataValue* initialValue,
                                      float accuracy )
    : DataElement( name,
                   initialValue == NULL ? NULL : & initialValue->getUnit().getBaseUnit(),
                   initialValue == NULL ? 0 : initialValue->getTypeSize() ),
      value_( initialValue ),
      accuracy_( accuracy )
{}

SimpleDataElement::~SimpleDataElement()
{
    if( NULL != value_ )
    {
        delete value_;
    }
}

DataValue* SimpleDataElement::getDataValue( void ) const
{
    return value_;
}

void SimpleDataElement::setDataValue( DataValue* dataValue )
{
    if( NULL != value_ )
    {
        delete value_;
    }
    value_ = dataValue;
}

float SimpleDataElement::getAccuracy( const Unit& unit ) const
#ifndef __GAZEBO
throw( UninitializedException )
#endif
{
    return unit.getScaled( accuracy_ );
}

float SimpleDataElement::getAccuracySI() const
#ifndef __GAZEBO
throw( UninitializedException )
#endif
{
    return accuracy_;
}

float SimpleDataElement::setAccuracy( const Unit& unit, float accuracy )
{
    accuracy_ = unit.getSI( accuracy );
    return accuracy;
}

