OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
GetEnvironmentVariable.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifdef _MSC_VER
26 // Don't warn about getenv
27 #define _CRT_SECURE_NO_WARNINGS
28 #endif
29 
30 // Internal Includes
33 
34 // Library/third-party includes
35 // - none
36 
37 // Standard includes
38 #include <cstdlib>
39 
40 namespace osvr {
41 namespace util {
42 #if defined(OSVR_WINDOWS) && !defined(OSVR_WINDOWS_DESKTOP)
43  boost::optional<std::string> getEnvironmentVariable(std::string const &) {
47  return boost::optional<std::string>();
48  }
49 #else
50  boost::optional<std::string>
52  getEnvironmentVariable(std::string const &var) {
53  boost::optional<std::string> ret;
54 
55  auto initialRet = std::getenv(var.c_str());
56  if (nullptr == initialRet) {
57  return ret;
58  }
59  std::string val(initialRet);
60 #ifdef OSVR_WINDOWS
61  // Windows doesn't distinguish between empty and not defined, so assume
62  // empty means not defined.
63  if (val.empty()) {
64  return ret;
65  }
66 #endif
67  ret = val;
68  return ret;
69  }
70 #endif // end of if windows non-desktop
71 } // namespace util
72 } // namespace osvr
boost::optional< std::string > getEnvironmentVariable(std::string const &var)
Gets an environment variable's value. On systems that don't distinguish between having a variable def...
Header for determining what "WinAPI Family Partition" we're in, in a simple way.