/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : FloatAttribute.cc                                             */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include "FloatAttribute.h"
#include "StringConverter.h"

FloatAttribute::FloatAttribute(const char *name, const char *description,
			       double *valueAddress)
  : Attribute(name, description)
{
  _valueAddress = valueAddress;
}


FloatAttribute::FloatAttribute(const char *name, const char *description,
			       double *valueAddress,
			       double defaultValue)
  : Attribute(name, description)
{
  _valueAddress = valueAddress;
  *_valueAddress = defaultValue;
  _hasDefault = True;
}


FloatAttribute::~FloatAttribute()
{
}


void FloatAttribute::setValue(const char *stringRep)
{
  *_valueAddress = StringConverter::stringToFloat(stringRep);
}


const char *FloatAttribute::valueString()
{
  if (!valueHasBeenSet() && !hasDefault())
    return "";

  static char buf[32];

  sprintf(buf, "%7.3e", *_valueAddress);
  return buf;
}
