libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
getenv.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2012, 2013 Aldebaran Robotics. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the COPYING file.
6  */
7 
8 #ifndef QI_GETENV_HPP
9 #define QI_GETENV_HPP
10 
11 #include <qi/os.hpp>
12 #include <boost/lexical_cast.hpp>
13 
14 namespace qi
15 {
16 namespace os
17 {
18 
19 template <typename T>
20 T getEnvDefault(const char* name, T defaultVal)
21 {
22  std::string sval = qi::os::getenv(name);
23  if (sval.empty())
24  return defaultVal;
25  else
26  return boost::lexical_cast<T>(sval);
27 }
28 
29 }
30 }
31 
32 #endif
std::string getenv(const char *var)
Get an environment variable.
T getEnvDefault(const char *name, T defaultVal)
Definition: getenv.hpp:20