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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3082 - (hide annotations) (download) (as text)
Mon Jan 9 18:39:35 2017 UTC (7 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7120 byte(s)
* Added support for sfz extension opcode 'script' which may be used to
  load real-time instrument script file (NKSP script language).
* Removed code duplication in SFZ file loading code.
* Bumped version (2.0.0.svn37).

1 schoenebeck 1332 /***************************************************************************
2     * *
3 schoenebeck 3082 * Copyright (C) 2007-2017 Christian Schoenebeck *
4 schoenebeck 1332 * *
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 schoenebeck 2529 /**
48     * Default constructor.
49     */
50 schoenebeck 1471 Path();
51    
52 schoenebeck 1332 /**
53 schoenebeck 3082 * 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 schoenebeck 2529 */
62     Path(std::string path);
63    
64     /**
65 schoenebeck 1332 * 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 schoenebeck 1471 * 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 schoenebeck 3082 * 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 schoenebeck 1332 * Convert this Path into the correct encoding as expected by POSIX
90     * compliant system calls.
91 schoenebeck 3082 *
92     * @see toNativeFSPath()
93 schoenebeck 1332 */
94 schoenebeck 1471 std::string toPosix() const;
95 schoenebeck 1332
96     /**
97 iliev 1345 * Convert this Path into the correct encoding as expected
98     * by the instruments database implementation.
99     */
100 schoenebeck 1471 std::string toDbPath() const;
101 iliev 1345
102     /**
103 schoenebeck 1399 * Convert this Path into the correct encoding as expected and needed
104     * for LSCP responses.
105     */
106 schoenebeck 1471 std::string toLscp() const;
107 schoenebeck 1399
108     /**
109 schoenebeck 1471 * Convert this Path into the correct encoding as expected by Windows
110     * operating systems.
111 schoenebeck 3082 *
112     * @see toNativeFSPath()
113 schoenebeck 1471 */
114     std::string toWindows() const;
115    
116     /**
117 schoenebeck 1332 * 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 schoenebeck 1399 /**
127 schoenebeck 3082 * 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 schoenebeck 1399 * Create a Path object from a POSIX path / filename string.
137     */
138     static Path fromPosix(std::string path);
139    
140 iliev 1403 /**
141     * Create a Path object from a DB path.
142     */
143     static Path fromDbPath(std::string path);
144    
145 schoenebeck 1471 /**
146     * Create a Path object from a Windows path / filename string.
147     */
148 senoner 1481 static Path fromWindows(std::string path);
149 schoenebeck 1471
150 iliev 1782 /**
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 schoenebeck 3082 std::string getName() const;
156 iliev 1782
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 iliev 2012 * 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 iliev 1782 * Returns the last name in the path's name sequence
178     * of this path with the file extension stripped off.
179     */
180 schoenebeck 3082 std::string getBaseName() const;
181 iliev 1782
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 schoenebeck 2529 /**
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 schoenebeck 1332 private:
195     std::vector<std::string> elements; ///< stores the path names raw = unencoded, each element is one node of the path
196 schoenebeck 1471 char drive;
197 schoenebeck 2529 bool absolute;
198 schoenebeck 1332 };
199    
200     } // namespace LinuxSampler
201    
202     #endif // LS_PATH_H

  ViewVC Help
Powered by ViewVC