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

#include "Script.H"
#include "xrmlP.H"

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

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

bool Script::assign_url(const MFString& value)
{
  // TODO: value range check!
  url = value;
  status |= url_updated;
  timestamp = interface[0]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Script_url(SFNode* node, const fieldValue& value)
{
  Script* Script_node = dynamic_cast<Script*>(node);
  if (!Script_node)
    Fatal(-1, "assign_Script_url", "called for a non-Script node");
  return Script_node->assign_url((const MFString&)value);
}

void Script::set_url(const MFString& val)
{
  MFString tmpval(val);
  fieldValue v(&tmpval);
  interface[0]->assign(this, v);
}

bool Script::assign_directOutput(const SFBool& value)
{
  // TODO: value range check!
  directOutput = value;
  status |= directOutput_updated;
  timestamp = interface[1]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Script_directOutput(SFNode* node, const fieldValue& value)
{
  Script* Script_node = dynamic_cast<Script*>(node);
  if (!Script_node)
    Fatal(-1, "assign_Script_directOutput", "called for a non-Script node");
  return Script_node->assign_directOutput((const SFBool&)value);
}

bool Script::assign_mustEvaluate(const SFBool& value)
{
  // TODO: value range check!
  mustEvaluate = value;
  status |= mustEvaluate_updated;
  timestamp = interface[2]->timestamp = world ? world->time : 0;
  return true;
}

static bool assign_Script_mustEvaluate(SFNode* node, const fieldValue& value)
{
  Script* Script_node = dynamic_cast<Script*>(node);
  if (!Script_node)
    Fatal(-1, "assign_Script_mustEvaluate", "called for a non-Script node");
  return Script_node->assign_mustEvaluate((const SFBool&)value);
}

Script::Script()
{
  interfaceMember* the_interface[3] = {
    new exposedField("url", fieldValue(&url), assign_Script_url),
    new field("directOutput", fieldValue(&directOutput), assign_Script_directOutput),
    new field("mustEvaluate", fieldValue(&mustEvaluate), assign_Script_mustEvaluate),
  };
  SFNode::construct(ScriptTypeId, 3, the_interface);

  url = MFString(0);
  directOutput = 0;
  mustEvaluate = 0;
  
  Children::util_init();
  Script::util_init();
}

void Script::destruct(void)
{
  Script::util_destruct();
  Children::util_destruct();
  SFNode::destruct();
}

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

void Script::clone_here(const Script& src)
{
  SFNode::clone(src);
  
  interface[0]->value = fieldValue(&url);
  interface[1]->value = fieldValue(&directOutput);
  interface[2]->value = fieldValue(&mustEvaluate);
  
  url = src.url;
  directOutput = src.directOutput;
  mustEvaluate = src.mustEvaluate;
  
  Children::util_clone(src);
  Script::util_clone(src);
}

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

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

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

}  // namespace xrml
