svn-gvsig-desktop / trunk / libraries / libjni-mrsid / include / support / lt_fileSpec.h @ 3539
History | View | Annotate | Download (6.44 KB)
1 |
/* $Id: lt_fileSpec.h 3539 2006-01-09 12:23:20Z nacho $ */
|
---|---|
2 |
/* //////////////////////////////////////////////////////////////////////////
|
3 |
// //
|
4 |
// This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue, //
|
5 |
// Suite 200, Seattle, WA 98104. Unauthorized use or distribution //
|
6 |
// prohibited. Access to and use of this code is permitted only under //
|
7 |
// license from LizardTech, Inc. Portions of the code are protected by //
|
8 |
// US and foreign patents and other filings. All Rights Reserved. //
|
9 |
// //
|
10 |
////////////////////////////////////////////////////////////////////////// */
|
11 |
/* PUBLIC */
|
12 |
|
13 |
#ifndef LT_FILESPEC_H
|
14 |
#define LT_FILESPEC_H
|
15 |
|
16 |
// lt_lib_base
|
17 |
#include "lt_base.h" |
18 |
|
19 |
#if defined(LT_OS_DARWIN)
|
20 |
#if defined(LT_OS_DARWIN6)
|
21 |
#include <wcstring.h> |
22 |
#endif
|
23 |
#elif defined (LT_OS_WIN32)
|
24 |
#include <wchar.h> |
25 |
#endif
|
26 |
|
27 |
#include <stddef.h> // for NULL |
28 |
|
29 |
#if defined(LT_COMPILER_MS)
|
30 |
#pragma warning(push,4) |
31 |
#endif
|
32 |
|
33 |
|
34 |
LT_BEGIN_NAMESPACE(LizardTech) |
35 |
|
36 |
|
37 |
/**
|
38 |
* Max length of a path
|
39 |
*/
|
40 |
#ifdef LT_OS_WIN
|
41 |
#define LT_UTIL_MAX_PATH _MAX_PATH
|
42 |
#else
|
43 |
#define LT_UTIL_MAX_PATH 2048 |
44 |
#endif
|
45 |
|
46 |
/**
|
47 |
* Represents a file or directory path
|
48 |
*/
|
49 |
class LTFileSpec |
50 |
{ |
51 |
public:
|
52 |
enum
|
53 |
{ |
54 |
fSlash = '/',
|
55 |
bSlash = '\\',
|
56 |
#ifdef LT_OS_WIN
|
57 |
platformSlash = '\\'
|
58 |
#else
|
59 |
platformSlash = '/'
|
60 |
#endif
|
61 |
}; |
62 |
|
63 |
|
64 |
public:
|
65 |
/**
|
66 |
* default constructor
|
67 |
*/
|
68 |
LTFileSpec(void);
|
69 |
|
70 |
/**
|
71 |
* destructor
|
72 |
*/
|
73 |
~LTFileSpec(void);
|
74 |
|
75 |
/**
|
76 |
* native constructor
|
77 |
*
|
78 |
* @param p1 first part of the path could be directory or filename
|
79 |
* @param p2 second part of the path could be directory or filename or NULL
|
80 |
* @param p3 last part of the path could be a filename or NULL
|
81 |
*
|
82 |
* @note On Win32 the file system treats a (char *) as a multibyte string
|
83 |
* On Unix/Linux the file system treats a (char *) as a utf8 string
|
84 |
*/
|
85 |
explicit LTFileSpec(const char *p1, const char *p2 = NULL, const char *p3 = NULL); |
86 |
|
87 |
/**
|
88 |
* wchar constructor
|
89 |
* @note See native constructor for arguments
|
90 |
* @note On Win32 wchar_t is a UTF16 string. On unix it is UTF32
|
91 |
*/
|
92 |
explicit LTFileSpec(const wchar_t *p1, const wchar_t *p2 = NULL, const wchar_t *p3 = NULL); |
93 |
|
94 |
/*@{*/
|
95 |
/**
|
96 |
* LTFileSpec constructor
|
97 |
* @note See native constructor for arguments
|
98 |
* @note See above for notes on (char *) and (wchar_t *) types
|
99 |
*/
|
100 |
LTFileSpec(const LTFileSpec ©);
|
101 |
LTFileSpec(const LTFileSpec &p1, const char *p2, const char *p3 = NULL); |
102 |
LTFileSpec(const LTFileSpec &p1, const wchar_t *p2, const wchar_t *p3 = NULL); |
103 |
|
104 |
LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2, const char *p3 = NULL); |
105 |
LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2, const wchar_t *p3); |
106 |
|
107 |
LTFileSpec(const LTFileSpec &p1, const LTFileSpec &p2, const LTFileSpec &p3); |
108 |
/*@}*/
|
109 |
|
110 |
/**
|
111 |
* assignment operator
|
112 |
*/
|
113 |
LTFileSpec& operator=(const LTFileSpec& copy);
|
114 |
|
115 |
/**
|
116 |
* inequality operator
|
117 |
*/
|
118 |
bool operator!=(const LTFileSpec& fs) const; |
119 |
|
120 |
/**
|
121 |
* equality operator
|
122 |
*/
|
123 |
bool operator==(const LTFileSpec& fs) const; |
124 |
|
125 |
/**
|
126 |
* Initialization from Native strings
|
127 |
*
|
128 |
* See Native contructor for arguments
|
129 |
*/
|
130 |
void set(const char *p1, const char *p2 = NULL, const char *p3 = NULL); |
131 |
|
132 |
/**
|
133 |
* Initialization from UTF8 strings
|
134 |
*
|
135 |
* See Native contructor for arguments
|
136 |
*/
|
137 |
void setUTF8(const lt_utf8 *p1, const lt_utf8 *p2 = NULL, const lt_utf8 *p3 = NULL); |
138 |
|
139 |
/**
|
140 |
* Initialization from Wide strings
|
141 |
*
|
142 |
* See Native contructor for arguments
|
143 |
*/
|
144 |
void setWide(const wchar_t *p1, const wchar_t *p2 = NULL, const wchar_t *p3 = NULL); |
145 |
|
146 |
/**
|
147 |
* Return the parent directory
|
148 |
*
|
149 |
* The semantics are similar to the standard Unix dirname.
|
150 |
*
|
151 |
* Examples:
|
152 |
* - "/usr/lib" -> "/usr"
|
153 |
* - "/usr/" -> "/"
|
154 |
* - "usr" -> "."
|
155 |
* - "/" -> "/"
|
156 |
* - "C:/" -> "C:/"
|
157 |
* - "." -> "."
|
158 |
* - ".." -> "."
|
159 |
*/
|
160 |
LTFileSpec dirname(void) const; |
161 |
|
162 |
/**
|
163 |
* Return the base filename
|
164 |
*
|
165 |
* The semantics are similar to the standard Unix basename.
|
166 |
*
|
167 |
* Examples:
|
168 |
* - "/usr/lib" -> "lib"
|
169 |
* - "/usr/" -> "usr/" (not the same as the unix basename)
|
170 |
* - "usr" -> "usr"
|
171 |
* - "/" -> "/"
|
172 |
* - "C:/" -> "C:/"
|
173 |
* - "." -> "."
|
174 |
* - ".." -> ".."
|
175 |
*/
|
176 |
const lt_utf8 *basename(void) const; |
177 |
|
178 |
/**
|
179 |
* Function to convert the path to native format.
|
180 |
*
|
181 |
* @note On Win32 this returns a multi-byte string.
|
182 |
* @note On Unix this returns a UTF8 string.
|
183 |
*/
|
184 |
const char *n_str(void) const; |
185 |
|
186 |
/* DEPRECATED */
|
187 |
const char *c_str(void) const; |
188 |
|
189 |
/**
|
190 |
* Function to convert the path to Wide format.
|
191 |
*
|
192 |
* @note On Win32 this returns a 16bit UTF16 string.
|
193 |
* @note On Unix this returns a 32bit UTF32 string.
|
194 |
*/
|
195 |
const wchar_t *w_str(void) const; |
196 |
|
197 |
/**
|
198 |
* Function to convert the path to a UTF8 format.
|
199 |
*
|
200 |
* @note On Win32 this returns a 16bit UTF16 string.
|
201 |
* @note On Unix this returns a 32bit UTF32 string.
|
202 |
*/
|
203 |
const lt_utf8* utf8(void) const { return m_path8; } |
204 |
|
205 |
/**
|
206 |
* returns suffix (in utf8)
|
207 |
*
|
208 |
* Examples:
|
209 |
* - "foo.bar" -> "bar"
|
210 |
* - "foo." -> ""
|
211 |
* - "foo" -> ""
|
212 |
*/
|
213 |
const lt_utf8* getSuffix() const; |
214 |
|
215 |
/**
|
216 |
* replaces suffix (extension)
|
217 |
*
|
218 |
* Note that \a ext should not include the ".".
|
219 |
* If \a ext is null, the suffix is removed.
|
220 |
*
|
221 |
* Examples:
|
222 |
* - "foo.bar" with "baz" -> "foo.baz"
|
223 |
* - "foo.bar" with ".baz" -> "foo..baz"
|
224 |
* - "foo.bar" with "" -> "foo."
|
225 |
* - "foo" with "baz" -> "foo.baz"
|
226 |
*/
|
227 |
void replaceSuffix(const lt_utf8* ext); |
228 |
|
229 |
/**
|
230 |
* remove the suffix (extension)
|
231 |
*
|
232 |
* Note this also removes the ".".
|
233 |
*
|
234 |
* Examples:
|
235 |
* - "foo.bar" -> "foo"
|
236 |
* - "foo." -> "foo"
|
237 |
* - "foo" -> "foo"
|
238 |
*/
|
239 |
void removeSuffix();
|
240 |
|
241 |
/**
|
242 |
* returns true if path is absolute, false if relative
|
243 |
*/
|
244 |
bool absolute() const; |
245 |
|
246 |
protected:
|
247 |
|
248 |
private:
|
249 |
// using a utf8 string to hold the path because it is the easiest
|
250 |
// to play with (we can look for bSlashs and not have to worry
|
251 |
// about lead btyes.
|
252 |
lt_utf8 *m_path8; |
253 |
|
254 |
mutable char *m_pathA; // this will be updated in n_str() |
255 |
mutable wchar_t *m_pathW; // this will be updated in w_str()
|
256 |
}; |
257 |
|
258 |
|
259 |
LT_END_NAMESPACE(LizardTech) |
260 |
|
261 |
#if defined(LT_COMPILER_MS)
|
262 |
#pragma warning(pop)
|
263 |
#endif
|
264 |
|
265 |
#endif // LT_FILESPEC_H |