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

#include "PhBMixedSpectrum.H"
#include "xrmlP.H"

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

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

void PhBMixedSpectrum::synchronize_spectra(void)
{
  if (_spectra.size > spectra.size) spectra.grow(_spectra.size - spectra.size);
  for (int i=spectra.size=0; i<_spectra.size; i++)
    spectra.append(dynamic_cast<PhBSpectrum*>(_spectra[i]->firstnode()));
}

bool PhBMixedSpectrum::assign_spectra(const MFNode& value)
{
  MFNode oldval = _spectra;
  _spectra = value;
  if (checkValue(_spectra, IsPhBSpectrum, "PhBMixedSpectrum.spectra", "PhBSpectrum")) {
    synchronize_spectra();
    status |= spectra_updated;
    timestamp = interface[0]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _spectra = oldval;
    return false;
  }
}

static bool assign_PhBMixedSpectrum_spectra(SFNode* node, const fieldValue& value)
{
  PhBMixedSpectrum* PhBMixedSpectrum_node = dynamic_cast<PhBMixedSpectrum*>(node);
  if (!PhBMixedSpectrum_node)
    Fatal(-1, "assign_PhBMixedSpectrum_spectra", "called for a non-PhBMixedSpectrum node");
  return PhBMixedSpectrum_node->assign_spectra((const MFNode&)value);
}

void PhBMixedSpectrum::set_spectra(const MFNode& val)
{
  MFNode tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

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

static bool assign_PhBMixedSpectrum_weight(SFNode* node, const fieldValue& value)
{
  PhBMixedSpectrum* PhBMixedSpectrum_node = dynamic_cast<PhBMixedSpectrum*>(node);
  if (!PhBMixedSpectrum_node)
    Fatal(-1, "assign_PhBMixedSpectrum_weight", "called for a non-PhBMixedSpectrum node");
  return PhBMixedSpectrum_node->assign_weight((const MFFloat&)value);
}

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

PhBMixedSpectrum::PhBMixedSpectrum()
{
  interfaceMember* the_interface[2] = {
    new exposedField("spectra", fieldValue(&_spectra), assign_PhBMixedSpectrum_spectra),
    new exposedField("weight", fieldValue(&weight), assign_PhBMixedSpectrum_weight),
  };
  SFNode::construct(PhBMixedSpectrumTypeId, 2, the_interface);

  spectra = array<PhBSpectrum*>(0); 	_spectra = MFNode(0);
  weight = MFFloat(0);
  
  PhBSpectrum::util_init();
  PhBMixedSpectrum::util_init();
}

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

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

void PhBMixedSpectrum::clone_here(const PhBMixedSpectrum& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_spectra);
  interface[1]->value = fieldValue(&weight);
  
  spectra = src.spectra;	  _spectra = src._spectra;
  weight = src.weight;
  
  PhBSpectrum::util_clone(src);
  PhBMixedSpectrum::util_clone(src);
}

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

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

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

}  // namespace xrml
