diff --git a/module/Library/IO/Stream.cpp b/module/Library/IO/Stream.cpp index d84012b5..2ea81086 100644 --- a/module/Library/IO/Stream.cpp +++ b/module/Library/IO/Stream.cpp @@ -176,7 +176,8 @@ template < class T > struct RegisterStream mCls // Constructors .template Ctor() - .template Ctor< SQInteger >() + .template Ctor< StackStrF & >() + .template Ctor< SQInteger, StackStrF & >() // Properties .Prop(_SC("Str"), &T::GetStr, &T::SetStr) ; diff --git a/module/Library/IO/Stream.hpp b/module/Library/IO/Stream.hpp index d9455091..0b043a76 100644 --- a/module/Library/IO/Stream.hpp +++ b/module/Library/IO/Stream.hpp @@ -210,6 +210,42 @@ protected: } }; +/* ------------------------------------------------------------------------------------------------ + * Helper used to extract the string from the constructor to the proper type. +*/ +template < class T > struct StreamConstructorStr +{ + static auto Get(StackStrF & str) + { + return str.ToStr(); + } +}; + +/* ------------------------------------------------------------------------------------------------ + * Specializations of `StreamConstructorStr` that return the raw string pointer instead, +*/ +template < > struct StreamConstructorStr< std::fstream > +{ + static const SQChar * Get(StackStrF & str) + { + return str.mPtr; + } +}; +template < > struct StreamConstructorStr< std::ofstream > +{ + static const SQChar * Get(StackStrF & str) + { + return str.mPtr; + } +}; +template < > struct StreamConstructorStr< std::ifstream > +{ + static const SQChar * Get(StackStrF & str) + { + return str.mPtr; + } +}; + /* ------------------------------------------------------------------------------------------------ * Stream-based input/output class. */ @@ -217,7 +253,7 @@ template < class T > struct SqStream : public SqStreamStorage< T > { using SqStreamStorage< T >::Stream; // -------------------------------------------------------------------------------------------- - using Type = SqStreamStorage< T >::Type; + using Type = typename SqStreamStorage< T >::Type; /* -------------------------------------------------------------------------------------------- * Default string constructor. */ @@ -237,16 +273,16 @@ template < class T > struct SqStream : public SqStreamStorage< T > /* -------------------------------------------------------------------------------------------- * Base file constructor. */ - explicit SqStream(StackStrF & name) - : SqStreamStorage< T >(name.mPtr), m_Buffer() + explicit SqStream(StackStrF & str) + : SqStreamStorage< T >(StreamConstructorStr< Type >::Get(str)), m_Buffer() { } /* -------------------------------------------------------------------------------------------- * Explicit file constructor. */ - SqStream(SQInteger m, StackStrF & name) - : SqStreamStorage< T >(name.mPtr, static_cast< std::ios_base::openmode >(m)), m_Buffer() + SqStream(SQInteger m, StackStrF & str) + : SqStreamStorage< T >(StreamConstructorStr< Type >::Get(str), static_cast< std::ios_base::openmode >(m)), m_Buffer() { }