00001 // 00002 // DirectoryIterator.cpp 00003 // 00004 // $Id: //poco/1.3/Foundation/src/DirectoryIterator.cpp#1 $ 00005 // 00006 // Library: Foundation 00007 // Package: Filesystem 00008 // Module: DirectoryIterator 00009 // 00010 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. 00011 // and Contributors. 00012 // 00013 // Permission is hereby granted, free of charge, to any person or organization 00014 // obtaining a copy of the software and accompanying documentation covered by 00015 // this license (the "Software") to use, reproduce, display, distribute, 00016 // execute, and transmit the Software, and to prepare derivative works of the 00017 // Software, and to permit third-parties to whom the Software is furnished to 00018 // do so, all subject to the following: 00019 // 00020 // The copyright notices in the Software and this entire statement, including 00021 // the above license grant, this restriction and the following disclaimer, 00022 // must be included in all copies of the Software, in whole or in part, and 00023 // all derivative works of the Software, unless such copies or derivative 00024 // works are solely in the form of machine-executable object code generated by 00025 // a source language processor. 00026 // 00027 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00028 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00029 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 00030 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 00031 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 00032 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00033 // DEALINGS IN THE SOFTWARE. 00034 // 00035 00036 00037 #include "Poco/DirectoryIterator.h" 00038 00039 00040 #if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8) 00041 #include "DirectoryIterator_WIN32U.cpp" 00042 #elif defined(POCO_OS_FAMILY_WINDOWS) 00043 #include "DirectoryIterator_WIN32.cpp" 00044 #elif defined(POCO_OS_FAMILY_UNIX) 00045 #include "DirectoryIterator_UNIX.cpp" 00046 #else 00047 #include "DirectoryIterator_VMS.cpp" 00048 #endif 00049 00050 00051 namespace Poco { 00052 00053 00054 DirectoryIterator::DirectoryIterator(): _pImpl(0) 00055 { 00056 } 00057 00058 00059 DirectoryIterator::DirectoryIterator(const std::string& path): _path(path), _pImpl(new DirectoryIteratorImpl(path)) 00060 { 00061 _path.makeDirectory(); 00062 _path.setFileName(_pImpl->get()); 00063 _file = _path; 00064 } 00065 00066 00067 DirectoryIterator::DirectoryIterator(const DirectoryIterator& iterator): _path(iterator._path), _pImpl(iterator._pImpl) 00068 { 00069 _path.makeDirectory(); 00070 if (_pImpl) 00071 { 00072 _pImpl->duplicate(); 00073 _path.setFileName(_pImpl->get()); 00074 _file = _path; 00075 } 00076 } 00077 00078 00079 DirectoryIterator::DirectoryIterator(const File& file): _path(file.path()), _pImpl(new DirectoryIteratorImpl(file.path())) 00080 { 00081 _path.makeDirectory(); 00082 _path.setFileName(_pImpl->get()); 00083 _file = _path; 00084 } 00085 00086 00087 DirectoryIterator::DirectoryIterator(const Path& path): _path(path), _pImpl(new DirectoryIteratorImpl(path.toString())) 00088 { 00089 _path.makeDirectory(); 00090 _path.setFileName(_pImpl->get()); 00091 _file = _path; 00092 } 00093 00094 00095 DirectoryIterator::~DirectoryIterator() 00096 { 00097 if (_pImpl) _pImpl->release(); 00098 } 00099 00100 00101 DirectoryIterator& DirectoryIterator::operator = (const DirectoryIterator& it) 00102 { 00103 if (_pImpl) _pImpl->release(); 00104 _pImpl = it._pImpl; 00105 if (_pImpl) 00106 { 00107 _pImpl->duplicate(); 00108 _path = it._path; 00109 _file = _path; 00110 } 00111 return *this; 00112 } 00113 00114 00115 DirectoryIterator& DirectoryIterator::operator = (const File& file) 00116 { 00117 if (_pImpl) _pImpl->release(); 00118 _pImpl = new DirectoryIteratorImpl(file.path()); 00119 _path.parseDirectory(file.path()); 00120 _path.setFileName(_pImpl->get()); 00121 _file = _path; 00122 return *this; 00123 } 00124 00125 00126 DirectoryIterator& DirectoryIterator::operator = (const Path& path) 00127 { 00128 if (_pImpl) _pImpl->release(); 00129 _pImpl = new DirectoryIteratorImpl(path.toString()); 00130 _path = path; 00131 _path.makeDirectory(); 00132 _path.setFileName(_pImpl->get()); 00133 _file = _path; 00134 return *this; 00135 } 00136 00137 00138 DirectoryIterator& DirectoryIterator::operator = (const std::string& path) 00139 { 00140 if (_pImpl) _pImpl->release(); 00141 _pImpl = new DirectoryIteratorImpl(path); 00142 _path.parseDirectory(path); 00143 _path.setFileName(_pImpl->get()); 00144 _file = _path; 00145 return *this; 00146 } 00147 00148 00149 DirectoryIterator& DirectoryIterator::operator ++ () 00150 { 00151 if (_pImpl) 00152 { 00153 _path.setFileName(_pImpl->next()); 00154 _file = _path; 00155 } 00156 return *this; 00157 } 00158 00159 00160 DirectoryIterator DirectoryIterator::operator ++ (int dummy) 00161 { 00162 if (_pImpl) 00163 { 00164 _path.setFileName(_pImpl->next()); 00165 _file = _path; 00166 } 00167 return *this; 00168 } 00169 00170 00171 } // namespace Poco