/[svn]/linuxsampler/trunk/src/common/Path.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/common/Path.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3091 - (show annotations) (download) (as text)
Mon Jan 16 15:01:21 2017 UTC (7 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7160 byte(s)
* Cleanup of instruments DB file creation and opening code.
* The instrument DB path of linuxsampler's --create-instruments-db argument
  is now optional, if it is missing, then a default location is used.
* Bumped version (2.0.0.svn39).

1 /***************************************************************************
2 * *
3 * Copyright (C) 2007-2017 Christian Schoenebeck *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this library; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #ifndef LS_PATH_H
22 #define LS_PATH_H
23
24 #include <vector>
25 #include <string>
26
27 namespace LinuxSampler {
28
29 /** @brief Portable Path Abstraction
30 *
31 * Correct path and file names are dependent to the underlying OS and FS.
32 * Especially the set of forbidden characters (and their encodings / escape
33 * sequences) in path and file names differ on the various systems. This
34 * class is meant as a portable wrapper to circumvent these problems by
35 * storing the file names in its raw, human readable (intended) form and
36 * provides OS specific methods like @c toPosix() for converting the path into
37 * the correct encoding, as expected by the respective system.
38 *
39 * This class is currently only used internally by the LSCP parser. A lot
40 * generalization work would have to be done to use this class as a overall
41 * replacement for all @c char* / @c std::string file name arguments in the
42 * sampler or even its C++ API. Probably we'll use something like
43 * @c boost::filesystem::path instead of this class in future.
44 */
45 class Path {
46 public:
47 /**
48 * Default constructor.
49 */
50 Path();
51
52 /**
53 * Creates a Path object according to the local system's path conventions.
54 * That means to construct this Path object it uses fromPosix() on POSIX
55 * compliant systems (i.e. Linux, Mac) and fromWindows() on Windows systems.
56 *
57 * If you have no information in which file system encoding the path string
58 * was encoded as, then rather use fromUnknownFS() instead.
59 *
60 * @see fromUnknownFS(), fromPosix(), fromWindows(), fromDbPath()
61 */
62 Path(std::string path);
63
64 /**
65 * Concatenate exactly one path node or filename to the end of this Path
66 * object. This can be used to build up a full qualified path, directory
67 * by directory.
68 *
69 * @param Name - name of the path node's name or filename in it's raw,
70 * human readable/expected form
71 */
72 void appendNode(std::string Name);
73
74 /**
75 * Sets the hardware drive of the path, for systems that use the concept
76 * of drives in absolute pathes (i.e. Windows).
77 */
78 void setDrive(const char& Drive);
79
80 /**
81 * Returns file system path of this Path object as String in correct
82 * encoding as expected by the local file system calls. Essentially that
83 * means this software returns toWindows() on Windows systems, toPosix()
84 * on POSIX compliant systems like Linux and Mac.
85 */
86 std::string toNativeFSPath() const;
87
88 /**
89 * Convert this Path into the correct encoding as expected by POSIX
90 * compliant system calls.
91 *
92 * @see toNativeFSPath()
93 */
94 std::string toPosix() const;
95
96 /**
97 * Convert this Path into the correct encoding as expected
98 * by the instruments database implementation.
99 */
100 std::string toDbPath() const;
101
102 /**
103 * Convert this Path into the correct encoding as expected and needed
104 * for LSCP responses.
105 */
106 std::string toLscp() const;
107
108 /**
109 * Convert this Path into the correct encoding as expected by Windows
110 * operating systems.
111 *
112 * @see toNativeFSPath()
113 */
114 std::string toWindows() const;
115
116 /**
117 * Concatenate two paths.
118 */
119 Path operator+(const Path& p);
120
121 /**
122 * Concatenate two paths.
123 */
124 Path operator+(const Path* p);
125
126 /**
127 * Attempts to auto detect the file system the supplied filename string
128 * was encoded for, and then creates and returns a corresponding Path
129 * object. This method only auto detects file system encodings of Windows
130 * and POSIX (i.e. Linux and Mac). This method does @b NOT detect any other
131 * encodings like DB path for example.
132 */
133 static Path fromUnknownFS(std::string path);
134
135 /**
136 * Create a Path object from a POSIX path / filename string.
137 */
138 static Path fromPosix(std::string path);
139
140 /**
141 * Create a Path object from a DB path.
142 */
143 static Path fromDbPath(std::string path);
144
145 /**
146 * Create a Path object from a Windows path / filename string.
147 */
148 static Path fromWindows(std::string path);
149
150 /**
151 * Returns the name of the file or directory represented by
152 * this path in abstract/raw form. This is the last name in
153 * the path's name sequence.
154 */
155 std::string getName() const;
156
157 /**
158 * Returns the name of the file or directory
159 * represented by the specified path in abstract/raw form.
160 * This is the last name in the path's name sequence.
161 */
162 static std::string getName(std::string path);
163
164 /**
165 * Returns the path with the last name
166 * of the path's name sequence stripped off.
167 */
168 std::string stripLastName();
169
170 /**
171 * Returns the path with the last name
172 * of the path's name sequence stripped off.
173 */
174 static std::string stripLastName(std::string path);
175
176 /**
177 * Returns the last name in the path's name sequence
178 * of this path with the file extension stripped off.
179 */
180 std::string getBaseName() const;
181
182 /**
183 * Returns the last name in the path's name sequence
184 * of the specified path with the file extension stripped off.
185 */
186 static std::string getBaseName(std::string path);
187
188 /**
189 * Returns true if the path is reflecting an absolute path, false if it is
190 * rather a relative path.
191 */
192 bool isAbsolute() const;
193
194 std::vector<std::string>& nodes();
195
196 private:
197 std::vector<std::string> elements; ///< stores the path names raw = unencoded, each element is one node of the path
198 char drive;
199 bool absolute;
200 };
201
202 } // namespace LinuxSampler
203
204 #endif // LS_PATH_H

  ViewVC Help
Powered by ViewVC