HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
type.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef TF_TYPE_H
25 #define TF_TYPE_H
26 
27 #include "pxr/pxr.h"
28 
29 #include "pxr/base/tf/api.h"
30 #include "pxr/base/tf/cxxCast.h"
31 #include "pxr/base/tf/refPtr.h"
33 #include "pxr/base/tf/traits.h"
35 
36 #include <hboost/operators.hpp>
37 
38 #include <iosfwd>
39 #include <memory>
40 #include <set>
41 #include <type_traits>
42 #include <typeinfo>
43 #include <vector>
44 
46 
47 #ifdef PXR_PYTHON_SUPPORT_ENABLED
48 class TfPyObjWrapper;
49 #endif // PXR_PYTHON_SUPPORT_ENABLED
50 
51 class TfType;
52 
53 /// \class TfType
54 ///
55 /// TfType represents a dynamic runtime type.
56 ///
57 /// TfTypes are created and discovered at runtime, rather than compile
58 /// time.
59 ///
60 /// Features:
61 ///
62 /// - unique typename
63 /// - safe across DSO boundaries
64 /// - can represent C++ types, pure Python types, or Python subclasses of
65 /// wrapped C++ types
66 /// - lightweight value semantics -- you can copy and default construct
67 /// TfType, unlike \c std::type_info.
68 /// - totally ordered -- can use as a \c std::map key
69 ///
70 class TfType : hboost::totally_ordered<TfType>
71 {
72  struct _TypeInfo;
73 
74 public:
75  /// Callback invoked when a declared type needs to be defined.
77 
78  /// Base class of all factory types.
79  class FactoryBase {
80  public:
81  TF_API virtual ~FactoryBase();
82  };
83 
84 public:
85 
86  enum LegacyFlags {
87  ABSTRACT = 0x01, ///< Abstract (unmanufacturable and unclonable)
88  CONCRETE = 0x02, ///< Not abstract
89  MANUFACTURABLE = 0x08, ///< Manufacturable type (implies concrete)
90  };
91 
92 #ifdef PXR_PYTHON_SUPPORT_ENABLED
93  // This is a non-templated base class for the templated
94  // polymorphic-to-Python infrastructure.
95  struct PyPolymorphicBase
96  {
97  protected:
98  TF_API virtual ~PyPolymorphicBase();
99  };
100 #endif // PXR_PYTHON_SUPPORT_ENABLED
101 
102 public:
103  /// A type-list of C++ base types.
104  /// \see TfType::Define()
105  template <class ... Args>
106  struct Bases {};
107 
108 public:
109  /// Construct an TfType representing an unknown type.
110  ///
111  /// To actually register a new type with the TfType system, see
112  /// TfType::Declare().
113  ///
114  /// Note that this always holds true:
115  /// \code
116  /// TfType().IsUnknown() == true
117  /// \endcode
118  ///
119  TF_API
120  TfType();
121 
122  /// Return an empty TfType, representing the unknown type.
123  ///
124  /// This is equivalento the default constructor, TfType(). This form exists
125  /// as a clearer way to express intent in code explicitly dealing with
126  /// unknown types.
127  ///
128  /// \see IsUnknown()
129  ///
130  TF_API
131  static TfType const& GetUnknownType();
132 
133  /// Equality operator.
134  ///
135  /// \note All unknown types (see IsUnknown()) are considered equal.
136  /// This is so all unknown types will only occupy one key when used in
137  /// an associative map.
138  inline bool operator ==(const TfType& t) const { return _info == t._info; }
139 
140  /// Comparison operator.
141  inline bool operator <(const TfType& t) const { return _info < t._info; }
142 
143 
144  /// \name Finding types
145  /// @{
146 
147  /// Retrieve the \c TfType corresponding to type \c T.
148  ///
149  /// The type \c T must have been defined in the type system or the
150  /// \c TfType corresponding to an unknown type is returned.
151  ///
152  /// \see IsUnknown()
153  ///
154  template <typename T>
155  static TfType const& Find() {
156  return Find(typeid(T));
157  }
158 
159  /// Retrieve the \c TfType corresponding to \c obj.
160  ///
161  /// The \c TfType corresponding to the actual object represented
162  /// by \c obj is returned; this may not be the object returned by
163  /// \c TfType::Find<T>() if \c T is a polymorphic type.
164  ///
165  /// This works for Python subclasses of the C++ type \c T as well,
166  /// as long as \c T has been wrapped using TfPyPolymorphic.
167  ///
168  /// Of course, the object's type must have been defined in the type
169  /// system or the \c TfType corresponding to an unknown type is returned.
170  ///
171  /// \see IsUnknown()
172  ///
173  template <typename T>
174  static TfType const& Find(const T &obj) {
175  typedef typename TfTraits::Type<T>::UnderlyingType Type;
176  // If T is polymorphic to python, we may have to bridge into python. We
177  // could also optimize for Ts that are not polymorphic at all and avoid
178  // doing rtti typeid lookups, but we trust the compiler to do this for
179  // us.
180  if (Type const *rawPtr = TfTypeFunctions<T>::GetRawPtr(obj))
181  return _FindImpl(rawPtr);
182  return GetUnknownType();
183  }
184 
185  /// Retrieve the \c TfType corresponding to an obj with the
186  /// given \c type_info.
187  ///
188  static TfType const& Find(const std::type_info &t) {
189  return _FindByTypeid(t);
190  }
191 
192  /// Retrieve the \c TfType corresponding to an obj with the
193  /// given \c type_info.
194  ///
195  static TfType const& FindByTypeid(const std::type_info &t) {
196  return _FindByTypeid(t);
197  }
198 
199  /// Retrieve the \c TfType corresponding to the given \c name.
200  ///
201  /// Every type defined in the TfType system has a unique, implementation
202  /// independent name. In addition, aliases can be added to identify
203  /// a type underneath a specific base type; see TfType::AddAlias().
204  /// The given name will first be tried as an alias under the root type,
205  /// and subsequently as a typename.
206  ///
207  /// This method is equivalent to:
208  /// \code
209  /// TfType::GetRoot().FindDerivedByName(name)
210  /// \endcode
211  ///
212  /// For any object \c obj,
213  /// \code
214  /// Find(obj) == FindByName( Find(obj).GetTypeName() )
215  /// \endcode
216  ///
217  TF_API
218  static TfType const& FindByName(const std::string &name);
219 
220  /// Retrieve the \c TfType that derives from this type and has the
221  /// given alias or typename.
222  ///
223  /// \see AddAlias
224  ///
225  TF_API
226  TfType const& FindDerivedByName(const std::string &name) const;
227 
228  /// Retrieve the \c TfType that derives from BASE and has the
229  /// given alias or typename.
230  ///
231  /// This is a convenience method, and is equivalent to:
232  /// \code
233  /// TfType::Find<BASE>().FindDerivedByName(name)
234  /// \endcode
235  ///
236  template <typename BASE>
237  static TfType const& FindDerivedByName(const std::string &name)
238  {
239  return TfType::Find<BASE>().FindDerivedByName(name);
240  }
241 
242 #ifdef PXR_PYTHON_SUPPORT_ENABLED
243  /// Retrieve the \c TfType corresponding to an obj with the
244  /// given Python class \c classObj.
245  ///
246  TF_API
247  static TfType const& FindByPythonClass(const TfPyObjWrapper & classObj);
248 #endif // PXR_PYTHON_SUPPORT_ENABLED
249 
250  /// @}
251 
252 
253  /// \name Type queries
254  /// @{
255 
256  /// Return the root type of the type hierarchy.
257  ///
258  /// All known types derive (directly or indirectly) from the root.
259  /// If a type is specified with no bases, it is implicitly
260  /// considered to derive from the root type.
261  ///
262  TF_API
263  static TfType const& GetRoot();
264 
265  /// Return the machine-independent name for this type.
266  /// This name is specified when the TfType is declared.
267  /// \see Declare()
268  ///
269  TF_API
270  const std::string &GetTypeName() const;
271 
272  /// Return a C++ RTTI type_info for this type.
273  ///
274  /// If this type is unknown or has not yet had a C++ type defined,
275  /// \c typeid(void) will be returned.
276  ///
277  /// \see Define()
278  ///
279  TF_API
280  const std::type_info &GetTypeid() const;
281 
282  /// Return the canonical typeName used for a given std::type_info.
283  ///
284  /// Exactly how the canonical name is generated is left undefined,
285  /// but in practice it is likely to be the demangled RTTI name
286  /// of the type_info, stripped of namespaces. The real answer
287  /// is implemented by this method.
288  ///
289  TF_API
290  static std::string GetCanonicalTypeName(const std::type_info &);
291 
292  /// Returns a vector of the aliases registered for the derivedType
293  /// under this, the base type.
294  /// \see AddAlias()
295  ///
296  TF_API
297  std::vector<std::string> GetAliases(TfType derivedType) const;
298 
299 #ifdef PXR_PYTHON_SUPPORT_ENABLED
300  /// Return the Python class object for this type.
301  ///
302  /// If this type is unknown or has not yet had a Python class
303  /// defined, this will return \c None, as an empty
304  /// \c TfPyObjWrapper
305  ///
306  /// \see DefinePythonClass()
307  ///
308  TF_API
309  TfPyObjWrapper GetPythonClass() const;
310 #endif // PXR_PYTHON_SUPPORT_ENABLED
311 
312  /// Return a vector of types from which this type was derived.
313  ///
314  TF_API
315  std::vector<TfType> GetBaseTypes() const;
316 
317  /// Copy the first \p maxBases base types of \p this type to \p out, or all
318  /// the base types if this type has \p maxBases or fewer base types. Return
319  /// \p this type's number of base types.
320  ///
321  /// Note that it is supported to change a TfType to its first base type by
322  /// calling this function. For example:
323  /// \code
324  /// TfType t = ...;
325  /// t.GetNBaseTypes(&t, 1);
326  /// \endcode
327  TF_API
328  size_t GetNBaseTypes(TfType *out, size_t maxBases) const;
329 
330  /// Return a vector of types derived directly from this type.
331  ///
332  TF_API
333  std::vector<TfType> GetDirectlyDerivedTypes() const;
334 
335  /// Return the canonical type for this type.
336  TF_API
337  TfType const& GetCanonicalType() const;
338 
339  /// Return the set of all types derived (directly or indirectly)
340  /// from this type.
341  ///
342  TF_API
343  void GetAllDerivedTypes( std::set<TfType> *result ) const;
344 
345  /// Build a vector of all ancestor types inherited by this type.
346  /// The starting type is itself included, as the first element of
347  /// the results vector.
348  ///
349  /// Types are given in "C3" resolution order, as used for new-style
350  /// classes starting in Python 2.3. This algorithm is more complicated
351  /// than a simple depth-first traversal of base classes, in order to
352  /// prevent some subtle errors with multiple-inheritance. See the
353  /// references below for more background.
354  ///
355  /// \note This can be expensive; consider caching the results. TfType
356  /// does not cache this itself since it is not needed internally.
357  ///
358  /// \see Guido van Rossum.
359  /// "Unifying types and classes in Python 2.2: Method resolution order."
360  /// http://www.python.org/download/releases/2.2.2/descrintro/#mro
361  ///
362  /// \see Barrett, Cassels, Haahr, Moon, Playford, Withington.
363  /// "A Monotonic Superclass Linearization for Dylan." OOPSLA 96.
364  /// http://www.webcom.com/haahr/dylan/linearization-oopsla96.html
365  ///
366  TF_API
367  void GetAllAncestorTypes(std::vector<TfType> *result) const;
368 
369  /// Return true if this type is the same as or derived from \p queryType.
370  /// If \c queryType is unknown, this always returns \c false.
371  ///
372  TF_API
373  bool IsA(TfType queryType) const;
374 
375  /// Return true if this type is the same as or derived from T.
376  /// This is equivalent to:
377  /// \code
378  /// IsA(Find<T>())
379  /// \endcode
380  ///
381  template <typename T>
382  bool IsA() const { return IsA(Find<T>()); }
383 
384  /// Return true if this is the unknown type, representing a type
385  /// unknown to the TfType system.
386  ///
387  /// The unknown type does not derive from the root type, or any
388  /// other type.
389  ///
390  bool IsUnknown() const { return *this == TfType(); }
391 
393 
394  /// Convert to bool -- return true if this type is not unknown, false
395  /// otherwise.
396  operator UnspecifiedBoolType() const {
397  return IsUnknown() ? NULL : &TfType::_info;
398  }
399 
400  /// Boolean not operator -- return true if this type is unknown, false
401  /// otherwise.
402  bool operator !() const { return !bool(*this); }
403 
404  /// Return true if this is the root type.
405  ///
406  bool IsRoot() const { return *this == GetRoot(); }
407 
408  /// Return true if this is an enum type.
409  ///
410  TF_API
411  bool IsEnumType() const;
412 
413  /// Return true if this is a plain old data type, as defined by C++.
414  ///
415  TF_API
416  bool IsPlainOldDataType() const;
417 
418  /// Return the size required to hold an instance of this type on the stack
419  /// (does not include any heap allocated memory the instance uses).
420  ///
421  /// This is what the C++ sizeof operator returns for the type, so this
422  /// value is not very useful for Python types (it will always be
423  /// sizeof(hboost::python::object)).
424  ///
425  TF_API
426  size_t GetSizeof() const;
427 
428  /// @}
429 
430 
431  /// \name Registering new types
432  /// @{
433 
434  /// Declare a TfType with the given \c typeName, but no base type
435  /// information. This just establishes the minimal stub for the
436  /// type to exist, prior to it being fleshed out with more
437  /// declarations (specifying base types) or a definition.
438  ///
439  TF_API
440  static TfType const&
441  Declare( const std::string & typeName );
442 
443  /// Declare a TfType with the given \c typeName and \c bases.
444  /// If the bases vector is empty, the type will be marked as
445  /// deriving from the root TfType (see TfType::GetRootType()).
446  /// The \c definitionCallback, if given, will be invoked later to
447  /// define the type when needed.
448  ///
449  /// It is ok to redeclare a type that has already been declared.
450  /// The given bases will supplement any existing bases. An
451  /// example use of this is the Plugin system, where only a single
452  /// base may be known in the plugin metadata, but when the code
453  /// is loaded later, a full set of bases is specified.
454  ///
455  /// It is an error to redeclare a type's definitionCallback.
456  ///
457  TF_API
458  static TfType const&
459  Declare( const std::string & typeName,
460  const std::vector<TfType> & bases,
461  DefinitionCallback definitionCallback=nullptr );
462 
463  /// Define a TfType with the given C++ type T and C++ base types
464  /// B. Each of the base types will be declared (but not defined)
465  /// as TfTypes if they have not already been.
466  ///
467  /// The typeName of the created TfType will be the canonical
468  /// demangled RTTI type name, as defined by GetCanonicalTypeName().
469  ///
470  /// It is an error to attempt to define a type that has already
471  /// been defined.
472  ///
473  template <typename T, typename B>
474  static TfType const& Define();
475 
476  /// Define a TfType with the given C++ type T and no bases.
477  /// See the other Define() template for more details.
478  ///
479  /// \note C++ does not allow default template arguments for function
480  /// templates, so we provide this separate definition for the case of
481  /// no bases.
482  ///
483  template <typename T>
484  static TfType const& Define();
485 
486 #ifdef PXR_PYTHON_SUPPORT_ENABLED
487  /// Define the Python class object corresponding to this TfType.
488  /// \see TfTypePythonClass
489  TF_API
490  void DefinePythonClass(const TfPyObjWrapper &classObj) const;
491 #endif // PXR_PYTHON_SUPPORT_ENABLED
492 
493  /// Add an alias for DERIVED beneath BASE.
494  ///
495  /// This is a convenience method, that declares both DERIVED and BASE
496  /// as TfTypes before adding the alias.
497  ///
498  template <typename Base, typename Derived>
499  static void AddAlias(const std::string &name) {
500  TfType b = Declare(GetCanonicalTypeName(typeid(Base)));
501  TfType d = Declare(GetCanonicalTypeName(typeid(Derived)));
502  d.AddAlias(b, name);
503  }
504 
505  /// Add an alias name for this type under the given base type.
506  ///
507  /// Aliases are similar to typedefs in C++: they provide an
508  /// alternate name for a type. The alias is defined with respect
509  /// to the given \c base type; aliases must be unique beneath that
510  /// base type.
511  ///
512  TF_API
513  void AddAlias(TfType base, const std::string &name) const;
514 
515  /// Convenience method to add an alias and return *this.
516  /// \see AddAlias()
517  const TfType &Alias(TfType base, const std::string &name) const {
518  AddAlias(base, name);
519  return *this;
520  }
521 
522  /// @}
523 
524 
525  /// \name Pointer casts
526  /// @{
527 
528  /// Cast \c addr to the address corresponding to the type \c ancestor.
529  ///
530  /// (This is a dangerous function; there's probably a much better way to
531  /// do whatever it is you're trying to do.)
532  ///
533  /// With multiple inheritance, you can't do a reinterpret_cast back to an
534  /// ancestor type; this function figures out how to cast addr to the
535  /// address corresponding to the type ancestor if in fact ancestor is
536  /// really an ancestor of the type corresponding to \c *this.
537  ///
538  /// In order for this function to work correctly, \p addr must have been a
539  /// pointer of type corresponding to \c *this, which was cast to void; and
540  /// of course the type of \p ancestor must be an ancestor of the type of
541  /// \c *this.
542  ///
543  /// \warning You are warned: this is deadly dangerous stuff, and you
544  /// shouldn't be doing it!
545  TF_API
546  void* CastToAncestor(TfType ancestor, void* addr) const;
547 
548  const void* CastToAncestor(TfType ancestor,
549  const void* addr) const {
550  return CastToAncestor(ancestor, const_cast<void*>(addr));
551  }
552 
553  /// Cast \c addr, which pointed to the ancestor type \p ancestor, to the
554  /// type of \c *this.
555  ///
556  /// This function is the opposite of \c CastToAncestor(); the assumption
557  /// is that \c addr was a pointer to the type corresponding to \c
558  /// ancestor, and was then reinterpret-cast to \c void*, but now you wish
559  /// to turn cast the pointer to the type corresponding to \c *this. While
560  /// the fact that \p addr was a pointer of type \c ancestor is taken on
561  /// faith, a runtime check is performed to verify that the underlying
562  /// object pointed to by \p addr is of type \c *this (or derived from \c
563  /// *this).
564  ///
565  /// \warning Again, this is dangerous territory, and there's probably
566  /// something much better than using this function.
567  TF_API
568  void* CastFromAncestor(TfType ancestor, void* addr) const;
569 
570  const void* CastFromAncestor(TfType ancestor,
571  const void* addr) const {
572  return CastFromAncestor(ancestor, const_cast<void*>(addr));
573  }
574 
575  /// @}
576 
577  /// \name Instantiation / Manufacturing
578  /// @{
579 
580  /// Sets the factory object for this type. A type's factory typically
581  /// has methods to instantiate the type given various arguments and must
582  /// inherit from \c FactoryBase. The factory cannot be changed once set.
583  TF_API
584  void SetFactory(std::unique_ptr<FactoryBase> factory) const;
585 
586  /// Sets the factory object for this type. A type's factory typically
587  /// has methods to instantiate the type given various arguments and must
588  /// inherit from \c FactoryBase. The factory cannot be changed once set.
589  template <class T>
590  void SetFactory(std::unique_ptr<T>& factory) const {
591  SetFactory(std::unique_ptr<FactoryBase>(std::move(factory)));
592  }
593 
594  /// Sets the factory object for this type to be a \c T. The factory
595  /// cannot be changed once set.
596  template <class T>
597  void SetFactory() const { SetFactory(std::unique_ptr<FactoryBase>(new T)); }
598 
599  /// Sets the factory object for this type. A type's factory typically
600  /// has methods to instantiate the type given various arguments and must
601  /// inherit from \c FactoryBase. The factory cannot be changed once set.
602  const TfType& Factory(std::unique_ptr<FactoryBase> factory) const {
603  SetFactory(std::move(factory));
604  return *this;
605  }
606 
607  /// Sets the factory object for this type. A type's factory typically
608  /// has methods to instantiate the type given various arguments and must
609  /// inherit from \c FactoryBase. The factory cannot be changed once set.
610  template <class T>
611  const TfType& Factory(std::unique_ptr<T>& factory) const
612  {
613  SetFactory(std::unique_ptr<FactoryBase>(std::move(factory)));
614  return *this;
615  }
616 
617  /// Sets the factory object for this type to be a \c T. The factory
618  /// cannot be changed once set.
619  template <class T>
620  const TfType& Factory() const {
621  SetFactory(std::unique_ptr<FactoryBase>(new T));
622  return *this;
623  }
624 
625  /// Returns the factory object for this type as a \c T*, or \c NULL if
626  /// there is no factory or the factory is not or is not derived from \c T.
627  /// Clients can check if a factory is set using
628  /// \c GetFactory<TfType::FactoryBase>().
629  template <class T>
630  T *GetFactory() const { return dynamic_cast<T*>(_GetFactory()); }
631 
632  /// @}
633 
634 private:
635  TF_API
636  FactoryBase* _GetFactory() const;
637 
638 #ifdef PXR_PYTHON_SUPPORT_ENABLED
639  TF_API
640  static TfType const &_FindImplPyPolymorphic(PyPolymorphicBase const *ptr);
641 
642  // PyPolymorphic case.
643  template <class T>
644  static typename std::enable_if<
646  _FindImpl(T const *rawPtr) {
647  return _FindImplPyPolymorphic(
648  static_cast<PyPolymorphicBase const *>(rawPtr));
649  }
650 
651  // Polymorphic.
652  template <class T>
653  static typename std::enable_if<
656  _FindImpl(T const *rawPtr) {
657  if (auto ptr = dynamic_cast<PyPolymorphicBase const *>(rawPtr))
658  return _FindImplPyPolymorphic(ptr);
659  return Find(typeid(*rawPtr));
660  }
661 
662  template <class T>
663  static typename std::enable_if<
665  _FindImpl(T const *rawPtr) {
666  return Find(typeid(T));
667  }
668 
669 #else
670  template <class T>
671  static typename std::enable_if<
673  _FindImpl(T const *rawPtr) {
674  return Find(typeid(*rawPtr));
675  }
676 
677  template <class T>
678  static typename std::enable_if<
680  _FindImpl(T const *rawPtr) {
681  return Find(typeid(T));
682  }
683 
684 #endif // PXR_PYTHON_SUPPORT_ENABLED
685 
686  bool _IsAImpl(TfType queryType) const;
687 
688  typedef void *(*_CastFunction)(void *, bool derivedToBase);
689 
690  template <typename TypeVector>
691  friend struct Tf_AddBases;
692  friend struct _TypeInfo;
693  friend class Tf_TypeRegistry;
694  friend class TfHash;
695 
696  // Construct a TfType with the given _TypeInfo.
697  explicit TfType(_TypeInfo *info) : _info(info) {}
698 
699  // Adds base type(s), and link as a derived type of that bases.
700  void _AddBases(
701  const std::vector<TfType> &bases,
702  std::vector<std::string> *errorToEmit) const;
703 
704  // Add the given function for casting to/from the given baseType.
705  TF_API
706  void _AddCppCastFunc(
707  const std::type_info &baseTypeInfo, _CastFunction) const;
708 
709  // Define this TfType to have the given type_info.
710  TF_API
711  void _DefineCppType(const std::type_info &,
712  size_t sizeofType,
713  bool isPodType,
714  bool isEnumType) const;
715 
716  // Execute the definition callback if one exists.
717  void _ExecuteDefinitionCallback() const;
718 
719  // Retrieve the \c TfType corresponding to an obj with the
720  // given \c type_info.
721  TF_API
722  static TfType const& _FindByTypeid(const std::type_info &);
723 
724  // Pointer to internal type representation.
725  // Our only data member.
726  _TypeInfo *_info;
727 };
728 
729 /// Output a TfType, using the machine-independent type name.
730 /// \ingroup group_tf_DebuggingOutput
731 TF_API std::ostream& operator<<(std::ostream& out, const TfType &t);
732 
733 /// Metafunction returning sizeof(T) for a type T (or 0 if T is a void type).
734 template <typename T>
735 struct TfSizeofType {
736  static const size_t value = sizeof(T);
737 };
738 template <>
740  static const size_t value = 0;
741 };
742 template <>
744  static const size_t value = 0;
745 };
746 template <>
747 struct TfSizeofType<volatile void> {
748  static const size_t value = 0;
749 };
750 template <>
751 struct TfSizeofType<const volatile void> {
752  static const size_t value = 0;
753 };
754 
756 
757 // Implementation details are put in this header.
758 #include "pxr/base/tf/type_Impl.h"
759 
760 #endif // TF_TYPE_H
bool IsUnknown() const
Definition: type.h:390
GLuint const GLchar * name
Definition: glew.h:1814
static TF_API TfType const & GetUnknownType()
#define TF_API
Definition: api.h:40
bool IsA() const
Definition: type.h:382
static TfType const & FindDerivedByName(const std::string &name)
Definition: type.h:237
static TF_API std::string GetCanonicalTypeName(const std::type_info &)
Manufacturable type (implies concrete)
Definition: type.h:89
static TfType const & Find()
Definition: type.h:155
static TF_API TfType const & Declare(const std::string &typeName)
static TfType const & FindByTypeid(const std::type_info &t)
Definition: type.h:195
const TfType & Factory(std::unique_ptr< T > &factory) const
Definition: type.h:611
GLhandleARB obj
Definition: glew.h:6236
TF_API std::vector< TfType > GetBaseTypes() const
TF_API void GetAllDerivedTypes(std::set< TfType > *result) const
TF_API TfType const & FindDerivedByName(const std::string &name) const
bool operator!() const
Definition: type.h:402
TF_API TfType()
static TfType const & Find(const std::type_info &t)
Definition: type.h:188
Base class of all factory types.
Definition: type.h:79
Definition: hash.h:86
const void * CastToAncestor(TfType ancestor, const void *addr) const
Definition: type.h:548
virtual TF_API ~FactoryBase()
const TfType & Alias(TfType base, const std::string &name) const
Definition: type.h:517
const TfType & Factory() const
Definition: type.h:620
static TfType const & Define()
Definition: type_Impl.h:78
bool IsRoot() const
Definition: type.h:406
static TF_API TfType const & FindByName(const std::string &name)
TF_API bool IsPlainOldDataType() const
void
Definition: png.h:1083
TF_API void * CastToAncestor(TfType ancestor, void *addr) const
friend class Tf_TypeRegistry
Definition: type.h:693
TF_API std::vector< std::string > GetAliases(TfType derivedType) const
Metafunction returning sizeof(T) for a type T (or 0 if T is a void type).
Definition: type.h:735
void SetFactory(std::unique_ptr< T > &factory) const
Definition: type.h:590
LegacyFlags
Definition: type.h:86
TF_API size_t GetNBaseTypes(TfType *out, size_t maxBases) const
bool operator==(const TfType &t) const
Definition: type.h:138
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
T UnderlyingType
Definition: traits.h:148
friend struct _TypeInfo
Definition: type.h:692
GLenum void * addr
Definition: glew.h:11505
Not abstract.
Definition: type.h:88
static TfType const & Find(const T &obj)
Definition: type.h:174
TF_API bool IsEnumType() const
TF_API TfType const & GetCanonicalType() const
Return the canonical type for this type.
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
TF_API size_t GetSizeof() const
TF_API void GetAllAncestorTypes(std::vector< TfType > *result) const
const void * ptr(const T *p)
Definition: format.h:3292
void(*)(TfType) DefinitionCallback
Callback invoked when a declared type needs to be defined.
Definition: type.h:76
TF_API const std::string & GetTypeName() const
TfType::_TypeInfo *TfType::* UnspecifiedBoolType
Definition: type.h:392
TF_API void * CastFromAncestor(TfType ancestor, void *addr) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
const TfType & Factory(std::unique_ptr< FactoryBase > factory) const
Definition: type.h:602
static void AddAlias(const std::string &name)
Definition: type.h:499
Definition: type.h:70
const void * CastFromAncestor(TfType ancestor, const void *addr) const
Definition: type.h:570
GLuint64EXT * result
Definition: glew.h:14007
TF_API const std::type_info & GetTypeid() const
T * GetFactory() const
Definition: type.h:630
TF_API std::ostream & operator<<(std::ostream &out, const TfType &t)
#define const
Definition: zconf.h:214
Abstract (unmanufacturable and unclonable)
Definition: type.h:87
TF_API std::vector< TfType > GetDirectlyDerivedTypes() const
GLsizei const GLfloat * value
Definition: glew.h:1849
static TF_API TfType const & GetRoot()
GLdouble GLdouble t
Definition: glew.h:1398
bool operator<(const TfType &t) const
Comparison operator.
Definition: type.h:141
void SetFactory() const
Definition: type.h:597