Panda3D
Loading...
Searching...
No Matches
eggObject.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 eggObject.cxx
10 * @author drose
11 * @date 1999-01-17
12 */
13
14#include "eggObject.h"
15
16TypeHandle EggObject::_type_handle;
17
18
19/**
20 *
21 */
22EggObject::
23EggObject() {
24}
25
26
27/**
28 *
29 */
30EggObject::
31EggObject(const EggObject &copy) :
33 _user_data(copy._user_data),
34 _default_user_data(copy._default_user_data)
35{
36}
37
38
39/**
40 *
41 */
42EggObject &EggObject::
43operator = (const EggObject &copy) {
44 TypedReferenceCount::operator = (copy);
45 _user_data = copy._user_data;
46 _default_user_data = copy._default_user_data;
47 return *this;
48}
49
50/**
51 *
52 */
53EggObject::
54~EggObject() {
55}
56
57/**
58 * Sets the user data associated with this object. This may be any
59 * EggUserData-derived object. The egg library will do nothing with this
60 * pointer, except to hold its reference count and return the pointer on
61 * request.
62 *
63 * The EggObject maintains multiple different EggUserData pointers, one for
64 * each unique type (as reported by get_type()). If you know that only one
65 * type of EggUserData object will be added in your application, you may use
66 * the query functions that accept no parameters, but it is recommended that
67 * in general you pass in the type of your particular user data, to allow
68 * multiple applications to coexist in the same egg data.
69 *
70 * This pointer is also copied by the copy assignment operator and copy
71 * constructor.
72 */
74set_user_data(EggUserData *user_data) {
75 _user_data[user_data->get_type()] = user_data;
76 _default_user_data = user_data;
77}
78
79/**
80 * Returns the user data pointer most recently stored on this object, or NULL
81 * if nothing was previously stored.
82 */
84get_user_data() const {
85 return _default_user_data;
86}
87
88/**
89 * Returns the user data pointer of the indicated type, if it exists, or NULL
90 * if it does not.
91 */
93get_user_data(TypeHandle type) const {
94 UserData::const_iterator ui;
95 ui = _user_data.find(type);
96 if (ui != _user_data.end()) {
97 return (*ui).second;
98 }
99 return nullptr;
100}
101
102/**
103 * Returns true if a generic user data pointer has recently been set and not
104 * yet cleared, false otherwise.
105 */
107has_user_data() const {
108 return !_default_user_data.is_null();
109}
110
111/**
112 * Returns true if the user data pointer of the indicated type has been set,
113 * false otherwise.
114 */
116has_user_data(TypeHandle type) const {
117 UserData::const_iterator ui;
118 ui = _user_data.find(type);
119 return (ui != _user_data.end());
120}
121
122/**
123 * Removes *all* user data pointers from the node.
124 */
127 _user_data.clear();
128 _default_user_data.clear();
129}
130
131/**
132 * Removes the user data pointer of the indicated type.
133 */
136 UserData::iterator ui;
137 ui = _user_data.find(type);
138 if (ui != _user_data.end()) {
139 if ((*ui).second == _default_user_data) {
140 _default_user_data.clear();
141 }
142 _user_data.erase(ui);
143 }
144}
145
146/**
147 * Returns this object cross-cast to an EggTransform pointer, if it inherits
148 * from EggTransform, or NULL if it does not.
149 */
151as_transform() {
152 return nullptr;
153}
The highest-level base class in the egg directory.
Definition eggObject.h:29
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:84
virtual EggTransform * as_transform()
Returns this object cross-cast to an EggTransform pointer, if it inherits from EggTransform,...
bool has_user_data() const
Returns true if a generic user data pointer has recently been set and not yet cleared,...
void clear_user_data()
Removes *all* user data pointers from the node.
void set_user_data(EggUserData *user_data)
Sets the user data associated with this object.
Definition eggObject.cxx:74
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
This is a base class for a user-defined data type to extend egg structures in processing code.
Definition eggUserData.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.