Panda3D
Loading...
Searching...
No Matches
xFileArrayDef.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 xFileArrayDef.cxx
10 * @author drose
11 * @date 2004-10-03
12 */
13
14#include "xFileArrayDef.h"
15#include "xFileDataDef.h"
16#include "xFileDataObject.h"
17
18/**
19 * Returns the size of the array dimension. If this is a fixed array, the
20 * size is trivial; if it is dynamic, the size is determined by looking up the
21 * dynamic_size element in the prev_data table (which lists all of the data
22 * values already defined at this scoping level).
23 */
25get_size(const XFileNode::PrevData &prev_data) const {
26 if (is_fixed_size()) {
27 return _fixed_size;
28 } else {
29 XFileNode::PrevData::const_iterator pi;
30 pi = prev_data.find(_dynamic_size);
31 nassertr_always(pi != prev_data.end(), 0);
32 nassertr((*pi).second != nullptr, 0);
33 return (*pi).second->i();
34 }
35}
36
37/**
38 *
39 */
40void XFileArrayDef::
41output(std::ostream &out) const {
42 if (is_fixed_size()) {
43 out << "[" << _fixed_size << "]";
44 } else {
45 out << "[" << _dynamic_size->get_name() << "]";
46 }
47}
48
49/**
50 * Returns true if the node, particularly a template node, is structurally
51 * equivalent to the other node (which must be of the same type). This checks
52 * data element types, but does not compare data element names.
53 */
55matches(const XFileArrayDef &other, const XFileDataDef *parent,
56 const XFileDataDef *other_parent) const {
57 if (other.is_fixed_size() != is_fixed_size()) {
58 return false;
59 }
60 if (is_fixed_size()) {
61 if (other.get_fixed_size() != get_fixed_size()) {
62 return false;
63 }
64
65 } else {
66 int child_index = parent->find_child_index(get_dynamic_size());
67 int other_child_index =
68 other_parent->find_child_index(other.get_dynamic_size());
69 if (other_child_index != child_index) {
70 return false;
71 }
72 }
73
74 return true;
75}
Defines one level of array bounds for an associated XFileDataDef element.
bool is_fixed_size() const
Returns true if this array definition specifies a const-size array, false if it is a dynamic-size arr...
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 ...
int get_fixed_size() const
Returns the const size of the array, if is_fixed_size() returned true.
XFileDataDef * get_dynamic_size() const
Returns the data element that names the dynamic size of the array, if is_fixed_size() returned false.
int get_size(const XFileNode::PrevData &prev_data) const
Returns the size of the array dimension.
A definition of a single data element appearing within a template record.
int find_child_index(const std::string &name) const
Returns the index number of the child with the indicated name, if any, or -1 if none.
Definition xFileNode.cxx:70
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.