This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
12
13#if defined(__cplusplus) || defined(doxygen)
14
15#include "pxr/pxr.h"
16
17#include "pxr/base/arch/buildMode.h"
18#include "pxr/base/arch/math.h"
20
21#include <math.h>
22#include <utility>
23
24PXR_NAMESPACE_OPEN_SCOPE
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
38#define TF_BAD_SIZE_T SIZE_MAX
39
42
44inline int TfAbs(int v) {
45 return (v < 0 ? -v : v);
46}
47
49inline double TfAbs(double v) {
50 return fabs(v);
51}
52
54template <class T>
55inline T TfMin(const T& v1, const T& v2) {
56 return (v1 < v2 ? v1 : v2);
57}
58
60template <class T>
61inline T TfMax(const T& v1, const T& v2) {
62 return (v1 > v2 ? v1 : v2);
63}
64
66
98struct 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
146PXR_NAMESPACE_CLOSE_SCOPE
147
148#endif // defined(__cplusplus)
149
168#define TF_UNUSED(x) (void) x
169
170#endif // TF_H
Architecture-specific math function calls.
Assorted mathematical utility functions.
T TfMax(const T &v1, const T &v2)
Returns the larger of the two given values.
Definition: tf.h:61
T TfMin(const T &v1, const T &v2)
Returns the smaller of the two given values.
Definition: tf.h:55
int TfAbs(int v)
Returns the absolute value of the given int value.
Definition: tf.h:44
Define integral types.
Function object for deleting any pointer.
Definition: tf.h:98