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

#include "PhBTextureEmitter.H"
#include "xrmlP.H"

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

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

void PhBTextureEmitter::synchronize_texture(void)
{
  texture = (_texture) ? dynamic_cast<PhBTexture*>(_texture->firstnode()) : 0;
}

bool PhBTextureEmitter::assign_texture(SFNode* value)
{
  SFNode* oldval = _texture;
  _texture = value;
  if (checkValue(_texture, IsPhBTexture, "PhBTextureEmitter.texture", "PhBTexture")) {
    synchronize_texture();
    status |= texture_updated;
    timestamp = interface[0]->timestamp = world ? world->time : 0;
    return true;
  } else {
    _texture = oldval;
    return false;
  }
}

static bool assign_PhBTextureEmitter_texture(SFNode* node, const fieldValue& value)
{
  PhBTextureEmitter* PhBTextureEmitter_node = dynamic_cast<PhBTextureEmitter*>(node);
  if (!PhBTextureEmitter_node)
    Fatal(-1, "assign_PhBTextureEmitter_texture", "called for a non-PhBTextureEmitter node");
  return PhBTextureEmitter_node->assign_texture((SFNode*&)value);
}

void PhBTextureEmitter::set_texture(SFNode* val)
{
  SFNode* tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool PhBTextureEmitter::assign_channel(const SFInt32& value)
{
  // TODO: value range check!
  channel = value;
  status |= channel_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_PhBTextureEmitter_channel(SFNode* node, const fieldValue& value)
{
  PhBTextureEmitter* PhBTextureEmitter_node = dynamic_cast<PhBTextureEmitter*>(node);
  if (!PhBTextureEmitter_node)
    Fatal(-1, "assign_PhBTextureEmitter_channel", "called for a non-PhBTextureEmitter node");
  return PhBTextureEmitter_node->assign_channel((const SFInt32&)value);
}

void PhBTextureEmitter::set_channel(const SFInt32& val)
{
  SFInt32 tmpval(val);
  fieldValue v(&tmpval);
  interface[1]->assign(this, v);
}

PhBTextureEmitter::PhBTextureEmitter()
{
  interfaceMember* the_interface[2] = {
    new exposedField("texture", fieldValue(&_texture), assign_PhBTextureEmitter_texture),
    new exposedField("channel", fieldValue(&channel), assign_PhBTextureEmitter_channel),
  };
  SFNode::construct(PhBTextureEmitterTypeId, 2, the_interface);

  texture = (PhBTexture *)0; 	_texture = (SFNode *)0;
  channel = 1;
  
  PhBEmitter::util_init();
  PhBTextureEmitter::util_init();
}

void PhBTextureEmitter::destruct(void)
{
  PhBTextureEmitter::util_destruct();
  PhBEmitter::util_destruct();
  SFNode::destruct();
}

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

void PhBTextureEmitter::clone_here(const PhBTextureEmitter& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&_texture);
  interface[1]->value = fieldValue(&channel);
  
  texture = src.texture;	  _texture = src._texture;
  channel = src.channel;
  
  PhBEmitter::util_clone(src);
  PhBTextureEmitter::util_clone(src);
}

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

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

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

}  // namespace xrml
