OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
filename.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5//----------------------------------------------------------------------------
6#if !defined(OWL_FILENAME_H)
7#define OWL_FILENAME_H
8
9#include <owl/private/defs.h>
10#if defined(BI_HAS_PRAGMA_ONCE)
11# pragma once
12#endif
13
14#include <owl/file.h>
15
16#include <owl/private/dir.h> // struct ffblk
17
18namespace owl {
19
20#include <owl/preclass.h>
21
22// Copied from old owl (04-16-01 JAM)
23#ifdef UNIX
24#include <owl/system.h>
25#endif
26
27//#include <string>
28//using std::string;
29
30struct TFileStatus;
31
32//
33/// \class TFileName
34// ~~~~~ ~~~~~~~~~
35/// The TFileName class constructs filenames.
36//
38 protected:
39 void Parse(LPCTSTR freeform, bool pathOnly = false);
40
41/// Holds the server filename part.
43
44/// Holds the device filename part.
46
47/// Holds the path filename part.
48 mutable tstring PathStr; //had to do this to make Squeezed function const
49
50/// Holds the file filename part (no extension).
52
53/// Holds the extension filename part.
55
57 mutable tchar NameBuffer[_MAX_PATH];
58
59/// true if UNC naming convention in use; false otherwise.
60 bool Unc;
61
62 public:
63 // Construct an empty filename
64 //
65 TFileName();
66
67 // Construct a filename from its parts. OK to pass 0 to skip part
68 //
71
72 // Construct a filename from a freeform string
73 //
74 TFileName(LPCTSTR freeform, bool pathOnly = false);
75 TFileName(const tstring& freeform, bool pathOnly = false);
76
77 // Construct a filename from another filename
78 //
79 TFileName(const TFileName& src);
80
81 //virtual ~TFileName(){} ??
82
83 // Assign new filename or freeform to this name
84 //
88
89 /// Construct a filename representing a special file or directory
90 //
92 TempFile, ///< A temporary filename
93 TempDir, ///< Location of temporary files
94 CurrentDir, ///< Current working directory if any
95 BootDir, ///< Root dir of boot device (LDID_BOOT)
96 MachineDir, ///< (LDID_MACHINE) currently not implemented?
97 HomeDir, ///< Home directory for OS (LDID_WIN)
98 SharedDir, ///< Shared home directory for OS (LDID_SHARED) currently not implemented?
99 SysDir, ///< Location of system files (LDID_SYS)
101 };
102 TFileName(TSpecialType type);
103
104 // Normal fully qualified path string, & short filename version of it
105 // Convert a possibly logical drive based name to a UNC name if indicated
106 //
107 //PERL API USE ONLY
108 tchar* GetNameNoExt();
109 tchar* GetNameAndExt() const;
110 tchar* GetFullFileName();
111 tchar* GetFullFileNameNoExt();
112
113 void FormCanonicalName();
114 const tstring& Canonical(bool forceUNC = false) const;
115 const tchar* CanonicalStr(bool forceUNC = false) const;
116 const tchar* ShortName(bool forceUNC = false) const;
117
118 const tchar* Title() const;
119
120 const tchar* Squeezed(int maxLen, bool keepName = true) const;
121
122 /// Obtain any combination of various filename parts. Seperators inserted
123 /// only as appropriate
124 //
125 enum TPart {
126 Server = 1, ///< Server name
127 Device = 2, ///< Logical device or sharename
128 Path = 4, ///< Directory path to the file
129 File = 8, ///< Filename part without the extension
130 Ext =16, ///< Extension
131 };
132 const tchar* GetParts(uint p) const; // Return assembled string of parts
133 bool HasParts(uint p) const; // Does name have an given part
134 TFileName& SetPart(uint p, const tstring& partStr); // Modify sub part
135 TFileName& MergeParts(uint p, const TFileName& source); // Modify sub parts
136 TFileName& StripParts(uint p); // Remove indicated parts
137 TFileName& AddSubDir(const tstring& subdir);
138
139 // Information about the filename
140 //
141 bool IsValid() const; // Is a valid name of any kind
142 bool IsUNC() const; // Is UNC vs logical drive based name
143 bool Exists() const; // Does device/dir/file exist?
144
145 // Is another filename equivalent to this filename?
146 //
147 bool operator ==(const TFileName& other) const;
148
149 // Remove the file or dir associated with this filename.
150 //
151 bool Remove() const;
152
153 enum { ReplaceExisting=1, CopyAllowed=2, DelayUntilReboot=4 };
154 // Move (rename) the file associated with this filename, and change this
155 // name to the new name
156 //
157 bool Move(const TFileName& newName, uint32 how = CopyAllowed);
158
159 // Copy the file associated with this filename to a new file
160 //
161 bool Copy(const TFileName& newName, bool failIfExists) const;
162
163 int ChangeDir() const;
164 int CreateDir() const;
165
166 // Get and Set the file status struct for the item associated with this
167 // filename
168 //
169 int GetStatus(TFileStatus& status) const;
170 int SetStatus(const TFileStatus& status);
171
172 // Other ideas...
173 //
174 static LPCTSTR WildName() {return _T("*");} ///< General wildstring
175 static LPCTSTR WildPart(uint /*p*/) {return _T("*");} ///< Part specific?
176
177 // ***********************************************************************************
178 // (JAM 03-12-01) Added GetNameAndExt for compliance with old code
179
180};
181
182//
183/// \class TFileNameIterator
184// ~~~~~ ~~~~~~~~~~~~~~~~~
185/// TFileNameIterator is used to iterate through a list of file names.
186//
188 public:
190 virtual ~TFileNameIterator();
191
192 operator const TFileStatus&() const;
193 const TFileStatus& operator *() const;
194 operator const tchar*() const;
195 const TFileStatus& operator ++();
196 const TFileStatus& Current() const;
197
198 bool IsDir() const;
199 bool IsSysDir() const;///< true if it is the "." or ".." system directory;
200 unsigned long GetAttributes() const { return Status.attribute; }
201 protected:
203 /// all work do here -> must fill TFileStatus structure return true on success
204 virtual bool FindNext(TFileStatus& status, void* findData);
205
206 protected:
207/// Set false in the constructor. Set true if the last attempt to find a file
208/// failed.
209 bool Done;
210
211/// Under Win32 a pointer to a WIN32_FIND_DATA structure.
212 void* Data;
213
214/// Status of last attempt to find a file. See TFileStatus structure
216};
217
218#include <owl/posclass.h>
219
220
221//----------------------------------------------------------------------------
222// Inlines
223//
224
225/// Assigns new filename or freeform to this name.
227{
228 Parse(src.c_str());
229 return *this;
230}
231
232/// Assigns new filename or freeform to this name.
234{
235 Parse(src);
236 return *this;
237}
238
239/// Returns true if this filename is canonically equal to other
240inline bool TFileName::operator ==(const TFileName& other) const
241{
242 return _tcsicmp(CanonicalStr(), other.CanonicalStr()) == 0;
243}
244
245/// Determines whether the name is UNC format as opposed to a logical-drive based
246/// machine.
247inline bool TFileName::IsUNC() const
248{
249 return Unc;
250}
251
252inline const tchar* TFileName::CanonicalStr(bool forceUNC) const
253{
254 return Canonical(forceUNC).c_str();
255}
256
257//
258/// Returns a reference to the Status member indicating the results of the last
259/// operation. See TFileStatus structure.
260/// For example:
261/// \code
262/// TFileNameIterator iterator("file?.exe");
263///
264/// while(iterator)
265/// {
266/// TFileStatus& status = iterator;
267/// //do something
268/// ++iterator;
269/// }
270/// \endcode
271//
272inline TFileNameIterator::operator const TFileStatus&() const
273{
274 return Status;
275}
276//
277/// Returns the full name if the last operator was sucessful; otherwise it returns 0.
278//
279inline TFileNameIterator::operator const tchar*() const
280{
281 return Done ? nullptr : Status.fullName;
282}
283//
284/// Dereference operator returns a reference to the Status member indicating the
285/// results of the last operation. Similar to STL form. See TFileStatus structure.
286/// For example:
287/// \code
288/// TFileNameIterator iterator("file?.exe");
289///
290/// while(iterator)
291/// {
292/// TFileStatus& status = *iterator;
293/// //do something
294/// ++iterator;
295/// }
296/// \endcode
297//
299{
300 return Status;
301}
302//
303/// Returns a reference to the Status member indicating the results of the last
304/// operation. See TFileStatus structure
305//
307{
308 return Status;
309}
310//
311/// Attempts to find the next file. Returns a reference to the Status member. See
312/// TFileStatus structure.
313/// For example:
314/// \code
315/// TFileNameIterator iterator("file?.exe");
316///
317/// while(iterator)
318/// {
319/// TFileStatus& status = *iterator;
320/// //do something
321/// ++iterator;
322/// }
323/// \endcode
324//
326{
327 if(!FindNext(Status, Data))
328 Done = true;
329 return Status;
330}
331
332inline bool TFileNameIterator::IsDir() const
333{
335}
336
337//Returns true if it is a directory & the directory is "." or "..";
339{
341 return IsDir() && p[0] == _T('.') &&
342 (
343 p[1] == _T('\0') || // "."
344 (p[1] == _T('.') && p[2] == _T('\0')) // ".."
345 );
346}
347
348} // OWL namespace
349
350
351#endif // OWL_FILENAME_H
The TFileName class constructs filenames.
Definition filename.h:37
const tchar * CanonicalStr(bool forceUNC=false) const
Definition filename.h:252
tstring DeviceStr
Holds the device filename part.
Definition filename.h:45
TPart
Obtain any combination of various filename parts.
Definition filename.h:125
tstring ServerStr
Holds the server filename part.
Definition filename.h:42
const tstring & Canonical(bool forceUNC=false) const
Return normal fully qualified path string.
Definition filename.cpp:520
void Parse(LPCTSTR freeform, bool pathOnly=false)
Parses the freeform string into the filename parts.
Definition filename.cpp:283
bool operator==(const TFileName &other) const
Returns true if this filename is canonically equal to other.
Definition filename.h:240
tstring ExtStr
Holds the extension filename part.
Definition filename.h:54
bool Unc
true if UNC naming convention in use; false otherwise.
Definition filename.h:60
static LPCTSTR WildName()
General wildstring.
Definition filename.h:174
TFileName & operator=(const TFileName &src)
Assigns new filename or freeform to this name.
Definition filename.cpp:451
bool IsUNC() const
Determines whether the name is UNC format as opposed to a logical-drive based machine.
Definition filename.h:247
static LPCTSTR WildPart(uint)
Part specific?
Definition filename.h:175
tstring FileStr
Holds the file filename part (no extension).
Definition filename.h:51
tstring PathStr
Holds the path filename part.
Definition filename.h:48
TSpecialType
Construct a filename representing a special file or directory.
Definition filename.h:91
@ SysDir
Location of system files (LDID_SYS)
Definition filename.h:99
@ MachineDir
(LDID_MACHINE) currently not implemented?
Definition filename.h:96
@ SharedDir
Shared home directory for OS (LDID_SHARED) currently not implemented?
Definition filename.h:98
@ BootDir
Root dir of boot device (LDID_BOOT)
Definition filename.h:95
@ TempDir
Location of temporary files.
Definition filename.h:93
@ CurrentDir
Current working directory if any.
Definition filename.h:94
@ HomeDir
Home directory for OS (LDID_WIN)
Definition filename.h:97
@ TempFile
A temporary filename.
Definition filename.h:92
tstring FullCanonicalName
Definition filename.h:56
TFileNameIterator is used to iterate through a list of file names.
Definition filename.h:187
const TFileStatus & Current() const
Returns a reference to the Status member indicating the results of the last operation.
Definition filename.h:306
TFileStatus Status
Status of last attempt to find a file. See TFileStatus structure.
Definition filename.h:215
unsigned long GetAttributes() const
Definition filename.h:200
const TFileStatus & operator++()
Attempts to find the next file.
Definition filename.h:325
bool IsDir() const
Definition filename.h:332
void * Data
Under Win32 a pointer to a WIN32_FIND_DATA structure.
Definition filename.h:212
const TFileStatus & operator*() const
Dereference operator returns a reference to the Status member indicating the results of the last oper...
Definition filename.h:298
virtual bool FindNext(TFileStatus &status, void *findData)
all work do here -> must fill TFileStatus structure return true on success
bool Done
Set false in the constructor.
Definition filename.h:209
bool IsSysDir() const
true if it is the "." or ".." system directory;
Definition filename.h:338
#define _MAX_PATH
Definition cygwin.h:97
#define _tcsicmp
Definition cygwin.h:76
#define _T(x)
Definition cygwin.h:51
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define _OWLCLASS
Definition defs.h:338
tchar fullName[_MAX_PATH]
Definition file.h:41
uint attribute
Definition file.h:40
Definition of TSystem, a system information provider class.