RSC  0.17.1
Environment.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSC project
4  *
5  * Copyright (C) 2011-2016 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <string>
30 #include <vector>
31 
32 #include <boost/filesystem/path.hpp>
33 
34 #include <rsc/logging/Logger.h>
35 
36 #include "ConfigSource.h"
37 
38 #include "rsc/config.h"
39 #include "rsc/rscexports.h"
40 
41 
42 namespace rsc {
43 namespace config {
44 
54 RSC_EXPORT boost::filesystem::path systemConfigDirectory();
55 
66 RSC_EXPORT boost::filesystem::path prefixConfigDirectory(
67  const boost::filesystem::path& prefix = RSC_INSTALL_PREFIX);
68 
79 RSC_EXPORT boost::filesystem::path userHomeDirectory();
80 
91 RSC_EXPORT boost::filesystem::path userConfigDirectory();
92 
103 RSC_EXPORT boost::shared_ptr<std::string>
104 getEnvironmentVariable(const std::string& name);
105 
115 class RSC_EXPORT EnvironmentVariableSource : public ConfigSource {
116 public:
117  class Match {
118  public:
119  Match(const std::string& rawName,
120  const std::string& transformedName,
121  const std::string& value);
122 
123  const std::string& getRawName() const;
124  const std::string& getTransformedName() const;
125  const std::string& getValue() const;
126  private:
127  std::string rawName;
128  std::string transformedName;
129  std::string value;
130  };
131  typedef std::vector<Match> Matches;
132 
145  EnvironmentVariableSource(const std::string& prefix = "",
146  const bool& stripPrefix = true);
147 
148  void provideOptions(OptionHandler& handler);
149 
157  Matches getMatches();
158 private:
160 
161  const std::string prefix;
163 
164  boost::shared_ptr<Matches> matches;
165 };
166 
167 }
168 }
path userConfigDirectory()
Return the canonical directory for configuration files of the user associated with the current proces...
Objects of this class analyze the environment of the current process, finding environment variables w...
Definition: Environment.h:115
Implementations of this interface receive options from ConfigSource objects.
Definition: OptionHandler.h:43
boost::shared_ptr< std::string > getEnvironmentVariable(const std::string &name)
Return the value of the environment value name or an empty pointer.
path systemConfigDirectory()
Return the directory in which system-wide configuration files are located.
Definition: Environment.cpp:56
path prefixConfigDirectory(const path &prefix)
Definition: Environment.cpp:64
Implementations of this interface obtain configuration information somewhere and pass individual conf...
Definition: ConfigSource.h:42
rsc::logging::LoggerPtr logger
Definition: Environment.h:159
boost::shared_ptr< Matches > matches
Definition: Environment.h:164
path userHomeDirectory()
Return the home directory of the user associated with the current process.
Definition: Environment.cpp:79
void handler(int signal)
boost::shared_ptr< Logger > LoggerPtr
Definition: Logger.h:41