source: XMLIO_V2/external/src/POCO/Foundation.save/File.cpp @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 5.5 KB
Line 
1//
2// File.cpp
3//
4// $Id: //poco/1.3/Foundation/src/File.cpp#6 $
5//
6// Library: Foundation
7// Package: Filesystem
8// Module:  File
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// Permission is hereby granted, free of charge, to any person or organization
14// obtaining a copy of the software and accompanying documentation covered by
15// this license (the "Software") to use, reproduce, display, distribute,
16// execute, and transmit the Software, and to prepare derivative works of the
17// Software, and to permit third-parties to whom the Software is furnished to
18// do so, all subject to the following:
19//
20// The copyright notices in the Software and this entire statement, including
21// the above license grant, this restriction and the following disclaimer,
22// must be included in all copies of the Software, in whole or in part, and
23// all derivative works of the Software, unless such copies or derivative
24// works are solely in the form of machine-executable object code generated by
25// a source language processor.
26//
27// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
30// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
31// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
32// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33// DEALINGS IN THE SOFTWARE.
34//
35
36
37#include "Poco/File.h"
38#include "Poco/Path.h"
39#include "Poco/DirectoryIterator.h"
40
41
42#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
43#include "File_WIN32U.cpp"
44#elif defined(POCO_OS_FAMILY_WINDOWS)
45#include "File_WIN32.cpp"
46#elif defined(POCO_OS_FAMILY_UNIX)
47#include "File_UNIX.cpp"
48#else
49#include "File_VMS.cpp"
50#endif
51
52
53namespace Poco {
54
55
56File::File()
57{
58}
59
60
61File::File(const std::string& path): FileImpl(path)
62{
63}
64
65
66File::File(const char* path): FileImpl(std::string(path))
67{
68}
69
70
71File::File(const Path& path): FileImpl(path.toString())
72{
73}
74
75
76File::File(const File& file): FileImpl(file.getPathImpl())
77{
78}
79
80
81File::~File()
82{
83}
84
85
86File& File::operator = (const File& file)
87{
88        setPathImpl(file.getPathImpl());
89        return *this;
90}
91
92
93File& File::operator = (const std::string& path)
94{
95        setPathImpl(path);
96        return *this;
97}
98
99
100File& File::operator = (const char* path)
101{
102        poco_check_ptr (path);
103        setPathImpl(path);
104        return *this;
105}
106
107
108File& File::operator = (const Path& path)
109{
110        setPathImpl(path.toString());
111        return *this;
112}
113
114
115void File::swap(File& file)
116{
117        swapImpl(file);
118}
119
120
121bool File::exists() const
122{
123        return existsImpl();
124}
125
126       
127bool File::canRead() const
128{
129        return canReadImpl();
130}
131
132       
133bool File::canWrite() const
134{
135        return canWriteImpl();
136}
137
138
139bool File::canExecute() const
140{
141        return canExecuteImpl();
142}
143
144
145bool File::isFile() const
146{
147        return isFileImpl();
148}
149
150       
151bool File::isDirectory() const
152{
153        return isDirectoryImpl();
154}
155
156
157bool File::isLink() const
158{
159        return isLinkImpl();
160}
161
162
163bool File::isDevice() const
164{
165        return isDeviceImpl();
166}
167
168
169bool File::isHidden() const
170{
171        return isHiddenImpl();
172}
173
174
175Timestamp File::created() const
176{
177        return createdImpl();
178}
179
180       
181Timestamp File::getLastModified() const
182{
183        return getLastModifiedImpl();
184}
185
186       
187void File::setLastModified(const Timestamp& ts)
188{
189        setLastModifiedImpl(ts);
190}
191
192       
193File::FileSize File::getSize() const
194{
195        return getSizeImpl();
196}
197
198       
199void File::setSize(FileSizeImpl size)
200{
201        setSizeImpl(size);
202}
203
204       
205void File::setWriteable(bool flag)
206{
207        setWriteableImpl(flag);
208}
209
210
211void File::setReadOnly(bool flag)
212{
213        setWriteableImpl(!flag);
214}
215
216
217void File::setExecutable(bool flag)
218{
219        setExecutableImpl(flag);
220}
221
222       
223void File::copyTo(const std::string& path) const
224{
225        Path src(getPathImpl());
226        Path dest(path);
227        File destFile(path);
228        if ((destFile.exists() && destFile.isDirectory()) || dest.isDirectory())
229        {
230                dest.makeDirectory();
231                dest.setFileName(src.getFileName());
232        }
233        if (isDirectory())
234                copyDirectory(dest.toString());
235        else
236                copyToImpl(dest.toString());
237}
238
239
240void File::copyDirectory(const std::string& path) const
241{
242        File target(path);
243        target.createDirectories();
244
245        Path src(getPathImpl());
246        src.makeFile();
247        DirectoryIterator it(src);
248        DirectoryIterator end;
249        for (; it != end; ++it)
250        {
251                it->copyTo(path);
252        }
253}
254
255
256void File::moveTo(const std::string& path)
257{
258        copyTo(path);
259        remove(true);
260        setPathImpl(path);
261}
262
263       
264void File::renameTo(const std::string& path)
265{
266        renameToImpl(path);
267        setPathImpl(path);
268}
269
270       
271void File::remove(bool recursive)
272{
273        if (recursive && !isLink() && isDirectory())
274        {
275                std::vector<File> files;
276                list(files);
277                for (std::vector<File>::iterator it = files.begin(); it != files.end(); ++it)
278                {
279                        it->remove(true);
280                }
281        }
282        removeImpl();
283}
284
285
286bool File::createFile()
287{
288        return createFileImpl();
289}
290
291
292bool File::createDirectory()
293{
294        return createDirectoryImpl();
295}
296
297
298void File::createDirectories()
299{
300        if (!exists())
301        {
302                Path p(getPathImpl());
303                p.makeDirectory();
304                if (p.depth() > 1)
305                {
306                        p.makeParent();
307                        File f(p);
308                        f.createDirectories();
309                }
310                createDirectoryImpl();
311        }
312}
313
314
315void File::list(std::vector<std::string>& files) const
316{
317        files.clear();
318        DirectoryIterator it(*this);
319        DirectoryIterator end;
320        while (it != end)
321        {
322                files.push_back(it.name());
323                ++it;
324        }
325}
326
327
328void File::list(std::vector<File>& files) const
329{
330        files.clear();
331        DirectoryIterator it(*this);
332        DirectoryIterator end;
333        while (it != end)
334        {
335                files.push_back(*it);
336                ++it;
337        }
338}
339
340
341void File::handleLastError(const std::string& path)
342{
343        handleLastErrorImpl(path);
344}
345
346
347} // namespace Poco
Note: See TracBrowser for help on using the repository browser.