mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Adjust stream constructor.
This commit is contained in:
parent
6935d4bfb1
commit
4c08879b5c
@ -176,7 +176,8 @@ template < class T > struct RegisterStream
|
|||||||
mCls
|
mCls
|
||||||
// Constructors
|
// Constructors
|
||||||
.template Ctor()
|
.template Ctor()
|
||||||
.template Ctor< SQInteger >()
|
.template Ctor< StackStrF & >()
|
||||||
|
.template Ctor< SQInteger, StackStrF & >()
|
||||||
// Properties
|
// Properties
|
||||||
.Prop(_SC("Str"), &T::GetStr, &T::SetStr)
|
.Prop(_SC("Str"), &T::GetStr, &T::SetStr)
|
||||||
;
|
;
|
||||||
|
@ -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.
|
* Stream-based input/output class.
|
||||||
*/
|
*/
|
||||||
@ -217,7 +253,7 @@ template < class T > struct SqStream : public SqStreamStorage< T >
|
|||||||
{
|
{
|
||||||
using SqStreamStorage< T >::Stream;
|
using SqStreamStorage< T >::Stream;
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
using Type = SqStreamStorage< T >::Type;
|
using Type = typename SqStreamStorage< T >::Type;
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Default string constructor.
|
* Default string constructor.
|
||||||
*/
|
*/
|
||||||
@ -237,16 +273,16 @@ template < class T > struct SqStream : public SqStreamStorage< T >
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Base file constructor.
|
* Base file constructor.
|
||||||
*/
|
*/
|
||||||
explicit SqStream(StackStrF & name)
|
explicit SqStream(StackStrF & str)
|
||||||
: SqStreamStorage< T >(name.mPtr), m_Buffer()
|
: SqStreamStorage< T >(StreamConstructorStr< Type >::Get(str)), m_Buffer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Explicit file constructor.
|
* Explicit file constructor.
|
||||||
*/
|
*/
|
||||||
SqStream(SQInteger m, StackStrF & name)
|
SqStream(SQInteger m, StackStrF & str)
|
||||||
: SqStreamStorage< T >(name.mPtr, static_cast< std::ios_base::openmode >(m)), m_Buffer()
|
: SqStreamStorage< T >(StreamConstructorStr< Type >::Get(str), static_cast< std::ios_base::openmode >(m)), m_Buffer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user