HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tf.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_TF_H
8 #define PXR_BASE_TF_TF_H
9 
10 /// \file tf/tf.h
11 /// A file containing basic constants and definitions.
12 
13 #if defined(__cplusplus) || defined(doxygen)
14 
15 #include "pxr/pxr.h"
16 
18 #include "pxr/base/arch/math.h"
19 #include "pxr/base/arch/inttypes.h"
20 
21 #include <math.h>
22 #include <utility>
23 
25 
26 // This constant will only be defined if not defined already. This is because
27 // many files need a higher limit and define this constant themselves before
28 // including anything else.
29 
30 #ifndef TF_MAX_ARITY
31 # define TF_MAX_ARITY 7
32 #endif // TF_MAX_ARITY
33 
34 
35 /// This value may be used by functions that return a \c size_t to indicate
36 /// that a special or error condition has occurred.
37 /// \ingroup group_tf_TfError
38 #define TF_BAD_SIZE_T SIZE_MAX
39 
40 /// \addtogroup group_tf_BasicMath
41 ///@{
42 
43 /// Returns the absolute value of the given \c int value.
44 inline int TfAbs(int v) {
45  return (v < 0 ? -v : v);
46 }
47 
48 /// Returns the absolute value of the given \c double value.
49 inline double TfAbs(double v) {
50  return fabs(v);
51 }
52 
53 /// Returns the smaller of the two given \c values.
54 template <class T>
55 inline T TfMin(const T& v1, const T& v2) {
56  return (v1 < v2 ? v1 : v2);
57 }
58 
59 /// Returns the larger of the two given \c values.
60 template <class T>
61 inline T TfMax(const T& v1, const T& v2) {
62  return (v1 > v2 ? v1 : v2);
63 }
64 
65 ///@}
66 
67 /// \struct TfDeleter
68 /// Function object for deleting any pointer.
69 ///
70 /// An STL collection of pointers does not automatically delete each
71 /// pointer when the collection itself is destroyed. Instead of writing
72 /// \code
73 /// for (list<Otter*>::iterator i = otters.begin(); i != otters.end(); ++i)
74 /// delete *i;
75 /// \endcode
76 /// you can use \c TfDeleter and simply write
77 /// \code
78 /// #include <algorithm>
79 ///
80 /// for_each(otters.begin(), otters.end(), TfDeleter());
81 /// \endcode
82 ///
83 /// \note \c TfDeleter calls the non-array version of \c delete.
84 /// Don't use \c TfDeleter if you allocated your space using \c new[]
85 /// (and consider using a \c vector<> in place of a built-in array).
86 /// Also, note that you need to put parenthesis after \c TfDeleter
87 /// in the call to \c for_each().
88 ///
89 /// Finally, \c TfDeleter also works for map-like collections.
90 /// Note that this works as follows: if \c TfDeleter is handed
91 /// a datatype of type \c std::pair<T1,T2*>, then the second element
92 /// of the pair is deleted, but the first (whether or not it is a pointer)
93 /// is left alone. In other words, if you give \c TfDeleter() a pair of
94 /// pointers, it only deletes the second, but never the first. This is the
95 /// desired behavior for maps.
96 ///
97 /// \ingroup group_tf_Stl
98 struct TfDeleter {
99  template <class T>
100  void operator() (T* t) const {
101  delete t;
102  }
103 
104  template <class T1, class T2>
105  void operator() (std::pair<T1, T2*> p) const {
106  delete p.second;
107  }
108 };
109 
110 /*
111  * The compile-time constants are not part of doxygen; if you know they're here,
112  * fine, but they should be used rarely, so we don't go out of our way to
113  * advertise them.
114  *
115  * Here's the idea: you may have an axiom or conditional check which is just too
116  * expensive to make part of a release build. Compilers these days will optimize
117  * away expressions they can evaluate at compile-time. So you can do
118  *
119  * if (TF_DEV_BUILD)
120  * TF_AXIOM(expensiveConditional);
121  *
122  * to get a condition axiom. You can even write
123  *
124  * TF_AXIOM(!TF_DEV_BUILD || expensiveConditional);
125  *
126  * What you CANNOT do is write
127  * #if defined(TF_DEV_BUILD)
128  * or
129  * #if TF_DEV_BUILD == 0
130  *
131  * The former compiles but always yields true; the latter doesn't compile.
132  * In other words, you can change the flow of control using these constructs,
133  * but we deliberately are prohibiting things like
134  *
135  * struct Bar {
136  * #if ...
137  * int _onlyNeededForChecks;
138  * #endif
139  * };
140  *
141  * or creating functions which only show up in some builds.
142  */
143 
144 #define TF_DEV_BUILD ARCH_DEV_BUILD
145 
147 
148 #endif // defined(__cplusplus)
149 
150 /// Stops compiler from producing unused argument or variable warnings.
151 /// This is useful mainly in C, because in C++ you can just leave
152 /// the variable unnamed. However, there are situations where this
153 /// can be useful even in C++, such as
154 /// \code
155 /// void
156 /// MyClass::Method( int foo )
157 /// {
158 /// #if defined(__APPLE__)
159 /// TF_UNUSED( foo );
160 /// // do something that doesn't need foo...
161 /// #else
162 /// // do something that needs foo
163 /// #endif
164 /// }
165 /// \endcode
166 ///
167 /// \ingroup group_tf_TfCompilerAids
168 #define TF_UNUSED(x) (void) x
169 
170 #endif // TF_H
const GLdouble * v
Definition: glcorearb.h:837
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GLdouble t
Definition: glad.h:2397
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLfloat GLfloat v1
Definition: glcorearb.h:817
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74