mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Adjust the Vector2 and Vector2i type functions to use the new method of receiving formatted strings.
This commit is contained in:
parent
759318d48e
commit
32ce07bdad
@ -51,13 +51,6 @@ Vector2 & Vector2::operator = (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2 & Vector2::operator = (CSStr values)
|
||||
{
|
||||
SetVector2(Vector2::Get(values, Delim));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2 & Vector2::operator = (const Vector2i & v)
|
||||
{
|
||||
@ -340,9 +333,9 @@ void Vector2::SetVector2i(const Vector2i & v)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector2::SetStr(CSStr values, SQChar delim)
|
||||
void Vector2::SetStr(SQChar delim, const StackStrF & values)
|
||||
{
|
||||
SetVector2(Vector2::Get(values, delim));
|
||||
SetVector2(Vector2::GetEx(delim, values));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -383,13 +376,13 @@ Vector2 Vector2::Abs() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2 & Vector2::Get(CSStr str)
|
||||
const Vector2 & Vector2::Get(const StackStrF & str)
|
||||
{
|
||||
return Vector2::Get(str, Vector2::Delim);
|
||||
return Vector2::GetEx(Vector2::Delim, str);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2 & Vector2::Get(CSStr str, SQChar delim)
|
||||
const Vector2 & Vector2::GetEx(SQChar delim, const StackStrF & str)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %f , %f ");
|
||||
@ -397,14 +390,14 @@ const Vector2 & Vector2::Get(CSStr str, SQChar delim)
|
||||
// Clear previous values, if any
|
||||
vec.Clear();
|
||||
// Is the specified string empty?
|
||||
if (!str || *str == '0')
|
||||
if (str.mLen <= 0)
|
||||
{
|
||||
return vec; // Return the value as is!
|
||||
}
|
||||
// Assign the specified delimiter
|
||||
fs[4] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
std::sscanf(str, fs, &vec.x, &vec.y);
|
||||
std::sscanf(str.mPtr, fs, &vec.x, &vec.y);
|
||||
// Return the resulted value
|
||||
return vec;
|
||||
}
|
||||
@ -475,18 +468,17 @@ void Register_Vector2(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetVector2"), &Vector2::SetVector2)
|
||||
.Func(_SC("SetVector2Ex"), &Vector2::SetVector2Ex)
|
||||
.Func(_SC("SetVector2i"), &Vector2::SetVector2i)
|
||||
.Func(_SC("SetStr"), &Vector2::SetStr)
|
||||
.FmtFunc(_SC("SetStr"), &Vector2::SetStr)
|
||||
.Func(_SC("Clear"), &Vector2::Clear)
|
||||
// Member Overloads
|
||||
.Overload< void (Vector2::*)(void) >(_SC("Generate"), &Vector2::Generate)
|
||||
.Overload< void (Vector2::*)(Val, Val) >(_SC("Generate"), &Vector2::Generate)
|
||||
.Overload< void (Vector2::*)(Val, Val, Val, Val) >(_SC("Generate"), &Vector2::Generate)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Vector2 & (*)(CSStr) >(_SC("FromStr"), &Vector2::Get)
|
||||
.StaticOverload< const Vector2 & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector2::Get)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Vector2 >)
|
||||
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector2 >)
|
||||
.StaticFmtFunc(_SC("FromStr"), &Vector2::Get)
|
||||
.StaticFmtFunc(_SC("FromStrEx"), &Vector2::GetEx)
|
||||
// Operator Exposure
|
||||
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opAddAssign"), &Vector2::operator +=)
|
||||
.Func< Vector2 & (Vector2::*)(const Vector2 &) >(_SC("opSubAssign"), &Vector2::operator -=)
|
||||
|
@ -314,7 +314,7 @@ struct Vector2
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the values extracted from the specified string using the specified delimiter.
|
||||
*/
|
||||
void SetStr(CSStr values, SQChar delim);
|
||||
void SetStr(SQChar delim, const StackStrF & values);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Generate random values for all components of this instance.
|
||||
@ -347,13 +347,12 @@ struct Vector2
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2 type from a string.
|
||||
*/
|
||||
static const Vector2 & Get(CSStr str);
|
||||
static const Vector2 & Get(const StackStrF & str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2 type from a string.
|
||||
*/
|
||||
static const Vector2 & Get(CSStr str, SQChar delim);
|
||||
|
||||
static const Vector2 & GetEx(SQChar delim, const StackStrF & str);
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -51,13 +51,6 @@ Vector2i & Vector2i::operator = (Value s)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2i & Vector2i::operator = (CSStr values)
|
||||
{
|
||||
SetVector2i(Vector2i::Get(values, Delim));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2i & Vector2i::operator = (const Vector2 & v)
|
||||
{
|
||||
@ -486,9 +479,9 @@ void Vector2i::SetVector2(const Vector2 & v)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Vector2i::SetStr(CSStr values, SQChar delim)
|
||||
void Vector2i::SetStr(SQChar delim, const StackStrF & values)
|
||||
{
|
||||
SetVector2i(Vector2i::Get(values, delim));
|
||||
SetVector2i(Vector2i::GetEx(delim, values));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -529,13 +522,13 @@ Vector2i Vector2i::Abs() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2i & Vector2i::Get(CSStr str)
|
||||
const Vector2i & Vector2i::Get(const StackStrF & str)
|
||||
{
|
||||
return Vector2i::Get(str, Vector2i::Delim);
|
||||
return Vector2i::GetEx(Vector2i::Delim, str);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const Vector2i & Vector2i::Get(CSStr str, SQChar delim)
|
||||
const Vector2i & Vector2i::GetEx(SQChar delim, const StackStrF & str)
|
||||
{
|
||||
// The format specifications that will be used to scan the string
|
||||
static SQChar fs[] = _SC(" %d , %d ");
|
||||
@ -543,14 +536,14 @@ const Vector2i & Vector2i::Get(CSStr str, SQChar delim)
|
||||
// Clear previous values, if any
|
||||
vec.Clear();
|
||||
// Is the specified string empty?
|
||||
if (!str || *str == '\0')
|
||||
if (str.mLen <= 0)
|
||||
{
|
||||
return vec; // Return the value as is!
|
||||
}
|
||||
// Assign the specified delimiter
|
||||
fs[4] = delim;
|
||||
// Attempt to extract the component values from the specified string
|
||||
std::sscanf(str, &fs[0], &vec.x, &vec.y);
|
||||
std::sscanf(str.mPtr, &fs[0], &vec.x, &vec.y);
|
||||
// Return the resulted value
|
||||
return vec;
|
||||
}
|
||||
@ -621,18 +614,17 @@ void Register_Vector2i(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetVector2i"), &Vector2i::SetVector2i)
|
||||
.Func(_SC("SetVector2iEx"), &Vector2i::SetVector2iEx)
|
||||
.Func(_SC("SetVector2"), &Vector2i::SetVector2)
|
||||
.Func(_SC("SetStr"), &Vector2i::SetStr)
|
||||
.FmtFunc(_SC("SetStr"), &Vector2i::SetStr)
|
||||
.Func(_SC("Clear"), &Vector2i::Clear)
|
||||
// Member Overloads
|
||||
.Overload< void (Vector2i::*)(void) >(_SC("Generate"), &Vector2i::Generate)
|
||||
.Overload< void (Vector2i::*)(Val, Val) >(_SC("Generate"), &Vector2i::Generate)
|
||||
.Overload< void (Vector2i::*)(Val, Val, Val, Val) >(_SC("Generate"), &Vector2i::Generate)
|
||||
// Static Overloads
|
||||
.StaticOverload< const Vector2i & (*)(CSStr) >(_SC("FromStr"), &Vector2i::Get)
|
||||
.StaticOverload< const Vector2i & (*)(CSStr, SQChar) >(_SC("FromStr"), &Vector2i::Get)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Vector2i >)
|
||||
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Vector2i >)
|
||||
.StaticFmtFunc(_SC("FromStr"), &Vector2i::Get)
|
||||
.StaticFmtFunc(_SC("FromStrEx"), &Vector2i::GetEx)
|
||||
// Operator Exposure
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opAddAssign"), &Vector2i::operator +=)
|
||||
.Func< Vector2i & (Vector2i::*)(const Vector2i &) >(_SC("opSubAssign"), &Vector2i::operator -=)
|
||||
|
@ -79,11 +79,6 @@ struct Vector2i
|
||||
*/
|
||||
Vector2i & operator = (Value s);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* String assignment operator.
|
||||
*/
|
||||
Vector2i & operator = (CSStr values);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Real two-dimensional vector assignment.
|
||||
*/
|
||||
@ -419,7 +414,7 @@ struct Vector2i
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the values extracted from the specified string using the specified delimiter.
|
||||
*/
|
||||
void SetStr(CSStr values, SQChar delim);
|
||||
void SetStr(SQChar delim, const StackStrF & values);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Generate random values for all components of this instance.
|
||||
@ -452,12 +447,12 @@ struct Vector2i
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2i type from a string.
|
||||
*/
|
||||
static const Vector2i & Get(CSStr str);
|
||||
static const Vector2i & Get(const StackStrF & str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract the values for components of the Vector2i type from a string.
|
||||
*/
|
||||
static const Vector2i & Get(CSStr str, SQChar delim);
|
||||
static const Vector2i & GetEx(SQChar delim, const StackStrF & str);
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user