Skip to content
Snippets Groups Projects
Commit 8abbad82 authored by Clinton Stimpson's avatar Clinton Stimpson
Browse files

FStream: Add FStream module.

Uses wide APIs on Windows for fstream.

Change-Id: I159da88196027665b520895a0c5aa881f7e4b125
parent 0c2ff1f7
No related branches found
No related tags found
No related merge requests found
...@@ -123,6 +123,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) ...@@ -123,6 +123,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET(KWSYS_USE_FundamentalType 1) SET(KWSYS_USE_FundamentalType 1)
SET(KWSYS_USE_Terminal 1) SET(KWSYS_USE_Terminal 1)
SET(KWSYS_USE_IOStream 1) SET(KWSYS_USE_IOStream 1)
SET(KWSYS_USE_FStream 1)
SET(KWSYS_USE_String 1) SET(KWSYS_USE_String 1)
SET(KWSYS_USE_SystemInformation 1) SET(KWSYS_USE_SystemInformation 1)
SET(KWSYS_USE_CPU 1) SET(KWSYS_USE_CPU 1)
...@@ -143,6 +144,9 @@ ENDIF(KWSYS_USE_Process) ...@@ -143,6 +144,9 @@ ENDIF(KWSYS_USE_Process)
IF(KWSYS_USE_SystemInformation) IF(KWSYS_USE_SystemInformation)
SET(KWSYS_USE_Process 1) SET(KWSYS_USE_Process 1)
ENDIF(KWSYS_USE_SystemInformation) ENDIF(KWSYS_USE_SystemInformation)
IF(KWSYS_USE_FStream)
SET(KWSYS_USE_Encoding 1)
ENDIF(KWSYS_USE_FStream)
# Setup the large file support default. # Setup the large file support default.
IF(KWSYS_LFS_DISABLE) IF(KWSYS_LFS_DISABLE)
...@@ -869,7 +873,7 @@ SET(KWSYS_HXX_FILES Configure String ...@@ -869,7 +873,7 @@ SET(KWSYS_HXX_FILES Configure String
# Add selected C++ classes. # Add selected C++ classes.
SET(cppclasses SET(cppclasses
Directory DynamicLoader Encoding Glob RegularExpression SystemTools Directory DynamicLoader Encoding Glob RegularExpression SystemTools
CommandLineArguments IOStream SystemInformation CommandLineArguments IOStream FStream SystemInformation
) )
FOREACH(cpp ${cppclasses}) FOREACH(cpp ${cppclasses})
IF(KWSYS_USE_${cpp}) IF(KWSYS_USE_${cpp})
...@@ -931,7 +935,7 @@ FOREACH(c ${KWSYS_CLASSES}) ...@@ -931,7 +935,7 @@ FOREACH(c ${KWSYS_CLASSES})
# Add this source to the list of source files for the library. # Add this source to the list of source files for the library.
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}CXX.cxx) IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}CXX.cxx)
LIST(APPEND KWSYS_CXX_SRCS ${c}CXX.cxx) LIST(APPEND KWSYS_CXX_SRCS ${c}CXX.cxx)
ELSE() ELSEIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}.cxx)
LIST(APPEND KWSYS_CXX_SRCS ${c}.cxx) LIST(APPEND KWSYS_CXX_SRCS ${c}.cxx)
ENDIF() ENDIF()
......
/*============================================================================
KWSys - Kitware System Library
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef @KWSYS_NAMESPACE@_FStream_hxx
#define @KWSYS_NAMESPACE@_FStream_hxx
#include <@KWSYS_NAMESPACE@/ios/fstream>
#include <@KWSYS_NAMESPACE@/Encoding.hxx>
namespace @KWSYS_NAMESPACE@
{
#if defined(_MSC_VER) && _MSC_VER >= 1400
template<typename CharType,typename Traits>
class basic_filebuf : public std::basic_filebuf<CharType,Traits>
{
public:
typedef std::basic_filebuf<CharType,Traits> my_base_type;
basic_filebuf *open(char const *s,std::ios_base::openmode mode)
{
my_base_type::open(Encoding::ToWide(s).c_str(), mode);
return this;
}
};
template<typename CharType,typename Traits = std::char_traits<CharType> >
class basic_ifstream : public std::basic_istream<CharType,Traits>
{
public:
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
typedef std::basic_istream<CharType,Traits> internal_stream_type;
basic_ifstream() : internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
}
explicit basic_ifstream(char const *file_name,
std::ios_base::openmode mode = std::ios_base::in)
: internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
open(file_name,mode);
}
void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::in)
{
if(!buf_->open(file_name,mode | std::ios_base::in))
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
}
bool is_open()
{
return buf_->is_open();
}
bool is_open() const
{
return buf_->is_open();
}
void close()
{
if(!buf_->close())
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
}
internal_buffer_type *rdbuf() const
{
return buf_.get();
}
~basic_ifstream()
{
buf_->close();
delete buf_;
}
private:
internal_buffer_type* buf_;
};
template<typename CharType,typename Traits = std::char_traits<CharType> >
class basic_ofstream : public std::basic_ostream<CharType,Traits>
{
public:
typedef basic_filebuf<CharType,Traits> internal_buffer_type;
typedef std::basic_ostream<CharType,Traits> internal_stream_type;
basic_ofstream() : internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
}
explicit basic_ofstream(char const *file_name,std::ios_base::openmode mode = std::ios_base::out) :
internal_stream_type(new internal_buffer_type())
{
buf_ = static_cast<internal_buffer_type *>(internal_stream_type::rdbuf());
open(file_name,mode);
}
void open(char const *file_name,std::ios_base::openmode mode = std::ios_base::out)
{
if(!buf_->open(file_name,mode | std::ios_base::out))
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
}
bool is_open()
{
return buf_->is_open();
}
bool is_open() const
{
return buf_->is_open();
}
void close()
{
if(!buf_->close())
{
this->setstate(std::ios_base::failbit);
}
else
{
this->clear();
}
}
internal_buffer_type *rdbuf() const
{
return buf_.get();
}
~basic_ofstream()
{
buf_->close();
delete buf_;
}
private:
internal_buffer_type* buf_;
};
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
#else
using @KWSYS_NAMESPACE@_ios_namespace::basic_filebuf;
using @KWSYS_NAMESPACE@_ios_namespace::ofstream;
using @KWSYS_NAMESPACE@_ios_namespace::ifstream;
#endif
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment