1 |
schoenebeck |
1332 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* Copyright (C) 2007 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 |
|
|
* Concatenate exactly one path node or filename to the end of this Path |
49 |
|
|
* object. This can be used to build up a full qualified path, directory |
50 |
|
|
* by directory. |
51 |
|
|
* |
52 |
|
|
* @param Name - name of the path node's name or filename in it's raw, |
53 |
|
|
* human readable/expected form |
54 |
|
|
*/ |
55 |
|
|
void appendNode(std::string Name); |
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* Convert this Path into the correct encoding as expected by POSIX |
59 |
|
|
* compliant system calls. |
60 |
|
|
*/ |
61 |
|
|
std::string toPosix(); |
62 |
|
|
|
63 |
|
|
/** |
64 |
iliev |
1345 |
* Convert this Path into the correct encoding as expected |
65 |
|
|
* by the instruments database implementation. |
66 |
|
|
*/ |
67 |
|
|
std::string toDbPath(); |
68 |
|
|
|
69 |
|
|
/** |
70 |
schoenebeck |
1399 |
* Convert this Path into the correct encoding as expected and needed |
71 |
|
|
* for LSCP responses. |
72 |
|
|
*/ |
73 |
|
|
std::string toLscp(); |
74 |
|
|
|
75 |
|
|
/** |
76 |
schoenebeck |
1332 |
* Concatenate two paths. |
77 |
|
|
*/ |
78 |
|
|
Path operator+(const Path& p); |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* Concatenate two paths. |
82 |
|
|
*/ |
83 |
|
|
Path operator+(const Path* p); |
84 |
|
|
|
85 |
schoenebeck |
1399 |
/** |
86 |
|
|
* Create a Path object from a POSIX path / filename string. |
87 |
|
|
*/ |
88 |
|
|
static Path fromPosix(std::string path); |
89 |
|
|
|
90 |
iliev |
1403 |
/** |
91 |
|
|
* Create a Path object from a DB path. |
92 |
|
|
*/ |
93 |
|
|
static Path fromDbPath(std::string path); |
94 |
|
|
|
95 |
schoenebeck |
1332 |
private: |
96 |
|
|
std::vector<std::string> elements; ///< stores the path names raw = unencoded, each element is one node of the path |
97 |
|
|
}; |
98 |
|
|
|
99 |
|
|
} // namespace LinuxSampler |
100 |
|
|
|
101 |
|
|
#endif // LS_PATH_H |