Panda3D
eggObject.cxx
1 // Filename: eggObject.cxx
2 // Created by: drose (17Jan99)
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 "eggObject.h"
16 
17 TypeHandle EggObject::_type_handle;
18 
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: EggObject::Constructor
22 // Access: Published
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 EggObject::
26 EggObject() {
27 }
28 
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: EggObject::Copy constructor
32 // Access: Published
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 EggObject::
36 EggObject(const EggObject &copy) :
37  TypedReferenceCount(copy),
38  _user_data(copy._user_data),
39  _default_user_data(copy._default_user_data)
40 {
41 }
42 
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: EggObject::Copy assignment operator
46 // Access: Published
47 // Description:
48 ////////////////////////////////////////////////////////////////////
49 EggObject &EggObject::
50 operator = (const EggObject &copy) {
51  TypedReferenceCount::operator = (copy);
52  _user_data = copy._user_data;
53  _default_user_data = copy._default_user_data;
54  return *this;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: EggObject::Destructor
59 // Access: Published, Virtual
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 EggObject::
63 ~EggObject() {
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: EggObject::set_user_data
68 // Access: Published
69 // Description: Sets the user data associated with this object. This
70 // may be any EggUserData-derived object. The egg
71 // library will do nothing with this pointer, except to
72 // hold its reference count and return the pointer on
73 // request.
74 //
75 // The EggObject maintains multiple different
76 // EggUserData pointers, one for each unique type (as
77 // reported by get_type()). If you know that only one
78 // type of EggUserData object will be added in your
79 // application, you may use the query functions that
80 // accept no parameters, but it is recommended that in
81 // general you pass in the type of your particular user
82 // data, to allow multiple applications to coexist in
83 // the same egg data.
84 //
85 // This pointer is also copied by the copy assignment
86 // operator and copy constructor.
87 ////////////////////////////////////////////////////////////////////
88 void EggObject::
90  _user_data[user_data->get_type()] = user_data;
91  _default_user_data = user_data;
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: EggObject::get_user_data
96 // Access: Published
97 // Description: Returns the user data pointer most recently stored on
98 // this object, or NULL if nothing was previously
99 // stored.
100 ////////////////////////////////////////////////////////////////////
102 get_user_data() const {
103  return _default_user_data;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: EggObject::get_user_data
108 // Access: Published
109 // Description: Returns the user data pointer of the indicated type,
110 // if it exists, or NULL if it does not.
111 ////////////////////////////////////////////////////////////////////
114  UserData::const_iterator ui;
115  ui = _user_data.find(type);
116  if (ui != _user_data.end()) {
117  return (*ui).second;
118  }
119  return NULL;
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: EggObject::has_user_data
124 // Access: Published
125 // Description: Returns true if a generic user data pointer has
126 // recently been set and not yet cleared, false
127 // otherwise.
128 ////////////////////////////////////////////////////////////////////
129 bool EggObject::
130 has_user_data() const {
131  return !_default_user_data.is_null();
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: EggObject::has_user_data
136 // Access: Published
137 // Description: Returns true if the user data pointer of the
138 // indicated type has been set, false otherwise.
139 ////////////////////////////////////////////////////////////////////
140 bool EggObject::
142  UserData::const_iterator ui;
143  ui = _user_data.find(type);
144  return (ui != _user_data.end());
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: EggObject::clear_user_data
149 // Access: Published
150 // Description: Removes *all* user data pointers from the node.
151 ////////////////////////////////////////////////////////////////////
152 void EggObject::
154  _user_data.clear();
155  _default_user_data.clear();
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: EggObject::clear_user_data
160 // Access: Published
161 // Description: Removes the user data pointer of the indicated type.
162 ////////////////////////////////////////////////////////////////////
163 void EggObject::
165  UserData::iterator ui;
166  ui = _user_data.find(type);
167  if (ui != _user_data.end()) {
168  if ((*ui).second == _default_user_data) {
169  _default_user_data.clear();
170  }
171  _user_data.erase(ui);
172  }
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: EggObject::as_transform
177 // Access: Public, Virtual
178 // Description: Returns this object cross-cast to an EggTransform
179 // pointer, if it inherits from EggTransform, or NULL if
180 // it does not.
181 ////////////////////////////////////////////////////////////////////
184  return NULL;
185 }
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
void clear_user_data()
Removes *all* user data pointers from the node.
Definition: eggObject.cxx:153
bool has_user_data() const
Returns true if a generic user data pointer has recently been set and not yet cleared, false otherwise.
Definition: eggObject.cxx:130
virtual EggTransform * as_transform()
Returns this object cross-cast to an EggTransform pointer, if it inherits from EggTransform, or NULL if it does not.
Definition: eggObject.cxx:183
EggUserData * get_user_data() const
Returns the user data pointer most recently stored on this object, or NULL if nothing was previously ...
Definition: eggObject.cxx:102
void set_user_data(EggUserData *user_data)
Sets the user data associated with this object.
Definition: eggObject.cxx:89
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a base class for a user-defined data type to extend egg structures in processing code...
Definition: eggUserData.h:34
The highest-level base class in the egg directory.
Definition: eggObject.h:31
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
Definition: eggTransform.h:33