Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / C++11

Extending boost::filesystem for Windows and Linux: Part 1

Rate me:
Please Sign up or sign in to vote.
4.93/5 (15 votes)
19 Mar 2013CPOL16 min read 31.3K   977   33  
Extending boost::filesystem for Windows and Linux.
/********************************************************
 *                                                      *
 *          Written by Stanic Igor 2012/2013            *
 *          Windows implementation of F_INFO struct     *
 *                                                      *
 *******************************************************/

#include "F_INFO.h"
using namespace std;
using namespace boost;
using namespace boost::filesystem;


F_INFO_WINDOWS::F_INFO_WINDOWS( const F_INFO& other)
{
    if(this == &other)
        return;
    this->isDirectory = other.isDirectory;
    this->length = other.length;
    this->name = other.name;
    this->path = other.path;
    this->time = other.time;
    this->isSymLink = other.isSymLink;
    this->m_fileAttrData = other.m_fileAttrData;
    this->m_permission_denied = other.m_permission_denied;
}

F_INFO_WINDOWS::F_INFO_WINDOWS(F_INFO_WINDOWS&& other)
{
    if(this != &other)
    {
        this->isDirectory = other.isDirectory;
        this->length = other.length;
        this->name = std::move(other.name);
        this->path = std::move(other.path);
        this->time = other.time;
        this->isSymLink = other.isSymLink;
        this->m_fileAttrData = other.m_fileAttrData;
        this->m_permission_denied = other.m_permission_denied;
    }
}

F_INFO_WINDOWS& F_INFO_WINDOWS::operator=(F_INFO other)
{
    this->isDirectory = other.isDirectory;
    this->length = other.length;
    this->name = std::move(other.name);
    this->path = std::move(other.path);
    this->time = other.time;
    this->isSymLink = other.isSymLink;
    this->m_fileAttrData = other.m_fileAttrData;
    this->m_permission_denied = other.m_permission_denied;
    return *this;
}

bool F_INFO_WINDOWS::checkAttribute( DWORD dword) const
{
    // first part of expression returns BOOL type which needs conversion
    // to bool without performance penalties
    return (m_fileAttrData.dwFileAttributes & dword) != FALSE;
}

bool F_INFO_WINDOWS::isArchive() const
{
    return checkAttribute(FILE_ATTRIBUTE_ARCHIVE);
}

bool F_INFO_WINDOWS::isCompressed() const
{
    return checkAttribute(FILE_ATTRIBUTE_COMPRESSED);
}

bool F_INFO_WINDOWS::isEncrypted() const
{
    return checkAttribute(FILE_ATTRIBUTE_ENCRYPTED);
}

bool F_INFO_WINDOWS::isHidden() const
{
    return checkAttribute(FILE_ATTRIBUTE_HIDDEN);
}

bool F_INFO_WINDOWS::isNormal() const
{
    return checkAttribute(FILE_ATTRIBUTE_NORMAL);
}

bool F_INFO_WINDOWS::isOffline() const
{
    return checkAttribute(FILE_ATTRIBUTE_OFFLINE);
}

bool F_INFO_WINDOWS::isReadOnly() const
{
    return checkAttribute(FILE_ATTRIBUTE_READONLY);
}

bool F_INFO_WINDOWS::isSystem() const
{
    return checkAttribute(FILE_ATTRIBUTE_SYSTEM);
}

bool F_INFO_WINDOWS::isTemporary() const
{
    return checkAttribute(FILE_ATTRIBUTE_TEMPORARY);
}

bool F_INFO_WINDOWS::permission_denied() const
{
    return m_permission_denied;
}

//F_INFO_WINDOWS END

/* FileOperations BEGIN*/
//#ifdef WINDOWS
//extern BOOL WINAPI GetFileAttributesExW(
//  _In_   LPCTSTR lpFileName,
//  _In_   GET_FILEEX_INFO_LEVELS fInfoLevelId,
//  _Out_  LPVOID lpFileInformation
//);

//long FILE_ATTRIBUTE_HIDDEN = 0x2;
//long FILE_ATTRIBUTE_SYSTEM = 0x4;
//#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Serbia Serbia
Software developer with couple of years of experience mostly with .NET programming and MS SQL databases currently interested in expanding knowledge to C++ and other operating systems.

Comments and Discussions