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