Panda3D
 All Classes Functions Variables Enumerations
xFileArrayDef.cxx
1 // Filename: xFileArrayDef.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 "xFileArrayDef.h"
16 #include "xFileDataDef.h"
17 #include "xFileDataObject.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: XFileArrayDef::get_size
21 // Access: Public
22 // Description: Returns the size of the array dimension. If this is
23 // a fixed array, the size is trivial; if it is dynamic,
24 // the size is determined by looking up the dynamic_size
25 // element in the prev_data table (which lists all of
26 // the data values already defined at this scoping
27 // level).
28 ////////////////////////////////////////////////////////////////////
30 get_size(const XFileNode::PrevData &prev_data) const {
31  if (is_fixed_size()) {
32  return _fixed_size;
33  } else {
34  XFileNode::PrevData::const_iterator pi;
35  pi = prev_data.find(_dynamic_size);
36  nassertr_always(pi != prev_data.end(), 0);
37  nassertr((*pi).second != (XFileDataObject *)NULL, 0);
38  return (*pi).second->i();
39  }
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: XFileArrayDef::output
44 // Access: Public
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 void XFileArrayDef::
48 output(ostream &out) const {
49  if (is_fixed_size()) {
50  out << "[" << _fixed_size << "]";
51  } else {
52  out << "[" << _dynamic_size->get_name() << "]";
53  }
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: XFileArrayDef::matches
58 // Access: Public, Virtual
59 // Description: Returns true if the node, particularly a template
60 // node, is structurally equivalent to the other node
61 // (which must be of the same type). This checks data
62 // element types, but does not compare data element
63 // names.
64 ////////////////////////////////////////////////////////////////////
65 bool XFileArrayDef::
66 matches(const XFileArrayDef &other, const XFileDataDef *parent,
67  const XFileDataDef *other_parent) const {
68  if (other.is_fixed_size() != is_fixed_size()) {
69  return false;
70  }
71  if (is_fixed_size()) {
72  if (other.get_fixed_size() != get_fixed_size()) {
73  return false;
74  }
75 
76  } else {
77  int child_index = parent->find_child_index(get_dynamic_size());
78  int other_child_index =
79  other_parent->find_child_index(other.get_dynamic_size());
80  if (other_child_index != child_index) {
81  return false;
82  }
83  }
84 
85  return true;
86 }
int get_size(const XFileNode::PrevData &prev_data) const
Returns the size of the array dimension.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
bool matches(const XFileArrayDef &other, const XFileDataDef *parent, const XFileDataDef *other_parent) const
Returns true if the node, particularly a template node, is structurally equivalent to the other node ...
Defines one level of array bounds for an associated XFileDataDef element.
Definition: xFileArrayDef.h:29
bool is_fixed_size() const
Returns true if this array definition specifies a const-size array, false if it is a dynamic-size arr...
Definition: xFileArrayDef.I:48
A definition of a single data element appearing within a template record.
Definition: xFileDataDef.h:35
XFileDataDef * get_dynamic_size() const
Returns the data element that names the dynamic size of the array, if is_fixed_size() returned false...
Definition: xFileArrayDef.I:71
int get_fixed_size() const
Returns the const size of the array, if is_fixed_size() returned true.
Definition: xFileArrayDef.I:59
int find_child_index(const string &name) const
Returns the index number of the child with the indicated name, if any, or -1 if none.
Definition: xFileNode.cxx:78
The abstract base class for a number of different types of data elements that may be stored in the X ...