// PhBInterpolatedSpectrumP.C: PhBInterpolatedSpectrum nodes (private source).
// Automatically generated with nodegen 0.5a - do not edit.

#include "PhBInterpolatedSpectrum.H"
#include "xrmlP.H"

namespace xrml {
int PhBInterpolatedSpectrum::major_version(void) { return 0; }
int PhBInterpolatedSpectrum::minor_version(void) { return 5; }
bool PhBInterpolatedSpectrum::is_leaf_class(void) { return true; }

bool IsPhBInterpolatedSpectrum(SFNode* node)
{
  return (dynamic_cast<PhBInterpolatedSpectrum*>(node) != 0);
}

bool PhBInterpolatedSpectrum::assign_fraction(const SFFloat& value)
{
  // TODO: value range check!
  fraction = value;
  status |= fraction_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBInterpolatedSpectrum_fraction(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedSpectrum* PhBInterpolatedSpectrum_node = dynamic_cast<PhBInterpolatedSpectrum*>(node);
  if (!PhBInterpolatedSpectrum_node)
    Fatal(-1, "assign_PhBInterpolatedSpectrum_fraction", "called for a non-PhBInterpolatedSpectrum node");
  return PhBInterpolatedSpectrum_node->assign_fraction((const SFFloat&)value);
}

void PhBInterpolatedSpectrum::set_fraction(const SFFloat& val)
{
  SFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool PhBInterpolatedSpectrum::assign_key(const MFFloat& value)
{
  // TODO: value range check!
  key = value;
  status |= key_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBInterpolatedSpectrum_key(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedSpectrum* PhBInterpolatedSpectrum_node = dynamic_cast<PhBInterpolatedSpectrum*>(node);
  if (!PhBInterpolatedSpectrum_node)
    Fatal(-1, "assign_PhBInterpolatedSpectrum_key", "called for a non-PhBInterpolatedSpectrum node");
  return PhBInterpolatedSpectrum_node->assign_key((const MFFloat&)value);
}

void PhBInterpolatedSpectrum::set_key(const MFFloat& val)
{
  MFFloat tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

void PhBInterpolatedSpectrum::synchronize_keySpectra(void)
{
  if (_keySpectra.size > keySpectra.size) keySpectra.grow(_keySpectra.size - keySpectra.size);
  for (int i=keySpectra.size=0; i<_keySpectra.size; i++)
    keySpectra.append(dynamic_cast<PhBSpectrum*>(_keySpectra[i]->firstnode()));
}

bool PhBInterpolatedSpectrum::assign_keySpectra(const MFNode& value)
{
  MFNode oldval = _keySpectra;
  _keySpectra = value;
  if (checkValue(_keySpectra, IsPhBSpectrum, "PhBInterpolatedSpectrum.keySpectra", "PhBSpectrum")) {
    synchronize_keySpectra();
    status |= keySpectra_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _keySpectra = oldval;
    return false;
  }
}

static bool assign_PhBInterpolatedSpectrum_keySpectra(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedSpectrum* PhBInterpolatedSpectrum_node = dynamic_cast<PhBInterpolatedSpectrum*>(node);
  if (!PhBInterpolatedSpectrum_node)
    Fatal(-1, "assign_PhBInterpolatedSpectrum_keySpectra", "called for a non-PhBInterpolatedSpectrum node");
  return PhBInterpolatedSpectrum_node->assign_keySpectra((const MFNode&)value);
}

void PhBInterpolatedSpectrum::set_keySpectra(const MFNode& val)
{
  MFNode tmpval(val);
  fieldValue v(&tmpval);
  interface[2]->assign(this, v);
}

PhBInterpolatedSpectrum::PhBInterpolatedSpectrum()
{
  interfaceMember* the_interface[3] = {
    new exposedField("fraction", fieldValue(&fraction), assign_PhBInterpolatedSpectrum_fraction),
    new exposedField("key", fieldValue(&key), assign_PhBInterpolatedSpectrum_key),
    new exposedField("keySpectra", fieldValue(&_keySpectra), assign_PhBInterpolatedSpectrum_keySpectra),
  };
  SFNode::construct(PhBInterpolatedSpectrumTypeId, 3, the_interface);

  fraction = 0;
  key = MFFloat(0);
  keySpectra = array<PhBSpectrum*>(0); 	_keySpectra = MFNode(0);
  
  PhBSpectrum::util_init();
  PhBInterpolatedSpectrum::util_init();
}

void PhBInterpolatedSpectrum::destruct(void)
{
  PhBInterpolatedSpectrum::util_destruct();
  PhBSpectrum::util_destruct();
  SFNode::destruct();
}

PhBInterpolatedSpectrum::~PhBInterpolatedSpectrum()
{
  destruct();
}

void PhBInterpolatedSpectrum::clone_here(const PhBInterpolatedSpectrum& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&fraction);
  interface[1]->value = fieldValue(&key);
  interface[2]->value = fieldValue(&_keySpectra);
  
  fraction = src.fraction;
  key = src.key;
  keySpectra = src.keySpectra;	  _keySpectra = src._keySpectra;
  
  PhBSpectrum::util_clone(src);
  PhBInterpolatedSpectrum::util_clone(src);
}

PhBInterpolatedSpectrum::PhBInterpolatedSpectrum(const PhBInterpolatedSpectrum& src)
{
  clone_here(src);
}

PhBInterpolatedSpectrum& PhBInterpolatedSpectrum::operator=(const PhBInterpolatedSpectrum& src)
{
  if (this != &src) {
    destruct();
    clone_here(src);
  }
  return *this;
}

SFNode* PhBInterpolatedSpectrum::instantiate(Proto *enclosing_proto)
{
  if (nameIndex>=0)
    // named node: return pointer to pre-made instance
    return enclosing_proto ? enclosing_proto->namedNodes[nameIndex] : this;
  
  PhBInterpolatedSpectrum* instance = new PhBInterpolatedSpectrum(*this);
  instance->instantiate_interface(enclosing_proto);
  instance->synchronize_keySpectra();
  return instance;
}

}  // namespace xrml
