Panda3D
 All Classes Functions Variables Enumerations
xFileArrayDef.cxx
00001 // Filename: xFileArrayDef.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 "xFileArrayDef.h"
00016 #include "xFileDataDef.h"
00017 #include "xFileDataObject.h"
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: XFileArrayDef::get_size
00021 //       Access: Public
00022 //  Description: Returns the size of the array dimension.  If this is
00023 //               a fixed array, the size is trivial; if it is dynamic,
00024 //               the size is determined by looking up the dynamic_size
00025 //               element in the prev_data table (which lists all of
00026 //               the data values already defined at this scoping
00027 //               level).
00028 ////////////////////////////////////////////////////////////////////
00029 int XFileArrayDef::
00030 get_size(const XFileNode::PrevData &prev_data) const {
00031   if (is_fixed_size()) {
00032     return _fixed_size;
00033   } else {
00034     XFileNode::PrevData::const_iterator pi;
00035     pi = prev_data.find(_dynamic_size);
00036     nassertr_always(pi != prev_data.end(), 0);
00037     nassertr((*pi).second != (XFileDataObject *)NULL, 0);
00038     return (*pi).second->i();
00039   }
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: XFileArrayDef::output
00044 //       Access: Public
00045 //  Description: 
00046 ////////////////////////////////////////////////////////////////////
00047 void XFileArrayDef::
00048 output(ostream &out) const {
00049   if (is_fixed_size()) {
00050     out << "[" << _fixed_size << "]";
00051   } else {
00052     out << "[" << _dynamic_size->get_name() << "]";
00053   }
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: XFileArrayDef::matches
00058 //       Access: Public, Virtual
00059 //  Description: Returns true if the node, particularly a template
00060 //               node, is structurally equivalent to the other node
00061 //               (which must be of the same type).  This checks data
00062 //               element types, but does not compare data element
00063 //               names.
00064 ////////////////////////////////////////////////////////////////////
00065 bool XFileArrayDef::
00066 matches(const XFileArrayDef &other, const XFileDataDef *parent,
00067         const XFileDataDef *other_parent) const {
00068   if (other.is_fixed_size() != is_fixed_size()) {
00069     return false;
00070   }
00071   if (is_fixed_size()) {
00072     if (other.get_fixed_size() != get_fixed_size()) {
00073       return false;
00074     }
00075 
00076   } else {
00077     int child_index = parent->find_child_index(get_dynamic_size());
00078     int other_child_index = 
00079       other_parent->find_child_index(other.get_dynamic_size());
00080     if (other_child_index != child_index) {
00081       return false;
00082     }
00083   }
00084 
00085   return true;
00086 }
 All Classes Functions Variables Enumerations