HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
getenv.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_GETENV_H
8 #define PXR_BASE_TF_GETENV_H
9 
10 /// \file tf/getenv.h
11 /// \ingroup group_tf_SystemsExt
12 /// Functions for accessing environment variables.
13 
14 #include "pxr/pxr.h"
15 #include "pxr/base/tf/api.h"
16 
17 #include <string>
18 
20 
21 /// \addtogroup group_tf_SystemsExt
22 ///@{
23 
24 /// Return an environment variable as a string.
25 ///
26 /// Return the value of the environment variable \c envName
27 /// as a string. If the variable is unset, or is the empty string,
28 /// then \c defaultValue is returned.
29 TF_API
30 std::string TfGetenv(const std::string& envName,
31  const std::string& defaultValue = "");
32 
33 /// Return an environment variable as an integer.
34 ///
35 /// Return the value of the environment variable \c envName as an integer. If
36 /// the variable is unset, or is the empty string, then \c defaultValue is
37 /// returned. Otherwise, the function uses atoi() to convert the string to an
38 /// integer: the implication being that if the string is not a valid integer,
39 /// you get back whatever value atoi() comes up with.
40 TF_API
41 int TfGetenvInt(const std::string& envName, int defaultValue);
42 
43 /// Return an environment variable as a boolean.
44 ///
45 /// Return the value of the environment variable \c envName as a boolean. If
46 /// the variable is unset, or is the empty string, then \c defaultValue is
47 /// returned. A value of \c true is returned if the environment variable is
48 /// any of "true", "yes", "on" or "1"; the match is not case sensitive. All
49 /// other values yield a return value of \c false.
50 TF_API
51 bool TfGetenvBool(const std::string&, bool defaultValue);
52 
53 /// Return an environment variable as a double.
54 ///
55 /// Return the value of the environment variable \c envName as a double. If
56 /// the variable is unset, or is the empty string, then \c defaultValue is
57 /// returned. Otherwise, the function uses TfStringToDouble() to convert the
58 /// string to a double: the implication being that if the string is not a
59 /// valid double, you get back whatever value TfStringToDouble() comes up
60 /// with.
61 TF_API
62 double TfGetenvDouble(const std::string& envName, double defaultValue);
63 
64 ///@}
65 
67 
68 #endif
#define TF_API
Definition: api.h:23
TF_API double TfGetenvDouble(const std::string &envName, double defaultValue)
TF_API std::string TfGetenv(const std::string &envName, const std::string &defaultValue="")
TF_API bool TfGetenvBool(const std::string &, bool defaultValue)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
TF_API int TfGetenvInt(const std::string &envName, int defaultValue)