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

Attribute::Attribute(const char *name, const char *description)
{
  _name = strdup(name);

  if (description)
    _description = strdup(description);
  else
    _description = 0;

  _hasDefault = False;
  _valueHasBeenSet = False;
}


Attribute::~Attribute()
{
  free((void *)_name);
  free((void *)_description);
}


const char *Attribute::name()
{
  return _name;
}


Boolean Attribute::hasDefault()
{
  return _hasDefault;
}


void Attribute::markAsSet()
{
  _valueHasBeenSet = True;
}


Boolean Attribute::valueHasBeenSet()
{
  return _valueHasBeenSet;
}


Attribute::Input::Input(const char *nm, const char *value)
{
  name = strdup(nm);
  valueString = strdup(value);
}


Attribute::Input::~Input()
{
  free((void *)name);
  free((void *)valueString);
}


void Attribute::printDescription()
{
  char buf[256];

  char *ptr = buf;
  sprintf(ptr, "name: %s\ntype: %s, ", name(), typeMnem());

  ptr += strlen(ptr);

  if (hasDefault()) {
    sprintf(ptr, "default: %s\n", valueString());
  }
  else {
    sprintf(ptr, "default: none - input mandatory\n");
  }

  ptr += strlen(ptr);

  sprintf(ptr, "Description: %s", _description);

  Syslog::write("%s", buf);
}


const char *Attribute::description()
{
  return _description;
}
