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

#include "PhBInterpolatedMedium.H"
#include "xrmlP.H"

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

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

bool PhBInterpolatedMedium::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_PhBInterpolatedMedium_fraction(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedMedium* PhBInterpolatedMedium_node = dynamic_cast<PhBInterpolatedMedium*>(node);
  if (!PhBInterpolatedMedium_node)
    Fatal(-1, "assign_PhBInterpolatedMedium_fraction", "called for a non-PhBInterpolatedMedium node");
  return PhBInterpolatedMedium_node->assign_fraction((const SFFloat&)value);
}

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

bool PhBInterpolatedMedium::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_PhBInterpolatedMedium_key(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedMedium* PhBInterpolatedMedium_node = dynamic_cast<PhBInterpolatedMedium*>(node);
  if (!PhBInterpolatedMedium_node)
    Fatal(-1, "assign_PhBInterpolatedMedium_key", "called for a non-PhBInterpolatedMedium node");
  return PhBInterpolatedMedium_node->assign_key((const MFFloat&)value);
}

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

void PhBInterpolatedMedium::synchronize_keyMedia(void)
{
  if (_keyMedia.size > keyMedia.size) keyMedia.grow(_keyMedia.size - keyMedia.size);
  for (int i=keyMedia.size=0; i<_keyMedia.size; i++)
    keyMedia.append(dynamic_cast<PhBMedium*>(_keyMedia[i]->firstnode()));
}

bool PhBInterpolatedMedium::assign_keyMedia(const MFNode& value)
{
  MFNode oldval = _keyMedia;
  _keyMedia = value;
  if (checkValue(_keyMedia, IsPhBMedium, "PhBInterpolatedMedium.keyMedia", "PhBMedium")) {
    synchronize_keyMedia();
    status |= keyMedia_updated;
    timestamp = interface[2]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _keyMedia = oldval;
    return false;
  }
}

static bool assign_PhBInterpolatedMedium_keyMedia(SFNode* node, const fieldValue& value)
{
  PhBInterpolatedMedium* PhBInterpolatedMedium_node = dynamic_cast<PhBInterpolatedMedium*>(node);
  if (!PhBInterpolatedMedium_node)
    Fatal(-1, "assign_PhBInterpolatedMedium_keyMedia", "called for a non-PhBInterpolatedMedium node");
  return PhBInterpolatedMedium_node->assign_keyMedia((const MFNode&)value);
}

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

PhBInterpolatedMedium::PhBInterpolatedMedium()
{
  interfaceMember* the_interface[3] = {
    new exposedField("fraction", fieldValue(&fraction), assign_PhBInterpolatedMedium_fraction),
    new exposedField("key", fieldValue(&key), assign_PhBInterpolatedMedium_key),
    new exposedField("keyMedia", fieldValue(&_keyMedia), assign_PhBInterpolatedMedium_keyMedia),
  };
  SFNode::construct(PhBInterpolatedMediumTypeId, 3, the_interface);

  fraction = 0;
  key = MFFloat(0);
  keyMedia = array<PhBMedium*>(0); 	_keyMedia = MFNode(0);
  
  PhBMedium::util_init();
  PhBInterpolatedMedium::util_init();
}

void PhBInterpolatedMedium::destruct(void)
{
  PhBInterpolatedMedium::util_destruct();
  PhBMedium::util_destruct();
  SFNode::destruct();
}

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

void PhBInterpolatedMedium::clone_here(const PhBInterpolatedMedium& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&fraction);
  interface[1]->value = fieldValue(&key);
  interface[2]->value = fieldValue(&_keyMedia);
  
  fraction = src.fraction;
  key = src.key;
  keyMedia = src.keyMedia;	  _keyMedia = src._keyMedia;
  
  PhBMedium::util_clone(src);
  PhBInterpolatedMedium::util_clone(src);
}

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

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

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

}  // namespace xrml
