DirectoryIterator_WIN32U.cpp
Go to the documentation of this file.
00001 //
00002 // DirectoryIterator_WIN32U.cpp
00003 //
00004 // $Id: //poco/1.3/Foundation/src/DirectoryIterator_WIN32U.cpp#4 $
00005 //
00006 // Library: Foundation
00007 // Package: Filesystem
00008 // Module:  DirectoryIterator
00009 //
00010 // Copyright (c) 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_WIN32U.h"
00038 #include "Poco/File_WIN32U.h"
00039 #include "Poco/Path.h"
00040 #include "Poco/UnicodeConverter.h"
00041 #include <cstring>
00042 
00043 
00044 namespace Poco {
00045 
00046 
00047 DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& path): _fh(INVALID_HANDLE_VALUE), _rc(1)
00048 {
00049         Path p(path);
00050         p.makeDirectory();
00051         std::string findPath = p.toString();
00052         findPath.append("*");
00053         std::wstring uFindPath;
00054         UnicodeConverter::toUTF16(findPath, uFindPath);
00055 
00056         _fh = FindFirstFileW(uFindPath.c_str(), &_fd);
00057         if (_fh == INVALID_HANDLE_VALUE)
00058         {
00059                 if (GetLastError() != ERROR_NO_MORE_FILES)
00060                         File::handleLastError(path);
00061         }
00062         else
00063         {
00064                 UnicodeConverter::toUTF8(_fd.cFileName, _current);
00065                 if (_current == "." || _current == "..")        
00066                         next();
00067         }
00068 }
00069 
00070 
00071 DirectoryIteratorImpl::~DirectoryIteratorImpl()
00072 {
00073         if (_fh != INVALID_HANDLE_VALUE)
00074                 FindClose(_fh);
00075 }
00076 
00077 
00078 const std::string& DirectoryIteratorImpl::next()
00079 {
00080         do
00081         {
00082                 _current.clear();
00083                 if (FindNextFileW(_fh, &_fd) != 0)
00084                 {
00085                         UnicodeConverter::toUTF8(_fd.cFileName, _current);
00086                 }
00087         }
00088         while (_current == "." || _current == "..");
00089         return _current;
00090 }
00091 
00092 
00093 } // namespace Poco


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:19