libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
path.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2012, 2014 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_PATH_HPP_
9 # define _QI_PATH_HPP_
10 
11 # include <memory>
12 # include <string>
13 # include <vector>
14 # include <locale>
15 # include <iosfwd>
16 # include <qi/api.hpp>
17 
18 namespace boost { namespace filesystem {
19  class path;
20 }}
21 
22 namespace qi
23 {
24 
25  class PrivatePath;
26  class Path;
27  using PathVector = std::vector<Path>;
28 
34  class QI_API Path {
35  public:
38  Path(const std::string& unicodePath = std::string());
39 
41  Path(const char* unicodePath);
42 
44  Path(const Path& path);
45 
47  Path(const boost::filesystem::path& path);
48 
50  ~Path();
51 
53  bool isEmpty() const;
54 
56  bool exists() const;
57 
59  bool isDir() const;
60 
62  bool isRegularFile() const;
63 
65  bool isSymlink() const;
66 
68  std::string filename() const;
69 
71  std::string extension() const;
72 
74  Path parent() const;
75 
77  Path absolute() const;
78 
80  PathVector files() const;
81 
83  PathVector recursiveFiles() const;
84 
86  PathVector dirs() const;
87 
89  explicit operator std::string() const;
90 
92  std::string str() const;
93 
95  operator boost::filesystem::path() const;
96 
98  const boost::filesystem::path& bfsPath() const;
99 
101  static Path fromNative(const char* nativeCharsPath);
102 
104  static Path fromNative(const wchar_t* nativeCharsPath);
105 
107  static Path fromNative(const std::string& nativeCharsPath);
108 
110  static Path fromNative(const std::wstring& nativeCharsPath);
111 
113  Path operator/(const qi::Path& rhs) const;
114 
116  const Path& operator/=(const qi::Path& rhs) const;
117 
119  const Path& operator=(const qi::Path& rhs) const;
120 
121  bool operator==(const qi::Path& rhs) const;
122  bool operator!=(const qi::Path& rhs) const;
123 
125  friend std::ostream& operator<<(std::ostream& output, const qi::Path& path)
126  {
127  output << path.str();
128  return output;
129  }
130 
131  private:
132  std::unique_ptr<PrivatePath> _p;
133  };
134 
135 
137  namespace path
138  {
142  {
143  public:
148  ScopedDir(qi::Path path = qi::Path());
150  ~ScopedDir();
151 
153  operator qi::Path() const;
154 
156  const qi::Path& path() const;
157 
158  private:
162  void removeAll(int retry);
163 
164  qi::Path _path;
165  };
166 
171  {
172  public:
178  ScopedFile(qi::Path filePath = qi::Path());
179  ~ScopedFile();
180 
182  const qi::Path& path() const;
183 
184  private:
185  qi::path::ScopedDir _dir;
186  qi::Path _path;
187  };
188 
194  QI_API std::string sdkPrefix();
195 
199  namespace detail {
200 
205  QI_API std::vector<std::string> getSdkPrefixes();
206 
217  QI_API void addOptionalSdkPrefix(const char* prefix);
218 
227 
233  QI_API void setWritablePath(const std::string &path);
234 
239  QI_API Path normalize(const Path& path);
240  }
241 
256  QI_API std::string findBin(const std::string& name, bool searchInPath=false);
257 
274  QI_API std::string findLib(const std::string& name);
275 
276 
300  QI_API std::string findConf(const std::string& applicationName,
301  const std::string& filename,
302  bool excludeUserWritablePath = false);
303 
332  QI_API std::string findData(const std::string& applicationName,
333  const std::string& filename,
334  bool excludeUserWritablePath = false);
335 
336 
369  QI_API std::vector<std::string> listData(const std::string& applicationName,
370  const std::string& pattern="*",
371  bool excludeUserWritablePath = false);
372 
375  QI_API std::vector<std::string> listLib(const std::string& subfolder,
376  const std::string& pattern="*");
377 
391  QI_API std::vector<std::string> confPaths(const std::string& applicationName="",
392  bool excludeUserWritablePath = false);
393 
417  QI_API std::vector<std::string> dataPaths(const std::string& applicationName="",
418  bool excludeUserWritablePath = false);
419 
431  QI_API std::vector<std::string> binPaths();
432 
444  QI_API std::vector<std::string> libPaths();
445 
465  QI_API std::string userWritableDataPath(const std::string& applicationName,
466  const std::string& filename);
467 
487  QI_API std::string userWritableConfPath(const std::string& applicationName,
488  const std::string& filename="");
489 
500  QI_API std::string convertToDosPath(const std::string &pathString);
501 
508  QI_API QI_API_DEPRECATED_MSG(Use 'detail::setWritablePath' instead)
509  void setWritablePath(const std::string &path);
510  }
511 
518  using codecvt_type = std::codecvt<wchar_t, char, std::mbstate_t>;
519 
530 }
531 
532 #endif // _QI_PATH_HPP_
std::vector< std::string > confPaths(const std::string &applicationName="", bool excludeUserWritablePath=false)
Get the list of directories used when searching for configuration files for the given application nam...
std::string findBin(const std::string &name, bool searchInPath=false)
Look for a binary.
codecvt_type & unicodeFacet()
UTF-8 facet object getter.
void setWritablePath(const std::string &path)
Set the writable files path for users.
std::vector< std::string > getSdkPrefixes()
Return the SDK prefixes list. It's always complete, native paths.
void addOptionalSdkPrefix(const char *prefix)
Add a new SDK prefix to the list of searchable prefixes.
#define QI_API
Definition: api.hpp:33
std::vector< std::string > listLib(const std::string &subfolder, const std::string &pattern="*")
std::vector< Path > PathVector
Definition: path.hpp:27
friend std::ostream & operator<<(std::ostream &output, const qi::Path &path)
Standard output stream operator for logging.
Definition: path.hpp:125
dll import/export and compiler message
std::string findConf(const std::string &applicationName, const std::string &filename, bool excludeUserWritablePath=false)
Look for a configuration file.
std::string findLib(const std::string &name)
Look for a library.
std::vector< std::string > libPaths()
Get the list of directories used when searching for libraries.
std::string str() const
std::vector< std::string > listData(const std::string &applicationName, const std::string &pattern="*", bool excludeUserWritablePath=false)
List data files matching the given pattern in all dataPaths(applicationName) directories. For each match, return the occurence from the first dataPaths prefix. Directories are discarded.
std::string convertToDosPath(const std::string &pathString)
Convert given path into DOS 8.3 path if it exists, else returns empty string (Windows only)...
bool operator==(const Signature &lhs, const Signature &rhs)
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:55
The Path class allow handling filesystem path in a cross-platform maner. <includename>qi/path.hpp</includename> The class assume that all string are encoded in UTF-8 if not specified otherwise.
Definition: path.hpp:34
Path normalize(const Path &path)
std::string userWritableDataPath(const std::string &applicationName, const std::string &filename)
Get the writable data files path for users.
std::vector< std::string > binPaths()
Get the list of directories used when searching for binaries.
std::string findData(const std::string &applicationName, const std::string &filename, bool excludeUserWritablePath=false)
Look for a file in all dataPaths(applicationName) directories, return the first match.
std::string sdkPrefix()
Return the default SDK prefix path.
std::string userWritableConfPath(const std::string &applicationName, const std::string &filename="")
Get the writable configuration files path for users.
std::vector< std::string > dataPaths(const std::string &applicationName="", bool excludeUserWritablePath=false)
Get the list of directories used when searching for data files for the given application name...
void clearOptionalSdkPrefix()
Reset the list of additional SDK prefixes.
std::codecvt< wchar_t, char, std::mbstate_t > codecvt_type
Standard std::codecvt type accepted by STL and boost.
Definition: path.hpp:518
bool operator!=(const Signature &lhs, const Signature &rhs)
Definition: signature.hpp:157