Gazebo Common

API Reference

4.7.0
gz/common/SystemPaths.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_COMMON_SYSTEMPATHS_HH_
18 #define IGNITION_COMMON_SYSTEMPATHS_HH_
19 
20 #include <stdio.h>
21 
22 #ifdef _WIN32
23  #include <direct.h>
24  #define GetCurrentDir _getcwd
25 #else
26  #include <unistd.h>
27  #define GetCurrentDir getcwd
28 #endif
29 
30 #include <functional>
31 #include <list>
32 #include <memory>
33 #include <string>
34 #include <vector>
35 
36 #include <gz/common/config.hh>
37 #include <gz/common/Export.hh>
39 #include <gz/common/URI.hh>
40 
41 namespace ignition
42 {
43  namespace common
44  {
45  // Forward declare private data class
46  class SystemPathsPrivate;
47 
52  class IGNITION_COMMON_VISIBLE SystemPaths
53  {
55  public: SystemPaths();
56 
58  public: virtual ~SystemPaths();
59 
65  public: std::string LogPath() const;
66 
69  public: const std::list<std::string> &PluginPaths();
70 
76  public: std::string FindFileURI(const std::string &_uri) const;
77 
85  public: std::string FindFileURI(const ignition::common::URI &_uri) const;
86 
89  public: void SetPluginPathEnv(const std::string &_env);
90 
98  public: std::string FindFile(const std::string &_filename,
99  const bool _searchLocalPath = true,
100  const bool _verbose = true) const;
101 
110  public: std::string FindSharedLibrary(const std::string &_libName);
111 
114  public: void AddPluginPaths(const std::string &_path);
115 
117  public: void ClearPluginPaths();
118 
126  public: void SetFilePathEnv(const std::string &_env);
127 
134  public: std::string FilePathEnv() const;
135 
138  public: const std::list<std::string> &FilePaths();
139 
145  public: void AddFilePaths(const std::string &_path);
146 
148  public: void ClearFilePaths();
149 
152  public: void AddSearchPathSuffix(const std::string &_suffix);
153 
160  public: void IGN_DEPRECATED(3) SetFindFileCallback(
161  std::function<std::string(const std::string &)> _cb);
162 
172  public: void AddFindFileCallback(
173  std::function<std::string(const std::string &)> _cb);
174 
184  public: void AddFindFileURICallback(
186 
193  public: void IGN_DEPRECATED(3) SetFindFileURICallback(
194  std::function<std::string(const std::string &)> _cb);
195 
207  public: static std::string LocateLocalFile(const std::string &_filename,
208  const std::vector<std::string> &_paths);
209 
214  public: static std::string NormalizeDirectoryPath(
215  const std::string &_path);
216 
220  public: static std::list<std::string> PathsFromEnv(
221  const std::string &_env);
222 
225  public: static char Delimiter();
226 
229  private: std::unique_ptr<SystemPathsPrivate> dataPtr;
231  };
232  }
233 }
234 #endif
void SetFindFileURICallback(std::function< std::string(const std::string &)> _cb)
Set the callback to use when ignition can't find a file uri. The callback should return a complete pa...
Forward declarations for the common classes.
STL class.
void AddFilePaths(const std::string &_path)
Add colon (semicolon on windows) delimited paths to find files. These paths will be used with the Fin...
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
STL class.
STL class.
std::string FindFileURI(const std::string &_uri) const
Find a file or path using a URI.
static std::string NormalizeDirectoryPath(const std::string &_path)
Format the directory path to use "/" as a separator with "/" at the end.
static std::list< std::string > PathsFromEnv(const std::string &_env)
Return all paths given by an environment variable.
void SetFindFileCallback(std::function< std::string(const std::string &)> _cb)
Set the callback to use when ignition can't find a file. The callback should return a complete path t...
std::string LogPath() const
Get the log path. If IGN_LOG_PATH environment variable is set, then this path is used....
void AddFindFileCallback(std::function< std::string(const std::string &)> _cb)
Add a callback to use when FindFile() can't find a file. The callback should return a full local path...
static char Delimiter()
Get the delimiter that the current operating system uses to separate different paths from each other.
std::string FindFile(const std::string &_filename, const bool _searchLocalPath=true, const bool _verbose=true) const
Find a file in the set search paths (not recursive)
void AddPluginPaths(const std::string &_path)
Add colon (semicolon on windows) delimited paths to plugins.
A complete URI which has the following components:
Definition: gz/common/URI.hh:407
Functions to handle getting system paths, keeps track of:
Definition: gz/common/SystemPaths.hh:52
const std::list< std::string > & PluginPaths()
Get the plugin paths.
virtual ~SystemPaths()
Destructor.
std::string FindSharedLibrary(const std::string &_libName)
Find a shared library by name in the plugin paths.
void SetFilePathEnv(const std::string &_env)
Set the file path environment variable to use, and clears any previously set file paths....
SystemPaths()
Constructor for SystemPaths.
std::string FilePathEnv() const
Get the file path environment variable in use. The environment variable contains a set of colon (semi...
void ClearPluginPaths()
clear out SystemPaths::pluginPaths
void AddFindFileURICallback(std::function< std::string(const ignition::common::URI &)> _cb)
Add a callback to use when FindFileURI() can't find a file. The callback should return a full local p...
void AddSearchPathSuffix(const std::string &_suffix)
add _suffix to the list of path search suffixes
static std::string LocateLocalFile(const std::string &_filename, const std::vector< std::string > &_paths)
look for a file in a set of search paths (not recursive) \description This method checks if a file ex...
void SetPluginPathEnv(const std::string &_env)
Set the plugin path environment variable to use.
const std::list< std::string > & FilePaths()
Get the file paths.
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68
void ClearFilePaths()
clear out SystemPaths::filePaths