Click here to Skip to main content
15,891,864 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.2K   977   33  
Extending boost::filesystem for Windows and Linux.
/************************************************************
 *                                                          *
 *          Written by Stanic Igor 2012/2013                *
 *  Header with basic defines/typedefs. This is the place   *
 *  where you need to define the platform you target        *
 *  compilation for(WINDOWS/LINUX).                         *
 *                                                          *
 ************************************************************/

#ifndef BASEDECL_BOOST_FILESYSTEM_HELPER_H
#define BASEDECL_BOOST_FILESYSTEM_HELPER_H

/***********************************************/
//Change define to specify platform where you
//need to compile
/***********************************************/
#define WINDOWS
//#define LINUX

#include <string>
#include <sstream>
#include <typeinfo>
#include <limits>


#ifdef WINDOWS
typedef std::wstring STRING_TYPE;
typedef std::wstringstream STR_STREAM;

#define EMPTYSTR std::wstring()
//char array literal to wchar_t array
#define CHRARR_CON(x) L ##x

#elif defined(LINUX)
typedef std::string STRING_TYPE;
typedef std::stringstream STR_STREAM;

#define EMPTYSTR std::string()
#define CHRARR_CON(x) STRING_TYPE(x)
#define CH_TYPE(x) x

#endif

typedef long long LLONG;
typedef unsigned long long ULLONG;
typedef unsigned int UINT;
typedef unsigned long ULONG;
#define STR_SET Helpers::STRING_TYPES<STRING_TYPE, STR_STREAM>

template<typename TSTR = STRING_TYPE>
inline bool IS_W_STRING()
{
    return typeid(TSTR) == typeid(std::wstring);
}

inline std::wstring TO_STRING_TYPE(const std::wstring& str)
{
    return str;
}

template<typename TSTR = STRING_TYPE>
inline TSTR TO_STRING_TYPE(const std::string& str)
{
#ifdef WINDOWS
        TSTR retval(str.begin(), str.end());
        return retval;
#elif defined(LINUX)
        return str;
#endif
}

template<typename TSTR = STRING_TYPE>
inline TSTR TO_STRING_TYPE(const char* chars)
{
        std::string temp(chars);
#ifdef WINDOWS
        TSTR retval(temp.begin(), temp.end());
        return retval;
#elif defined(LINUX)
        return temp;
#endif
}

#endif // BASEDECL_H

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