MRPT  2.0.4
get_env.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/core/from_string.h>
13 #include <cstdlib>
14 
15 namespace mrpt
16 {
17 /** Reads an environment variable, with a default value if not present.
18  * \ingroup mrpt_core_grp
19  */
20 template <class T>
21 inline T get_env(const std::string& varname, const T& defValue = T())
22 {
23  auto s = ::getenv(varname.c_str());
24  if (!s) return defValue;
25  return mrpt::from_string<T>(s, defValue, false /*dont throw*/);
26 }
27 
28 } // namespace mrpt
T get_env(const std::string &varname, const T &defValue=T())
Reads an environment variable, with a default value if not present.
Definition: get_env.h:21
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020