Panda3D
 All Classes Functions Variables Enumerations
xFileTemplate.cxx
00001 // Filename: xFileTemplate.cxx
00002 // Created by:  drose (03Oct04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "xFileTemplate.h"
00016 #include "indent.h"
00017 
00018 TypeHandle XFileTemplate::_type_handle;
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: XFileTemplate::Constructor
00022 //       Access: Public
00023 //  Description:
00024 ////////////////////////////////////////////////////////////////////
00025 XFileTemplate::
00026 XFileTemplate(XFile *x_file, const string &name, const WindowsGuid &guid) : 
00027   XFileNode(x_file, name),
00028   _guid(guid),
00029   _is_standard(false),
00030   _open(false)
00031 {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: XFileTemplate::Destructor
00036 //       Access: Public, Virtual
00037 //  Description:
00038 ////////////////////////////////////////////////////////////////////
00039 XFileTemplate::
00040 ~XFileTemplate() {
00041   clear();
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: XFileTemplate::has_guid
00046 //       Access: Public, Virtual
00047 //  Description: Returns true if this node has a GUID associated.
00048 ////////////////////////////////////////////////////////////////////
00049 bool XFileTemplate::
00050 has_guid() const {
00051   return true;
00052 }
00053 
00054 ////////////////////////////////////////////////////////////////////
00055 //     Function: XFileTemplate::get_guid
00056 //       Access: Public, Virtual
00057 //  Description: Returns the GUID associated with this template.
00058 ////////////////////////////////////////////////////////////////////
00059 const WindowsGuid &XFileTemplate::
00060 get_guid() const {
00061   return _guid;
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: XFileTemplate::is_template_def
00066 //       Access: Public, Virtual
00067 //  Description: Returns true if this node represents the definition
00068 //               of some template.  This is the template definition,
00069 //               not an actual data object that represents an instance
00070 //               of the template.  If the file strictly uses standard
00071 //               templates, the presence of template definitions is
00072 //               optional.
00073 //
00074 //               If this returns true, the node must be of type
00075 //               XFileTemplate.
00076 ////////////////////////////////////////////////////////////////////
00077 bool XFileTemplate::
00078 is_template_def() const {
00079   return true;
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: XFileTemplate::clear
00084 //       Access: Public, Virtual
00085 //  Description: Removes all children from the node, and otherwise
00086 //               resets it to its initial state.
00087 ////////////////////////////////////////////////////////////////////
00088 void XFileTemplate::
00089 clear() {
00090   XFileNode::clear();
00091   _options.clear();
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: XFileTemplate::write_text
00096 //       Access: Public, Virtual
00097 //  Description: Writes a suitable representation of this node to an
00098 //               .x file in text mode.
00099 ////////////////////////////////////////////////////////////////////
00100 void XFileTemplate::
00101 write_text(ostream &out, int indent_level) const {
00102   indent(out, indent_level)
00103     << "template " << get_name() << " {\n";
00104   indent(out, indent_level + 2)
00105     << "<" << _guid << ">\n";
00106 
00107   XFileNode::write_text(out, indent_level + 2);
00108 
00109   if (get_open()) {
00110     // An open template
00111     indent(out, indent_level + 2)
00112       << "[ ... ]\n";
00113 
00114   } else if (!_options.empty()) {
00115     // A restricted template
00116     indent(out, indent_level + 2);
00117 
00118     char delimiter = '[';
00119     Options::const_iterator ri;
00120     for (ri = _options.begin(); ri != _options.end(); ++ri) {
00121       XFileTemplate *option = (*ri);
00122       out << delimiter << " " 
00123           << option->get_name() << " <" << option->get_guid()
00124           << ">";
00125       delimiter = ',';
00126     }
00127     out << " ]\n";
00128   }
00129 
00130   indent(out, indent_level)
00131     << "}\n";
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: XFileTemplate::matches
00136 //       Access: Public, Virtual
00137 //  Description: Returns true if the node, particularly a template
00138 //               node, is structurally equivalent to the other node
00139 //               (which must be of the same type).  This checks data
00140 //               element types, but does not compare data element
00141 //               names.
00142 ////////////////////////////////////////////////////////////////////
00143 bool XFileTemplate::
00144 matches(const XFileNode *other) const {
00145   if (!XFileNode::matches(other)) {
00146     return false;
00147   }
00148 
00149   // We *could* compare the open/closed/options associated with the
00150   // template, but since this is only used for validating the set of
00151   // children for the instances of this template (which we don't even
00152   // bother to do anyway), it doesn't seem to matter.
00153   return true;
00154 }
 All Classes Functions Variables Enumerations