Logo Search packages:      
Sourcecode: poco version File versions

File.cpp

//
// File.cpp
//
// $Id: //poco/1.4/Foundation/src/File.cpp#3 $
//
// Library: Foundation
// Package: Filesystem
// Module:  File
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
// 
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//


#include "Poco/File.h"
#include "Poco/Path.h"
#include "Poco/DirectoryIterator.h"


#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
#if defined(_WIN32_WCE)
#include "File_WINCE.cpp"
#else
#include "File_WIN32U.cpp"
#endif
#elif defined(POCO_OS_FAMILY_WINDOWS)
#include "File_WIN32.cpp"
#elif defined(POCO_VXWORKS)
#include "File_VX.cpp"
#elif defined(POCO_OS_FAMILY_UNIX)
#include "File_UNIX.cpp"
#else
#include "File_VMS.cpp"
#endif


namespace Poco {


File::File()
{
00064 }


File::File(const std::string& path): FileImpl(path)
{
00069 }


File::File(const char* path): FileImpl(std::string(path))
{
00074 }


File::File(const Path& path): FileImpl(path.toString())
{
00079 }


File::File(const File& file): FileImpl(file.getPathImpl())
{
00084 }


File::~File()
{
00089 }


File& File::operator = (const File& file)
{
      setPathImpl(file.getPathImpl());
      return *this;
00096 }


File& File::operator = (const std::string& path)
{
      setPathImpl(path);
      return *this;
00103 }


File& File::operator = (const char* path)
{
      poco_check_ptr (path);
      setPathImpl(path);
      return *this;
00111 }


File& File::operator = (const Path& path)
{
      setPathImpl(path.toString());
      return *this;
00118 }


void File::swap(File& file)
{
      swapImpl(file);
00124 }


bool File::exists() const
{
      return existsImpl();
00130 }

      
bool File::canRead() const
{
      return canReadImpl();
00136 }

      
bool File::canWrite() const
{
      return canWriteImpl();
00142 }


bool File::canExecute() const
{
      return canExecuteImpl();
00148 }


bool File::isFile() const
{
      return isFileImpl();
00154 }

      
bool File::isDirectory() const
{
      return isDirectoryImpl();
00160 }


bool File::isLink() const
{
      return isLinkImpl();
00166 }


bool File::isDevice() const
{
      return isDeviceImpl();
00172 }


bool File::isHidden() const
{
      return isHiddenImpl();
00178 }


Timestamp File::created() const
{
      return createdImpl();
00184 }

      
Timestamp File::getLastModified() const
{
      return getLastModifiedImpl();
00190 }

      
File& File::setLastModified(const Timestamp& ts)
{
      setLastModifiedImpl(ts);
    return *this;
00197 }

      
File::FileSize File::getSize() const
{
      return getSizeImpl();
00203 }

      
File& File::setSize(FileSizeImpl size)
{
      setSizeImpl(size);
    return *this;
00210 }

      
File& File::setWriteable(bool flag)
{
      setWriteableImpl(flag);
    return *this;
00217 }


File& File::setReadOnly(bool flag)
{
      setWriteableImpl(!flag);
    return *this;
00224 }


File& File::setExecutable(bool flag)
{
      setExecutableImpl(flag);
    return *this;
00231 }

      
void File::copyTo(const std::string& path) const
{
      Path src(getPathImpl());
      Path dest(path);
      File destFile(path);
      if ((destFile.exists() && destFile.isDirectory()) || dest.isDirectory())
      {
            dest.makeDirectory();
            dest.setFileName(src.getFileName());
      }
      if (isDirectory())
            copyDirectory(dest.toString());
      else
            copyToImpl(dest.toString());
00248 }


void File::copyDirectory(const std::string& path) const
{
      File target(path);
      target.createDirectories();

      Path src(getPathImpl());
      src.makeFile();
      DirectoryIterator it(src);
      DirectoryIterator end;
      for (; it != end; ++it)
      {
            it->copyTo(path);
      }
00264 }


void File::moveTo(const std::string& path)
{
      copyTo(path);
      remove(true);
      setPathImpl(path);
00272 }

      
void File::renameTo(const std::string& path)
{
      renameToImpl(path);
      setPathImpl(path);
00279 }

      
void File::remove(bool recursive)
{
      if (recursive && !isLink() && isDirectory())
      {
            std::vector<File> files;
            list(files);
            for (std::vector<File>::iterator it = files.begin(); it != files.end(); ++it)
            {
                  it->remove(true);
            }
      }
      removeImpl();
00294 }


bool File::createFile()
{
      return createFileImpl();
00300 }


bool File::createDirectory()
{
      return createDirectoryImpl();
00306 }


void File::createDirectories()
{
      if (!exists())
      {
            Path p(getPathImpl());
            p.makeDirectory();
            if (p.depth() > 1)
            {
                  p.makeParent();
                  File f(p);
                  f.createDirectories();
            }
            createDirectoryImpl();
      }
00323 }


void File::list(std::vector<std::string>& files) const
{
      files.clear();
      DirectoryIterator it(*this);
      DirectoryIterator end;
      while (it != end)
      {
            files.push_back(it.name());
            ++it;
      }
00336 }


void File::list(std::vector<File>& files) const
{
      files.clear();
      DirectoryIterator it(*this);
      DirectoryIterator end;
      while (it != end)
      {
            files.push_back(*it);
            ++it;
      }
}


void File::handleLastError(const std::string& path)
{
      handleLastErrorImpl(path);
}


} // namespace Poco

Generated by  Doxygen 1.6.0   Back to index