Commit 704ab3d2 authored by Kitware Robot's avatar Kitware Robot Committed by Brad King
Browse files

KWSys 2013-11-21 (1010d0e3)

Extract upstream KWSys using the following shell commands.

$ git archive --prefix=upstream-kwsys/ 1010d0e3 | tar x
$ git shortlog --no-merges --abbrev=8 --format='%h %s' 6eab64c3..1010d0e3
Brad King (2):
      ace1364c Encoding: Remove unused include
      1010d0e3 SystemTools: Avoid unused function warnings

Clinton Stimpson (4):
      0c2ff1f7 Encoding: Add Encoding module.
      8abbad82 FStream: Add FStream module.
      0a98de97 KWSys: Port to use wide character Windows APIs throughout.
      2b0c683d Encoding: Default to ANSI code page on Windows

David Cole (1):
      f67bb2ba SystemTools: Move typedef mode_t inside the SystemTools class

Sean McBride (1):
      a40b9263 SystemInformation: Work around gcc -Wliteral-suffix warning

Change-Id: Ie52df972331cc7377c236d410ead86024e9d15ab
parent c01e7445
......@@ -112,6 +112,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET(KWSYS_USE_Base64 1)
SET(KWSYS_USE_Directory 1)
SET(KWSYS_USE_DynamicLoader 1)
SET(KWSYS_USE_Encoding 1)
SET(KWSYS_USE_Glob 1)
SET(KWSYS_USE_MD5 1)
SET(KWSYS_USE_Process 1)
......@@ -122,6 +123,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET(KWSYS_USE_FundamentalType 1)
SET(KWSYS_USE_Terminal 1)
SET(KWSYS_USE_IOStream 1)
SET(KWSYS_USE_FStream 1)
SET(KWSYS_USE_String 1)
SET(KWSYS_USE_SystemInformation 1)
SET(KWSYS_USE_CPU 1)
......@@ -130,18 +132,32 @@ ENDIF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
# Enforce component dependencies.
IF(KWSYS_USE_SystemTools)
SET(KWSYS_USE_Directory 1)
SET(KWSYS_USE_FStream 1)
SET(KWSYS_USE_Encoding 1)
ENDIF(KWSYS_USE_SystemTools)
IF(KWSYS_USE_Glob)
SET(KWSYS_USE_Directory 1)
SET(KWSYS_USE_SystemTools 1)
SET(KWSYS_USE_RegularExpression 1)
SET(KWSYS_USE_FStream 1)
SET(KWSYS_USE_Encoding 1)
ENDIF(KWSYS_USE_Glob)
IF(KWSYS_USE_Process)
SET(KWSYS_USE_System 1)
SET(KWSYS_USE_Encoding 1)
ENDIF(KWSYS_USE_Process)
IF(KWSYS_USE_SystemInformation)
SET(KWSYS_USE_Process 1)
ENDIF(KWSYS_USE_SystemInformation)
IF(KWSYS_USE_System)
SET(KWSYS_USE_Encoding 1)
ENDIF(KWSYS_USE_System)
IF(KWSYS_USE_Directory)
SET(KWSYS_USE_Encoding 1)
ENDIF(KWSYS_USE_Directory)
IF(KWSYS_USE_FStream)
SET(KWSYS_USE_Encoding 1)
ENDIF(KWSYS_USE_FStream)
# Setup the large file support default.
IF(KWSYS_LFS_DISABLE)
......@@ -150,6 +166,11 @@ ELSE(KWSYS_LFS_DISABLE)
SET(KWSYS_LFS_REQUESTED 1)
ENDIF(KWSYS_LFS_DISABLE)
# Specify default 8 bit encoding for Windows
IF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE)
SET(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_ACP)
ENDIF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE)
# Enable testing if building standalone.
IF(KWSYS_STANDALONE)
INCLUDE(Dart)
......@@ -506,6 +527,12 @@ IF(KWSYS_USE_FundamentalType)
"Checking whether char is signed" DIRECT)
ENDIF(KWSYS_USE_FundamentalType)
IF(KWSYS_USE_Encoding)
# Look for type size helper macros.
KWSYS_PLATFORM_CXX_TEST(KWSYS_STL_HAS_WSTRING
"Checking whether wstring is available" DIRECT)
ENDIF(KWSYS_USE_Encoding)
IF(KWSYS_USE_IOStream)
# Determine whether iostreams support long long.
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
......@@ -861,8 +888,8 @@ SET(KWSYS_HXX_FILES Configure String
# Add selected C++ classes.
SET(cppclasses
Directory DynamicLoader Glob RegularExpression SystemTools
CommandLineArguments IOStream SystemInformation
Directory DynamicLoader Encoding Glob RegularExpression SystemTools
CommandLineArguments IOStream FStream SystemInformation
)
FOREACH(cpp ${cppclasses})
IF(KWSYS_USE_${cpp})
......@@ -878,7 +905,7 @@ ENDFOREACH(cpp)
# Add selected C components.
FOREACH(c
Process Base64 FundamentalType MD5 Terminal System String CPU
Process Base64 Encoding FundamentalType MD5 Terminal System String CPU
)
IF(KWSYS_USE_${c})
# Use the corresponding header file.
......@@ -909,16 +936,24 @@ IF(KWSYS_USE_Process)
ENDIF(KWSYS_USE_Process)
# Add selected C sources.
FOREACH(c Base64 MD5 Terminal System String)
FOREACH(c Base64 Encoding MD5 Terminal System String)
IF(KWSYS_USE_${c})
SET(KWSYS_C_SRCS ${KWSYS_C_SRCS} ${c}.c)
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}C.c)
LIST(APPEND KWSYS_C_SRCS ${c}C.c)
ELSE()
LIST(APPEND KWSYS_C_SRCS ${c}.c)
ENDIF()
ENDIF(KWSYS_USE_${c})
ENDFOREACH(c)
# Configure headers of C++ classes and construct the list of sources.
FOREACH(c ${KWSYS_CLASSES})
# Add this source to the list of source files for the library.
SET(KWSYS_CXX_SRCS ${KWSYS_CXX_SRCS} ${c}.cxx)
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}CXX.cxx)
LIST(APPEND KWSYS_CXX_SRCS ${c}CXX.cxx)
ELSEIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${c}.cxx)
LIST(APPEND KWSYS_CXX_SRCS ${c}.cxx)
ENDIF()
# Configure the header for this class.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/${c}.hxx.in ${KWSYS_HEADER_DIR}/${c}.hxx
......@@ -1044,6 +1079,12 @@ IF(KWSYS_USE_String)
COMPILE_FLAGS "-DKWSYS_STRING_C")
ENDIF(KWSYS_USE_String)
IF(KWSYS_USE_Encoding)
# Set default 8 bit encoding in "EndcodingC.c".
SET_PROPERTY(SOURCE EncodingC.c APPEND PROPERTY COMPILE_DEFINITIONS
KWSYS_ENCODING_DEFAULT_CODEPAGE=${KWSYS_ENCODING_DEFAULT_CODEPAGE})
ENDIF(KWSYS_USE_Encoding)
#-----------------------------------------------------------------------------
# Setup testing if not being built as part of another project.
IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
......@@ -1087,6 +1128,11 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
testCommandLineArguments
testCommandLineArguments1
)
IF(KWSYS_STL_HAS_WSTRING)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
testEncoding
)
ENDIF(KWSYS_STL_HAS_WSTRING)
IF(KWSYS_USE_SystemInformation)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testSystemInformation)
ENDIF(KWSYS_USE_SystemInformation)
......
......@@ -36,6 +36,9 @@
/* Whether STL is in std namespace. */
#define @KWSYS_NAMESPACE@_STL_HAVE_STD @KWSYS_STL_HAVE_STD@
/* Whether wstring is available. */
#define @KWSYS_NAMESPACE@_STL_HAS_WSTRING @KWSYS_STL_HAS_WSTRING@
/* Whether the STL string has operator<< for ostream. */
#define @KWSYS_NAMESPACE@_STL_STRING_HAVE_OSTREAM @KWSYS_STL_STRING_HAVE_OSTREAM@
......@@ -170,6 +173,7 @@
# define KWSYS_STL_HAS_ALLOCATOR_TEMPLATE @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE
# define KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
# define KWSYS_STL_HAS_ALLOCATOR_OBJECTS @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_OBJECTS
# define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
#endif
#endif
......@@ -14,6 +14,8 @@
#include KWSYS_HEADER(Configure.hxx)
#include KWSYS_HEADER(Encoding.hxx)
#include KWSYS_HEADER(stl/string)
#include KWSYS_HEADER(stl/vector)
......@@ -22,6 +24,7 @@
#if 0
# include "Directory.hxx.in"
# include "Configure.hxx.in"
# include "Encoding.hxx.in"
# include "kwsys_stl.hxx.in"
# include "kwsys_stl_string.hxx.in"
# include "kwsys_stl_vector.hxx.in"
......@@ -120,10 +123,10 @@ bool Directory::Load(const char* name)
buf = new char[n + 2 + 1];
sprintf(buf, "%s/*", name);
}
struct _finddata_t data; // data of current file
struct _wfinddata_t data; // data of current file
// Now put them into the file array
srchHandle = _findfirst(buf, &data);
srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
delete [] buf;
if ( srchHandle == -1 )
......@@ -134,9 +137,9 @@ bool Directory::Load(const char* name)
// Loop through names
do
{
this->Internal->Files.push_back(data.name);
this->Internal->Files.push_back(Encoding::ToNarrow(data.name));
}
while ( _findnext(srchHandle, &data) != -1 );
while ( _wfindnext(srchHandle, &data) != -1 );
this->Internal->Path = name;
return _findclose(srchHandle) != -1;
}
......@@ -160,10 +163,10 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name)
buf = new char[n + 2 + 1];
sprintf(buf, "%s/*", name);
}
struct _finddata_t data; // data of current file
struct _wfinddata_t data; // data of current file
// Now put them into the file array
srchHandle = _findfirst(buf, &data);
srchHandle = _wfindfirst((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
delete [] buf;
if ( srchHandle == -1 )
......@@ -177,7 +180,7 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const char* name)
{
count++;
}
while ( _findnext(srchHandle, &data) != -1 );
while ( _wfindnext(srchHandle, &data) != -1 );
_findclose(srchHandle);
return count;
}
......
......@@ -186,13 +186,12 @@ namespace KWSYS_NAMESPACE
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname)
{
DynamicLoader::LibraryHandle lh;
#ifdef UNICODE
wchar_t libn[MB_CUR_MAX];
mbstowcs(libn, libname, MB_CUR_MAX);
lh = LoadLibrary(libn);
#else
lh = LoadLibrary(libname);
#endif
int length = MultiByteToWideChar(CP_UTF8, 0, libname, -1, NULL, 0);
wchar_t* wchars = new wchar_t[length+1];
wchars[0] = '\0';
MultiByteToWideChar(CP_UTF8, 0, libname, -1, wchars, length);
lh = LoadLibraryW(wchars);
delete [] wchars;
return lh;
}
......@@ -238,13 +237,7 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
#else
const char *rsym = sym;
#endif
#ifdef UNICODE
wchar_t wsym[MB_CUR_MAX];
mbstowcs(wsym, rsym, MB_CUR_MAX);
result = GetProcAddress(lib, wsym);
#else
result = (void*)GetProcAddress(lib, rsym);
#endif
#if defined(__BORLANDC__) || defined(__WATCOMC__)
delete[] rsym;
#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@_Encoding_h
#define @KWSYS_NAMESPACE@_Encoding_h
#include <@KWSYS_NAMESPACE@/Configure.h>
#include <wchar.h>
/* Redefine all public interface symbol names to be in the proper
namespace. These macros are used internally to kwsys only, and are
not visible to user code. Use kwsysHeaderDump.pl to reproduce
these macros after making changes to the interface. */
#if !defined(KWSYS_NAMESPACE)
# define kwsys_ns(x) @KWSYS_NAMESPACE@##x
# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
#if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsysEncoding kwsys_ns(Encoding)
# define kwsysEncoding_mbstowcs kwsys_ns(Encoding_mbstowcs)
# define kwsysEncoding_DupToWide kwsys_ns(Encoding_DupToWide)
# define kwsysEncoding_wcstombs kwsys_ns(Encoding_wcstombs)
# define kwsysEncoding_DupToNarrow kwsys_ns(Encoding_DupToNarrow)
#endif
#if defined(__cplusplus)
extern "C"
{
#endif
/* Convert a narrow string to a wide string.
On Windows, UTF-8 is assumed, and on other platforms,
the current locale is assumed.
*/
kwsysEXPORT size_t kwsysEncoding_mbstowcs(wchar_t* dest, const char* src, size_t n);
/* Convert a narrow string to a wide string.
This can return NULL if the conversion fails. */
kwsysEXPORT wchar_t* kwsysEncoding_DupToWide(const char* src);
/* Convert a wide string to a narrow string.
On Windows, UTF-8 is assumed, and on other platforms,
the current locale is assumed. */
kwsysEXPORT size_t kwsysEncoding_wcstombs(char* dest, const wchar_t* src, size_t n);
/* Convert a wide string to a narrow string.
This can return NULL if the conversion fails. */
kwsysEXPORT char* kwsysEncoding_DupToNarrow(const wchar_t* str);
#if defined(__cplusplus)
} /* extern "C" */
#endif
/* If we are building a kwsys .c or .cxx file, let it use these macros.
Otherwise, undefine them to keep the namespace clean. */
#if !defined(KWSYS_NAMESPACE)
# undef kwsys_ns
# undef kwsysEXPORT
# if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsysEncoding
# undef kwsysEncoding_mbstowcs
# undef kwsysEncoding_DupToWide
# undef kwsysEncoding_wcstombs
# undef kwsysEncoding_DupToNarrow
# endif
#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@_Encoding_hxx
#define @KWSYS_NAMESPACE@_Encoding_hxx
#include <@KWSYS_NAMESPACE@/Configure.hxx>
#include <@KWSYS_NAMESPACE@/stl/string>
/* Define these macros temporarily to keep the code readable. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# define kwsys_stl @KWSYS_NAMESPACE@_stl
#endif
namespace @KWSYS_NAMESPACE@
{
class @KWSYS_NAMESPACE@_EXPORT Encoding
{
public:
/**
* Convert between char and wchar_t
*/
#if @KWSYS_NAMESPACE@_STL_HAS_WSTRING
// Convert a narrow string to a wide string.
// On Windows, UTF-8 is assumed, and on other platforms,
// the current locale is assumed.
static kwsys_stl::wstring ToWide(const kwsys_stl::string& str);
static kwsys_stl::wstring ToWide(const char* str);
// Convert a wide string to a narrow string.
// On Windows, UTF-8 is assumed, and on other platforms,
// the current locale is assumed.
static kwsys_stl::string ToNarrow(const kwsys_stl::wstring& str);
static kwsys_stl::string ToNarrow(const wchar_t* str);
#endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
}; // class Encoding
} // namespace @KWSYS_NAMESPACE@
/* Undefine temporary macros. */
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
# undef kwsys_stl
#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.
============================================================================*/
#include "kwsysPrivate.h"
#include KWSYS_HEADER(Encoding.h)
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
# include "Encoding.h.in"
#endif
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
#endif
size_t kwsysEncoding_mbstowcs(wchar_t* dest, const char* str, size_t n)
{
if(str == 0)
{
return (size_t)-1;
}
#ifdef _WIN32
return MultiByteToWideChar(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0,
str, -1, dest, (int)n) - 1;
#else
return mbstowcs(dest, str, n);
#endif
}
wchar_t* kwsysEncoding_DupToWide(const char* str)
{
wchar_t* ret = NULL;
size_t length = kwsysEncoding_mbstowcs(NULL, str, 0) + 1;
if(length > 0)
{
ret = malloc((length)*sizeof(wchar_t));
ret[0] = 0;
kwsysEncoding_mbstowcs(ret, str, length);
}
return ret;
}
size_t kwsysEncoding_wcstombs(char* dest, const wchar_t* str, size_t n)
{
if(str == 0)
{
return (size_t)-1;
}
#ifdef _WIN32
return WideCharToMultiByte(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str, -1,
dest, (int)n, NULL, NULL) - 1;
#else
return wcstombs(dest, str, n);
#endif
}
char* kwsysEncoding_DupToNarrow(const wchar_t* str)
{
char* ret = NULL;
size_t length = kwsysEncoding_wcstombs(0, str, 0);
if(length > 0)
{
ret = malloc(length);
ret[0] = 0;
kwsysEncoding_wcstombs(ret, str, length);
}
return ret;
}
/*============================================================================
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.
============================================================================*/
#ifdef __osf__
# define _OSF_SOURCE
# define _POSIX_C_SOURCE 199506L
# define _XOPEN_SOURCE_EXTENDED
#endif
#include "kwsysPrivate.h"
#include KWSYS_HEADER(Encoding.hxx)
#include KWSYS_HEADER(Encoding.h)
#include KWSYS_HEADER(stl/vector)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
# include "Encoding.hxx.in"
# include "Encoding.h.in"
#endif
#include <stdlib.h>
#ifdef _MSC_VER
# pragma warning (disable: 4786)
#endif
// Windows API.
#if defined(_WIN32)
# include <windows.h>
#endif
namespace KWSYS_NAMESPACE
{
#if KWSYS_STL_HAS_WSTRING
kwsys_stl::wstring Encoding::ToWide(const kwsys_stl::string& str)
{
return ToWide(str.c_str());
}
kwsys_stl::string Encoding::ToNarrow(const kwsys_stl::wstring& str)
{
return ToNarrow(str.c_str());
}
kwsys_stl::wstring Encoding::ToWide(const char* cstr)
{
kwsys_stl::wstring wstr;
size_t length = kwsysEncoding_mbstowcs(0, cstr, 0) + 1;
if(length > 0)
{
kwsys_stl::vector<wchar_t> wchars(length);
if(kwsysEncoding_mbstowcs(&wchars[0], cstr, length) > 0)
{
wstr = &wchars[0];
}
}
return wstr;
}
kwsys_stl::string Encoding::ToNarrow(const wchar_t* wcstr)
{
kwsys_stl::string str;
size_t length = kwsysEncoding_wcstombs(0, wcstr, 0) + 1;
if(length > 0)
{
std::vector<char> chars(length);
if(kwsysEncoding_wcstombs(&chars[0], wcstr, length) > 0)
{
str = &chars[0];
}
}
return str;
}
#endif // KWSYS_STL_HAS_WSTRING
} // namespace KWSYS_NAMESPACE
/*============================================================================
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();
}
}