Panda3D
 All Classes Functions Variables Enumerations
xFileTemplate.cxx
1 // Filename: xFileTemplate.cxx
2 // Created by: drose (03Oct04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "xFileTemplate.h"
16 #include "indent.h"
17 
18 TypeHandle XFileTemplate::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: XFileTemplate::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 XFileTemplate::
26 XFileTemplate(XFile *x_file, const string &name, const WindowsGuid &guid) :
27  XFileNode(x_file, name),
28  _guid(guid),
29  _is_standard(false),
30  _open(false)
31 {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: XFileTemplate::Destructor
36 // Access: Public, Virtual
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 XFileTemplate::
40 ~XFileTemplate() {
41  clear();
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: XFileTemplate::has_guid
46 // Access: Public, Virtual
47 // Description: Returns true if this node has a GUID associated.
48 ////////////////////////////////////////////////////////////////////
49 bool XFileTemplate::
50 has_guid() const {
51  return true;
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: XFileTemplate::get_guid
56 // Access: Public, Virtual
57 // Description: Returns the GUID associated with this template.
58 ////////////////////////////////////////////////////////////////////
60 get_guid() const {
61  return _guid;
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: XFileTemplate::is_template_def
66 // Access: Public, Virtual
67 // Description: Returns true if this node represents the definition
68 // of some template. This is the template definition,
69 // not an actual data object that represents an instance
70 // of the template. If the file strictly uses standard
71 // templates, the presence of template definitions is
72 // optional.
73 //
74 // If this returns true, the node must be of type
75 // XFileTemplate.
76 ////////////////////////////////////////////////////////////////////
77 bool XFileTemplate::
78 is_template_def() const {
79  return true;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: XFileTemplate::clear
84 // Access: Public, Virtual
85 // Description: Removes all children from the node, and otherwise
86 // resets it to its initial state.
87 ////////////////////////////////////////////////////////////////////
88 void XFileTemplate::
89 clear() {
91  _options.clear();
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: XFileTemplate::write_text
96 // Access: Public, Virtual
97 // Description: Writes a suitable representation of this node to an
98 // .x file in text mode.
99 ////////////////////////////////////////////////////////////////////
100 void XFileTemplate::
101 write_text(ostream &out, int indent_level) const {
102  indent(out, indent_level)
103  << "template " << get_name() << " {\n";
104  indent(out, indent_level + 2)
105  << "<" << _guid << ">\n";
106 
107  XFileNode::write_text(out, indent_level + 2);
108 
109  if (get_open()) {
110  // An open template
111  indent(out, indent_level + 2)
112  << "[ ... ]\n";
113 
114  } else if (!_options.empty()) {
115  // A restricted template
116  indent(out, indent_level + 2);
117 
118  char delimiter = '[';
119  Options::const_iterator ri;
120  for (ri = _options.begin(); ri != _options.end(); ++ri) {
121  XFileTemplate *option = (*ri);
122  out << delimiter << " "
123  << option->get_name() << " <" << option->get_guid()
124  << ">";
125  delimiter = ',';
126  }
127  out << " ]\n";
128  }
129 
130  indent(out, indent_level)
131  << "}\n";
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: XFileTemplate::matches
136 // Access: Public, Virtual
137 // Description: Returns true if the node, particularly a template
138 // node, is structurally equivalent to the other node
139 // (which must be of the same type). This checks data
140 // element types, but does not compare data element
141 // names.
142 ////////////////////////////////////////////////////////////////////
143 bool XFileTemplate::
144 matches(const XFileNode *other) const {
145  if (!XFileNode::matches(other)) {
146  return false;
147  }
148 
149  // We *could* compare the open/closed/options associated with the
150  // template, but since this is only used for validating the set of
151  // children for the instances of this template (which we don't even
152  // bother to do anyway), it doesn't seem to matter.
153  return true;
154 }
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
This is an implementation of the Windows GUID object, used everywhere as a world-unique identifier fo...
Definition: windowsGuid.h:29
A single node of an X file.
Definition: xFileNode.h:42
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state. ...
virtual bool is_template_def() const
Returns true if this node represents the definition of some template.
virtual bool has_guid() const
Returns true if this node has a GUID associated.
virtual void write_text(ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
virtual void write_text(ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
Definition: xFileNode.cxx:263
virtual void clear()
Removes all children from the node, and otherwise resets it to its initial state. ...
Definition: xFileNode.cxx:250
virtual bool matches(const XFileNode *other) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
Definition: xFileNode.cxx:333
This represents the complete contents of an X file (file.x) in memory.
Definition: xFile.h:35
A template definition in the X file.
Definition: xFileTemplate.h:29
bool get_open() const
Returns whether the template is considered &quot;open&quot; or not.
Definition: xFileTemplate.I:54
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual const WindowsGuid & get_guid() const
Returns the GUID associated with this template.