00001 // Filename: dcMolecularField.cxx 00002 // Created by: drose (05Oct00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "dcMolecularField.h" 00020 #include "dcAtomicField.h" 00021 #include "hashGenerator.h" 00022 #include "dcindent.h" 00023 00024 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: DCMolecularField::as_molecular_field 00028 // Access: Public, Virtual 00029 // Description: Returns the same field pointer converted to a 00030 // molecular field pointer, if this is in fact a 00031 // molecular field; otherwise, returns NULL. 00032 //////////////////////////////////////////////////////////////////// 00033 DCMolecularField *DCMolecularField:: 00034 as_molecular_field() { 00035 return this; 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: DCMolecularField::get_num_atomics 00040 // Access: Public 00041 // Description: Returns the number of atomic fields that make up this 00042 // molecular field. 00043 //////////////////////////////////////////////////////////////////// 00044 int DCMolecularField:: 00045 get_num_atomics() const { 00046 return _fields.size(); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: DCMolecularField::get_atomic 00051 // Access: Public 00052 // Description: Returns the nth atomic field that makes up this 00053 // molecular field. This may or may not be a field of 00054 // this particular class; it might be defined in a 00055 // parent class. 00056 //////////////////////////////////////////////////////////////////// 00057 DCAtomicField *DCMolecularField:: 00058 get_atomic(int n) const { 00059 nassertr(n >= 0 && n < (int)_fields.size(), NULL); 00060 return _fields[n]; 00061 } 00062 00063 //////////////////////////////////////////////////////////////////// 00064 // Function: DCMolecularField::Constructor 00065 // Access: Public 00066 // Description: 00067 //////////////////////////////////////////////////////////////////// 00068 DCMolecularField:: 00069 DCMolecularField() { 00070 _number = 0; 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: DCMolecularField::write 00075 // Access: Public, Virtual 00076 // Description: Generates a parseable description of the object to 00077 // the indicated output stream. 00078 //////////////////////////////////////////////////////////////////// 00079 void DCMolecularField:: 00080 write(ostream &out, int indent_level) const { 00081 indent(out, indent_level) << _name; 00082 00083 if (!_fields.empty()) { 00084 Fields::const_iterator fi = _fields.begin(); 00085 out << " : " << (*fi)->_name; 00086 ++fi; 00087 while (fi != _fields.end()) { 00088 out << ", " << (*fi)->_name; 00089 ++fi; 00090 } 00091 } 00092 00093 out << "; // field " << _number << "\n"; 00094 } 00095 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: DCMolecularField::generate_hash 00099 // Access: Public, Virtual 00100 // Description: Accumulates the properties of this field into the 00101 // hash. 00102 //////////////////////////////////////////////////////////////////// 00103 void DCMolecularField:: 00104 generate_hash(HashGenerator &hashgen) const { 00105 DCField::generate_hash(hashgen); 00106 00107 hashgen.add_int(_fields.size()); 00108 Fields::const_iterator fi; 00109 for (fi = _fields.begin(); fi != _fields.end(); ++fi) { 00110 (*fi)->generate_hash(hashgen); 00111 } 00112 }