Panda3D
 All Classes Functions Variables Enumerations
eggObject.cxx
00001 // Filename: eggObject.cxx
00002 // Created by:  drose (17Jan99)
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 "eggObject.h"
00016 
00017 TypeHandle EggObject::_type_handle;
00018 
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: EggObject::Constructor
00022 //       Access: Published
00023 //  Description:
00024 ////////////////////////////////////////////////////////////////////
00025 EggObject::
00026 EggObject() {
00027 }
00028 
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: EggObject::Copy constructor
00032 //       Access: Published
00033 //  Description:
00034 ////////////////////////////////////////////////////////////////////
00035 EggObject::
00036 EggObject(const EggObject &copy) : 
00037   TypedReferenceCount(copy),
00038   _user_data(copy._user_data),
00039   _default_user_data(copy._default_user_data)
00040 {
00041 }
00042 
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: EggObject::Copy assignment operator
00046 //       Access: Published
00047 //  Description:
00048 ////////////////////////////////////////////////////////////////////
00049 EggObject &EggObject::
00050 operator = (const EggObject &copy) {
00051   TypedReferenceCount::operator = (copy);
00052   _user_data = copy._user_data;
00053   _default_user_data = copy._default_user_data;
00054   return *this;
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: EggObject::Destructor
00059 //       Access: Published, Virtual
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 EggObject::
00063 ~EggObject() {
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: EggObject::set_user_data
00068 //       Access: Published
00069 //  Description: Sets the user data associated with this object.  This
00070 //               may be any EggUserData-derived object.  The egg
00071 //               library will do nothing with this pointer, except to
00072 //               hold its reference count and return the pointer on
00073 //               request.
00074 //
00075 //               The EggObject maintains multiple different
00076 //               EggUserData pointers, one for each unique type (as
00077 //               reported by get_type()).  If you know that only one
00078 //               type of EggUserData object will be added in your
00079 //               application, you may use the query functions that
00080 //               accept no parameters, but it is recommended that in
00081 //               general you pass in the type of your particular user
00082 //               data, to allow multiple applications to coexist in
00083 //               the same egg data.
00084 //
00085 //               This pointer is also copied by the copy assignment
00086 //               operator and copy constructor.
00087 ////////////////////////////////////////////////////////////////////
00088 void EggObject::
00089 set_user_data(EggUserData *user_data) {
00090   _user_data[user_data->get_type()] = user_data;
00091   _default_user_data = user_data;
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: EggObject::get_user_data
00096 //       Access: Published
00097 //  Description: Returns the user data pointer most recently stored on
00098 //               this object, or NULL if nothing was previously
00099 //               stored.
00100 ////////////////////////////////////////////////////////////////////
00101 EggUserData *EggObject::
00102 get_user_data() const {
00103   return _default_user_data;
00104 }
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //     Function: EggObject::get_user_data
00108 //       Access: Published
00109 //  Description: Returns the user data pointer of the indicated type,
00110 //               if it exists, or NULL if it does not.
00111 ////////////////////////////////////////////////////////////////////
00112 EggUserData *EggObject::
00113 get_user_data(TypeHandle type) const {
00114   UserData::const_iterator ui;
00115   ui = _user_data.find(type);
00116   if (ui != _user_data.end()) {
00117     return (*ui).second;
00118   }
00119   return NULL;
00120 }
00121 
00122 ////////////////////////////////////////////////////////////////////
00123 //     Function: EggObject::has_user_data
00124 //       Access: Published
00125 //  Description: Returns true if a generic user data pointer has
00126 //               recently been set and not yet cleared, false
00127 //               otherwise.
00128 ////////////////////////////////////////////////////////////////////
00129 bool EggObject::
00130 has_user_data() const {
00131   return !_default_user_data.is_null();
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: EggObject::has_user_data
00136 //       Access: Published
00137 //  Description: Returns true if the user data pointer of the
00138 //               indicated type has been set, false otherwise.
00139 ////////////////////////////////////////////////////////////////////
00140 bool EggObject::
00141 has_user_data(TypeHandle type) const {
00142   UserData::const_iterator ui;
00143   ui = _user_data.find(type);
00144   return (ui != _user_data.end());
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: EggObject::clear_user_data
00149 //       Access: Published
00150 //  Description: Removes *all* user data pointers from the node.
00151 ////////////////////////////////////////////////////////////////////
00152 void EggObject::
00153 clear_user_data() {
00154   _user_data.clear();
00155   _default_user_data.clear();
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: EggObject::clear_user_data
00160 //       Access: Published
00161 //  Description: Removes the user data pointer of the indicated type.
00162 ////////////////////////////////////////////////////////////////////
00163 void EggObject::
00164 clear_user_data(TypeHandle type) {
00165   UserData::iterator ui;
00166   ui = _user_data.find(type);
00167   if (ui != _user_data.end()) {
00168     if ((*ui).second == _default_user_data) {
00169       _default_user_data.clear();
00170     }
00171     _user_data.erase(ui);
00172   }
00173 }
00174 
00175 ////////////////////////////////////////////////////////////////////
00176 //     Function: EggObject::as_transform
00177 //       Access: Public, Virtual
00178 //  Description: Returns this object cross-cast to an EggTransform
00179 //               pointer, if it inherits from EggTransform, or NULL if
00180 //               it does not.
00181 ////////////////////////////////////////////////////////////////////
00182 EggTransform *EggObject::
00183 as_transform() {
00184   return NULL;
00185 }
 All Classes Functions Variables Enumerations