Panda3D
 All Classes Functions Variables Enumerations
internalName.I
1 // Filename: internalName.I
2 // Created by: masad (15Jul04)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: InternalName::make
18 // Access: Public, Static
19 // Description: The public interface for constructing an InternalName
20 // pointer. This will return a new InternalName
21 // representing the indicated name, if this is the first
22 // time the particular name has been requested; if the
23 // name is already in use, it will return the existing
24 // pointer.
25 //
26 // If the string contains the '.' character, the string
27 // will be divided at the dots and the so-defined
28 // hierarchy of names will be registered. This is
29 // handled transparently.
30 ////////////////////////////////////////////////////////////////////
31 INLINE PT(InternalName) InternalName::
32 make(const string &name) {
33  return get_root()->append(name);
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: InternalName::make
38 // Access: Public, Static
39 // Description: This version of make() is defined such as to accept
40 // mostly string literals, which may be string pooled
41 // by the compiler. This allows us to make an
42 // additional optimization.
43 //
44 // This constructor is also used for fixed-size arrays,
45 // since there is no neat way to catch string literals
46 // only. Presumably people aren't using InternalName
47 // in that way.
48 ////////////////////////////////////////////////////////////////////
49 template<int N>
50 INLINE PT(InternalName) InternalName::
51 make(const char (&literal)[N]) {
52  LightMutexHolder holder(_literal_table_lock);
53  LiteralTable::const_iterator it = _literal_table.find(literal);
54 
55  if (it == _literal_table.end()) {
56  PT(InternalName) name = get_root()->append(literal);
57  _literal_table.insert(LiteralTable::value_type(literal, name));
58  return name;
59  } else {
60  return it->second;
61  }
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: InternalName::get_parent
66 // Access: Published
67 // Description: Return the parent of this InternalName. All names
68 // have a parent, except the root name.
69 ////////////////////////////////////////////////////////////////////
70 INLINE InternalName *InternalName::
71 get_parent() const {
72  return _parent;
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: InternalName::get_basename
77 // Access: Published
78 // Description: Return the name represented by just this particular
79 // InternalName object, ignoring its parents names.
80 // This is everything after the rightmost dot.
81 ////////////////////////////////////////////////////////////////////
82 INLINE const string &InternalName::
83 get_basename() const {
84  return _basename;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: InternalName::get_root
89 // Access: Published, Static
90 // Description: Returns the standard root InternalName. This is the
91 // root of all other InternalNames. It has no name
92 // itself, and it is the only InternalName with no
93 // parent.
94 ////////////////////////////////////////////////////////////////////
95 INLINE PT(InternalName) InternalName::
96 get_root() {
97  if (_root == (InternalName *)NULL) {
98  _root = new InternalName(NULL, "");
99  }
100  return _root;
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: InternalName::get_error
105 // Access: Published, Static
106 // Description: Returns the standard InternalName "error".
107 ////////////////////////////////////////////////////////////////////
108 INLINE PT(InternalName) InternalName::
109 get_error() {
110  if (_error == (InternalName *)NULL) {
111  _error = InternalName::make("error");
112  }
113  return _error;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: InternalName::get_vertex
118 // Access: Published, Static
119 // Description: Returns the standard InternalName "vertex". This is
120 // the column header for the 3-d or 4-d vertex position
121 // information for each vertex.
122 ////////////////////////////////////////////////////////////////////
123 INLINE PT(InternalName) InternalName::
124 get_vertex() {
125  if (_vertex == (InternalName *)NULL) {
126  _vertex = InternalName::make("vertex");
127  }
128  return _vertex;
129 }
130 
131 ////////////////////////////////////////////////////////////////////
132 // Function: InternalName::get_normal
133 // Access: Published, Static
134 // Description: Returns the standard InternalName "normal". This is
135 // the column header for the 3-d lighting normal for
136 // each vertex.
137 ////////////////////////////////////////////////////////////////////
138 INLINE PT(InternalName) InternalName::
139 get_normal() {
140  if (_normal == (InternalName *)NULL) {
141  _normal = InternalName::make("normal");
142  }
143  return _normal;
144 }
145 
146 ////////////////////////////////////////////////////////////////////
147 // Function: InternalName::get_tangent
148 // Access: Published, Static
149 // Description: Returns the standard InternalName "tangent". This is
150 // the column header for the tangent vector associated
151 // with each vertex, which is a unit vector
152 // usually perpendicular to the normal and in the
153 // direction of the U texture coordinate change. It is
154 // used for deriving bump maps.
155 ////////////////////////////////////////////////////////////////////
156 INLINE PT(InternalName) InternalName::
157 get_tangent() {
158  if (_tangent == (InternalName *)NULL) {
159  _tangent = InternalName::make("tangent");
160  }
161  return _tangent;
162 }
163 
164 ////////////////////////////////////////////////////////////////////
165 // Function: InternalName::get_tangent_name
166 // Access: Published, Static
167 // Description: Returns the InternalName "tangent.name", where name
168 // is the supplied string. This is the column header
169 // for the tangent associated with the named texture
170 // coordinate set.
171 ////////////////////////////////////////////////////////////////////
172 INLINE PT(InternalName) InternalName::
173 get_tangent_name(const string &name) {
174  return get_tangent()->append(name);
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: InternalName::get_binormal
179 // Access: Published, Static
180 // Description: Returns the standard InternalName "binormal". This is
181 // the column header for the tangent vector associated
182 // with each vertex, which is a unit vector
183 // usually perpendicular to both the normal and the
184 // tangent, and in the direction of the V texture
185 // coordinate change. It is used for deriving bump
186 // maps.
187 ////////////////////////////////////////////////////////////////////
188 INLINE PT(InternalName) InternalName::
189 get_binormal() {
190  if (_binormal == (InternalName *)NULL) {
191  _binormal = InternalName::make("binormal");
192  }
193  return _binormal;
194 }
195 
196 ////////////////////////////////////////////////////////////////////
197 // Function: InternalName::get_binormal_name
198 // Access: Published, Static
199 // Description: Returns the InternalName "binormal.name", where name
200 // is the supplied string. This is the column header
201 // for the binormal associated with the named texture
202 // coordinate set.
203 ////////////////////////////////////////////////////////////////////
204 INLINE PT(InternalName) InternalName::
205 get_binormal_name(const string &name) {
206  return get_binormal()->append(name);
207 }
208 
209 ////////////////////////////////////////////////////////////////////
210 // Function: InternalName::get_texcoord
211 // Access: Published, Static
212 // Description: Returns the standard InternalName "texcoord". This
213 // is the column header for the default texture
214 // coordinate set for each vertex. It is also used for
215 // identifying the default texture coordinate set in a
216 // TextureStage.
217 ////////////////////////////////////////////////////////////////////
218 INLINE PT(InternalName) InternalName::
219 get_texcoord() {
220  if (_texcoord == (InternalName *)NULL) {
221  _texcoord = InternalName::make("texcoord");
222  }
223  return _texcoord;
224 }
225 
226 ////////////////////////////////////////////////////////////////////
227 // Function: InternalName::get_texcoord_name
228 // Access: Published, Static
229 // Description: Returns the InternalName "texcoord.name", where name
230 // is the supplied string. This is the column header
231 // for the named texture coordinate set for each vertex.
232 // It is also used for identifying the named texture
233 // coordinate set in a TextureStage.
234 ////////////////////////////////////////////////////////////////////
235 INLINE PT(InternalName) InternalName::
236 get_texcoord_name(const string &name) {
237  return get_texcoord()->append(name);
238 }
239 
240 ////////////////////////////////////////////////////////////////////
241 // Function: InternalName::get_color
242 // Access: Published, Static
243 // Description: Returns the standard InternalName "color". This is
244 // the column header for the 4-component color value for
245 // each vertex.
246 ////////////////////////////////////////////////////////////////////
247 INLINE PT(InternalName) InternalName::
248 get_color() {
249  if (_color == (InternalName *)NULL) {
250  _color = InternalName::make("color");
251  }
252  return _color;
253 }
254 
255 ////////////////////////////////////////////////////////////////////
256 // Function: InternalName::get_rotate
257 // Access: Published, Static
258 // Description: Returns the standard InternalName "rotate". This is
259 // the column header for the floating-point rotate
260 // value, which represents a number of degrees
261 // counter-clockwise to rotate each point or point
262 // sprite.
263 ////////////////////////////////////////////////////////////////////
264 INLINE PT(InternalName) InternalName::
265 get_rotate() {
266  if (_rotate == (InternalName *)NULL) {
267  _rotate = InternalName::make("rotate");
268  }
269  return _rotate;
270 }
271 
272 ////////////////////////////////////////////////////////////////////
273 // Function: InternalName::get_size
274 // Access: Published, Static
275 // Description: Returns the standard InternalName "size". This is
276 // the column header for the floating-point size value,
277 // which overrides the thickness parameter of the
278 // RenderModeAttrib on a per-vertex (e.g. per-point)
279 // basis.
280 ////////////////////////////////////////////////////////////////////
281 INLINE PT(InternalName) InternalName::
282 get_size() {
283  if (_size == (InternalName *)NULL) {
284  _size = InternalName::make("size");
285  }
286  return _size;
287 }
288 
289 ////////////////////////////////////////////////////////////////////
290 // Function: InternalName::get_aspect_ratio
291 // Access: Published, Static
292 // Description: Returns the standard InternalName "aspect_ratio".
293 // This is the column header for the floating-point
294 // aspect ratio value, which is used to define
295 // non-square points. This number is the ratio x / y,
296 // where y is the point size (above).
297 ////////////////////////////////////////////////////////////////////
298 INLINE PT(InternalName) InternalName::
299 get_aspect_ratio() {
300  if (_aspect_ratio == (InternalName *)NULL) {
301  _aspect_ratio = InternalName::make("aspect_ratio");
302  }
303  return _aspect_ratio;
304 }
305 
306 ////////////////////////////////////////////////////////////////////
307 // Function: InternalName::get_transform_blend
308 // Access: Published, Static
309 // Description: Returns the standard InternalName "transform_blend".
310 // This is the column header for the integer
311 // transform_blend index, which is used to define vertex
312 // animation on the CPU by indexing to a particular
313 // vertex weighting from the TransformBlendTable.
314 ////////////////////////////////////////////////////////////////////
315 INLINE PT(InternalName) InternalName::
316 get_transform_blend() {
317  if (_transform_blend == (InternalName *)NULL) {
318  _transform_blend = InternalName::make("transform_blend");
319  }
320  return _transform_blend;
321 }
322 
323 ////////////////////////////////////////////////////////////////////
324 // Function: InternalName::get_transform_weight
325 // Access: Published, Static
326 // Description: Returns the standard InternalName "transform_weight".
327 // This is the column header for the n-component
328 // transform_weight value, which is used in conjuntion
329 // with "transform_index" to define vertex animation on
330 // the graphics card. The transform_weight value
331 // specifies the weight of the nth transform. By
332 // convention, there are 1 fewer weight values than
333 // transforms, since the weights are assumed to sum to 1
334 // (and the last value is therefore implicit).
335 ////////////////////////////////////////////////////////////////////
336 INLINE PT(InternalName) InternalName::
337 get_transform_weight() {
338  if (_transform_weight == (InternalName *)NULL) {
339  _transform_weight = InternalName::make("transform_weight");
340  }
341  return _transform_weight;
342 }
343 
344 ////////////////////////////////////////////////////////////////////
345 // Function: InternalName::get_transform_index
346 // Access: Published, Static
347 // Description: Returns the standard InternalName "transform_index".
348 // This is the column header for the n-component
349 // transform_index value, which is used in conjuntion
350 // with "transform_weight" to define vertex animation on
351 // the graphics card. The transform_index value
352 // specifies the nth transform, by lookup in the
353 // TransformTable. The transform_index column may be
354 // omitted, in which case the nth transform is the nth
355 // entry in the table.
356 ////////////////////////////////////////////////////////////////////
357 INLINE PT(InternalName) InternalName::
358 get_transform_index() {
359  if (_transform_index == (InternalName *)NULL) {
360  _transform_index = InternalName::make("transform_index");
361  }
362  return _transform_index;
363 }
364 
365 ////////////////////////////////////////////////////////////////////
366 // Function: InternalName::get_morph
367 // Access: Published, Static
368 // Description: Returns an InternalName derived from the given base
369 // column name and the given slider name, which is the
370 // column header for the offset vector that should be
371 // applied to the base column name when the named morph
372 // slider is engaged.
373 //
374 // Each morph slider requires a set of n morph columns,
375 // one for each base column it applies to.
376 ////////////////////////////////////////////////////////////////////
377 INLINE PT(InternalName) InternalName::
378 get_morph(InternalName *column, const string &slider) {
379  // This actually returns "column.morph.slider", although that's just
380  // an implementation detail--as long as it returns a consistent,
381  // unique name for each combination of column and slider, everything
382  // is good.
383  return column->append("morph")->append(slider);
384 }
385 
386 ////////////////////////////////////////////////////////////////////
387 // Function: InternalName::get_index
388 // Access: Published, Static
389 // Description: Returns the standard InternalName "index". This is
390 // the column header for the integer vertex index. It
391 // is not used in the vertex data itself, but is used in
392 // the GeomPrimitive structure to index into the vertex
393 // data.
394 ////////////////////////////////////////////////////////////////////
395 INLINE PT(InternalName) InternalName::
396 get_index() {
397  if (_index == (InternalName *)NULL) {
398  _index = InternalName::make("index");
399  }
400  return _index;
401 }
402 
403 ////////////////////////////////////////////////////////////////////
404 // Function: InternalName::get_world
405 // Access: Published, Static
406 // Description: Returns the standard InternalName "world". This is
407 // used as a keyword in the shader subsystem.
408 ////////////////////////////////////////////////////////////////////
409 INLINE PT(InternalName) InternalName::
410 get_world() {
411  if (_world == (InternalName *)NULL) {
412  _world = InternalName::make("world");
413  }
414  return _world;
415 }
416 
417 ////////////////////////////////////////////////////////////////////
418 // Function: InternalName::get_camera
419 // Access: Published, Static
420 // Description: Returns the standard InternalName "camera". This is
421 // used as a keyword in the shader subsystem.
422 ////////////////////////////////////////////////////////////////////
423 INLINE PT(InternalName) InternalName::
424 get_camera() {
425  if (_camera == (InternalName *)NULL) {
426  _camera = InternalName::make("camera");
427  }
428  return _camera;
429 }
430 
431 ////////////////////////////////////////////////////////////////////
432 // Function: InternalName::get_model
433 // Access: Published, Static
434 // Description: Returns the standard InternalName "model". This is
435 // used as a keyword in the shader subsystem.
436 ////////////////////////////////////////////////////////////////////
437 INLINE PT(InternalName) InternalName::
438 get_model() {
439  if (_model == (InternalName *)NULL) {
440  _model = InternalName::make("model");
441  }
442  return _model;
443 }
444 
445 ////////////////////////////////////////////////////////////////////
446 // Function: InternalName::get_view
447 // Access: Published, Static
448 // Description: Returns the standard InternalName "view". This is
449 // used as a keyword in the shader subsystem.
450 ////////////////////////////////////////////////////////////////////
451 INLINE PT(InternalName) InternalName::
452 get_view() {
453  if (_view == (InternalName *)NULL) {
454  _view = InternalName::make("view");
455  }
456  return _view;
457 }
458 
459 ////////////////////////////////////////////////////////////////////
460 // Function: InternalName::output operator
461 // Access: Public
462 // Description:
463 ////////////////////////////////////////////////////////////////////
464 INLINE ostream &
465 operator << (ostream &out, const InternalName &tcn) {
466  tcn.output(out);
467  return out;
468 }
469 
470 #ifndef CPPPARSER
471 ////////////////////////////////////////////////////////////////////
472 // Function: CPT_InternalName::Constructor
473 // Access: Public
474 // Description:
475 ////////////////////////////////////////////////////////////////////
476 INLINE CPT_InternalName::
477 CPT_InternalName(const InternalName *ptr) :
478  ConstPointerTo<InternalName>(ptr)
479 {
480 }
481 
482 ////////////////////////////////////////////////////////////////////
483 // Function: CPT_InternalName::Copy Constructor
484 // Access: Public
485 // Description:
486 ////////////////////////////////////////////////////////////////////
487 INLINE CPT_InternalName::
488 CPT_InternalName(const PointerTo<InternalName> &copy) :
489  ConstPointerTo<InternalName>(copy)
490 {
491 }
492 
493 ////////////////////////////////////////////////////////////////////
494 // Function: CPT_InternalName::Copy Constructor
495 // Access: Public
496 // Description:
497 ////////////////////////////////////////////////////////////////////
498 INLINE CPT_InternalName::
499 CPT_InternalName(const ConstPointerTo<InternalName> &copy) :
500  ConstPointerTo<InternalName>(copy)
501 {
502 }
503 
504 ////////////////////////////////////////////////////////////////////
505 // Function: CPT_InternalName::Conversion Constructor
506 // Access: Public
507 // Description:
508 ////////////////////////////////////////////////////////////////////
509 INLINE CPT_InternalName::
510 CPT_InternalName(const string &name) :
511  ConstPointerTo<InternalName>(InternalName::make(name))
512 {
513 }
514 
515 ////////////////////////////////////////////////////////////////////
516 // Function: CPT_InternalName::Conversion Constructor
517 // Access: Public
518 // Description:
519 ////////////////////////////////////////////////////////////////////
520 template<int N>
521 INLINE CPT_InternalName::
522 CPT_InternalName(const char (&literal)[N]) :
523  ConstPointerTo<InternalName>(InternalName::make(literal))
524 {
525 }
526 
527 #ifdef USE_MOVE_SEMANTICS
528 ////////////////////////////////////////////////////////////////////
529 // Function: CPT_InternalName::Move Constructor
530 // Access: Public
531 // Description:
532 ////////////////////////////////////////////////////////////////////
533 INLINE CPT_InternalName::
534 CPT_InternalName(PointerTo<InternalName> &&from) NOEXCEPT :
535  ConstPointerTo<InternalName>(move(from))
536 {
537 }
538 
539 ////////////////////////////////////////////////////////////////////
540 // Function: CPT_InternalName::Move Constructor
541 // Access: Public
542 // Description:
543 ////////////////////////////////////////////////////////////////////
544 INLINE CPT_InternalName::
545 CPT_InternalName(ConstPointerTo<InternalName> &&from) NOEXCEPT :
546  ConstPointerTo<InternalName>(move(from))
547 {
548 }
549 
550 ////////////////////////////////////////////////////////////////////
551 // Function: CPT_InternalName::Move Assignment Operator
552 // Access: Public
553 // Description:
554 ////////////////////////////////////////////////////////////////////
555 INLINE CPT_InternalName &CPT_InternalName::
556 operator = (PointerTo<InternalName> &&from) NOEXCEPT {
557  this->reassign(move(from));
558  return *this;
559 }
560 
561 ////////////////////////////////////////////////////////////////////
562 // Function: CPT_InternalName::Move Assignment Operator
563 // Access: Public
564 // Description:
565 ////////////////////////////////////////////////////////////////////
566 INLINE CPT_InternalName &CPT_InternalName::
567 operator = (ConstPointerTo<InternalName> &&from) NOEXCEPT {
568  this->reassign(move(from));
569  return *this;
570 }
571 #endif // USE_MOVE_SEMANTICS
572 
573 ////////////////////////////////////////////////////////////////////
574 // Function: CPT_InternalName::Assignment operator
575 // Access: Published
576 // Description:
577 ////////////////////////////////////////////////////////////////////
578 INLINE CPT_InternalName &CPT_InternalName::
579 operator = (const To *ptr) {
580  this->reassign((To *)ptr);
581  return *this;
582 }
583 
584 ////////////////////////////////////////////////////////////////////
585 // Function: CPT_InternalName::Assignment operator
586 // Access: Published
587 // Description:
588 ////////////////////////////////////////////////////////////////////
589 INLINE CPT_InternalName &CPT_InternalName::
590 operator = (const PointerTo<InternalName> &copy) {
591  this->reassign((const ConstPointerTo<InternalName> &)copy);
592  return *this;
593 }
594 
595 ////////////////////////////////////////////////////////////////////
596 // Function: CPT_InternalName::Assignment operator
597 // Access: Published
598 // Description:
599 ////////////////////////////////////////////////////////////////////
600 INLINE CPT_InternalName &CPT_InternalName::
601 operator = (const ConstPointerTo<InternalName> &copy) {
602  this->reassign((const ConstPointerTo<InternalName> &)copy);
603  return *this;
604 }
605 #endif // CPPPARSER
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:197
Similar to MutexHolder, but for a light mutex.
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing...
Definition: pointerTo.h:144
PointerTo is a template class which implements a smart pointer to an object derived from ReferenceCou...
Definition: pointerTo.h:79