Panda3D
vrmlNode.cxx
1 // Filename: vrmlNode.cxx
2 // Created by: drose (23Jun99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 // PANDA 3D SOFTWARE
6 // Copyright (c) Carnegie Mellon University. All rights reserved.
7 //
8 // All use of this software is subject to the terms of the revised BSD
9 // license. You should have received a copy of this license along
10 // with this source code in a file named "LICENSE."
11 ////////////////////////////////////////////////////////////////////
12 
13 #include "vrmlNode.h"
14 #include "vrmlParser.h"
15 
16 #include "indent.h"
17 #include "pnotify.h"
18 
19 VrmlNode::
20 VrmlNode(const VrmlNodeType *type) {
21  _type = type;
22  _use_count = 0;
23 }
24 
25 VrmlNode::
26 ~VrmlNode() {
27 }
28 
29 
30 const VrmlFieldValue &VrmlNode::
31 get_value(const char *field_name) const {
32  Fields::const_iterator fi;
33  for (fi = _fields.begin(); fi != _fields.end(); ++fi) {
34  if (strcmp((*fi)._type->name, field_name) == 0) {
35  return ((*fi)._value);
36  }
37  }
38 
39  // That field was not defined. Get the default value.
40  const VrmlNodeType::NameTypeRec *field = _type->hasField(field_name);
41  if (field != NULL) {
42  return field->dflt;
43  }
44 
45  cerr << "No such field defined for type " << _type->getName() << ": "
46  << field_name << "\n";
47  exit(1);
48  // Just to make the compiler happy.
49  static VrmlFieldValue zero;
50  return zero;
51 }
52 
53 void VrmlNode::
54 output(ostream &out, int indent_level) const {
55  out << _type->getName() << " {\n";
56  Fields::const_iterator fi;
57  for (fi = _fields.begin(); fi != _fields.end(); ++fi) {
58  indent(out, indent_level + 2) << (*fi)._type->name << " ";
59  output_value(out, (*fi)._value, (*fi)._type->type, indent_level + 2) << "\n";
60  }
61  indent(out, indent_level) << "}";
62 }
63 
64 
65 void Declaration::
66 output(ostream &out, int indent) const {
68  v._sfnode = _node;
69  output_value(out, v, SFNODE, indent);
70 }
71 
72 ostream &operator << (ostream &out, const VrmlScene &scene) {
73  VrmlScene::const_iterator si;
74  for (si = scene.begin(); si != scene.end(); ++si) {
75  out << (*si) << "\n";
76  }
77 
78  return out;
79 }
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39