libqi-api  2.4.3.28
 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 <string>
12 # include <vector>
13 # include <locale>
14 # include <iosfwd>
15 # include <boost/scoped_ptr.hpp>
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  typedef std::vector<Path> PathVector;
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  operator std::string() const;
90 
92  std::string str() const;
93 
95  const boost::filesystem::path& bfsPath() const;
96 
98  Path operator/(const qi::Path& rhs) const;
99 
101  const Path& operator/=(const qi::Path& rhs) const;
102 
104  const Path& operator=(const qi::Path& rhs) const;
105 
107  friend std::ostream& operator<<(std::ostream& output, const qi::Path& path)
108  {
109  output << path.str();
110  return output;
111  }
112 
113  private:
114  Path(PrivatePath* p);
115  boost::scoped_ptr<PrivatePath> _p;
116  };
117 
118 
120  namespace path
121  {
125  {
126  public:
131  ScopedDir(qi::Path path = qi::Path());
133  ~ScopedDir();
134 
136  operator qi::Path() const;
137 
139  const qi::Path& path() const;
140 
141  private:
145  void removeAll(int retry);
146 
147  qi::Path _path;
148  };
149 
154  {
155  public:
161  ScopedFile(qi::Path filePath = qi::Path());
162  ~ScopedFile();
163 
165  const qi::Path& path() const;
166 
167  private:
168  qi::path::ScopedDir _dir;
169  qi::Path _path;
170  };
171 
177  QI_API std::string sdkPrefix();
178 
182  namespace detail {
183 
188  QI_API std::vector<std::string> getSdkPrefixes();
189 
200  QI_API void addOptionalSdkPrefix(const char* prefix);
201 
210 
216  QI_API void setWritablePath(const std::string &path);
217  }
218 
233  QI_API std::string findBin(const std::string& name, bool searchInPath=false);
234 
251  QI_API std::string findLib(const std::string& name);
252 
253 
276  QI_API std::string findConf(const std::string& applicationName,
277  const std::string& filename);
278 
304  QI_API std::string findData(const std::string& applicationName,
305  const std::string& filename,
306  bool excludeUserWritablePath = false);
307 
308 
341  QI_API std::vector<std::string> listData(const std::string& applicationName,
342  const std::string& pattern="*",
343  bool excludeUserWritablePath = false);
344 
347  QI_API std::vector<std::string> listLib(const std::string& subfolder,
348  const std::string& pattern="*");
349 
362  QI_API std::vector<std::string> confPaths(const std::string& applicationName="");
363 
385  QI_API std::vector<std::string> dataPaths(const std::string& applicationName="",
386  bool excludeUserWritablePath = false);
387 
399  QI_API std::vector<std::string> binPaths();
400 
412  QI_API std::vector<std::string> libPaths();
413 
433  QI_API std::string userWritableDataPath(const std::string& applicationName,
434  const std::string& filename);
435 
455  QI_API std::string userWritableConfPath(const std::string& applicationName,
456  const std::string& filename="");
457 
468  QI_API std::string convertToDosPath(const std::string &pathString);
469 
476  QI_API QI_API_DEPRECATED void setWritablePath(const std::string &path);
477  }
478 
485  typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type;
486 
497 }
498 
499 #endif // _QI_PATH_HPP_
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.
std::codecvt< wchar_t, char, std::mbstate_t > codecvt_type
Standard std::codecvt type accepted by STL and boost.
Definition: path.hpp:485
std::vector< std::string > confPaths(const std::string &applicationName="")
Get the list of directories used when searching for configuration files for the given application nam...
#define QI_API
Definition: api.hpp:34
std::vector< std::string > listLib(const std::string &subfolder, const std::string &pattern="*")
QI_API_DEPRECATED void setWritablePath(const std::string &path)
Set the writable files path for users.
friend std::ostream & operator<<(std::ostream &output, const qi::Path &path)
Standard output stream operator for logging.
Definition: path.hpp:107
dll import/export and compiler message
std::string findConf(const std::string &applicationName, const std::string &filename)
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
return the path as a string
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)...
std::vector< Path > PathVector
Definition: path.hpp:26
The Path class allow handling path in a cross-platform maner. <includename>qi/path.hpp</includename> The class assume that all string are encoded in UTF-8.
Definition: path.hpp:34
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...
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:39
void clearOptionalSdkPrefix()
Reset the list of additional SDK prefixes.