1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Adjust the Sphere type functions to use the new method of receiving formatted strings.

This commit is contained in:
Sandu Liviu Catalin 2016-11-16 16:19:38 +02:00
parent 6522889492
commit 759318d48e
2 changed files with 13 additions and 15 deletions

View File

@ -409,9 +409,9 @@ void Sphere::SetPositionEx(Value nx, Value ny, Value nz)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Sphere::SetStr(CSStr values, SQChar delim) void Sphere::SetStr(SQChar delim, const StackStrF & values)
{ {
SetSphere(Sphere::Get(values, delim)); SetSphere(Sphere::GetEx(delim, values));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -468,13 +468,13 @@ Sphere Sphere::Abs() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Sphere & Sphere::Get(CSStr str) const Sphere & Sphere::Get(const StackStrF & str)
{ {
return Sphere::Get(str, Sphere::Delim); return Sphere::GetEx(Sphere::Delim, str);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const Sphere & Sphere::Get(CSStr str, SQChar delim) const Sphere & Sphere::GetEx(SQChar delim, const StackStrF & str)
{ {
// The format specifications that will be used to scan the string // The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %f , %f , %f , %f "); static SQChar fs[] = _SC(" %f , %f , %f , %f ");
@ -482,7 +482,7 @@ const Sphere & Sphere::Get(CSStr str, SQChar delim)
// Clear previous values, if any // Clear previous values, if any
sphere.Clear(); sphere.Clear();
// Is the specified string empty? // Is the specified string empty?
if (!str || *str == '\0') if (str.mLen <= 0)
{ {
return sphere; // Return the value as is! return sphere; // Return the value as is!
} }
@ -491,7 +491,7 @@ const Sphere & Sphere::Get(CSStr str, SQChar delim)
fs[9] = delim; fs[9] = delim;
fs[14] = delim; fs[14] = delim;
// Attempt to extract the component values from the specified string // Attempt to extract the component values from the specified string
std::sscanf(str, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad); std::sscanf(str.mPtr, fs, &sphere.pos.x, &sphere.pos.y, &sphere.pos.z, &sphere.rad);
// Return the resulted value // Return the resulted value
return sphere; return sphere;
} }
@ -573,19 +573,18 @@ void Register_Sphere(HSQUIRRELVM vm)
.Func(_SC("SetValues"), &Sphere::SetValues) .Func(_SC("SetValues"), &Sphere::SetValues)
.Func(_SC("SetPosition"), &Sphere::SetPosition) .Func(_SC("SetPosition"), &Sphere::SetPosition)
.Func(_SC("SetPositionEx"), &Sphere::SetPositionEx) .Func(_SC("SetPositionEx"), &Sphere::SetPositionEx)
.Func(_SC("SetStr"), &Sphere::SetStr) .FmtFunc(_SC("SetStr"), &Sphere::SetStr)
.Func(_SC("Clear"), &Sphere::Clear) .Func(_SC("Clear"), &Sphere::Clear)
// Member Overloads // Member Overloads
.Overload< void (Sphere::*)(void) >(_SC("Generate"), &Sphere::Generate) .Overload< void (Sphere::*)(void) >(_SC("Generate"), &Sphere::Generate)
.Overload< void (Sphere::*)(Val, Val, bool) >(_SC("Generate"), &Sphere::Generate) .Overload< void (Sphere::*)(Val, Val, bool) >(_SC("Generate"), &Sphere::Generate)
.Overload< void (Sphere::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Sphere::Generate) .Overload< void (Sphere::*)(Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Sphere::Generate)
.Overload< void (Sphere::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Sphere::Generate) .Overload< void (Sphere::*)(Val, Val, Val, Val, Val, Val, Val, Val) >(_SC("Generate"), &Sphere::Generate)
// Static Overloads
.StaticOverload< const Sphere & (*)(CSStr) >(_SC("FromStr"), &Sphere::Get)
.StaticOverload< const Sphere & (*)(CSStr, SQChar) >(_SC("FromStr"), &Sphere::Get)
// Static Functions // Static Functions
.StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Sphere >) .StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Sphere >)
.StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Sphere >) .StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Sphere >)
.StaticFmtFunc(_SC("FromStr"), &Sphere::Get)
.StaticFmtFunc(_SC("FromStrEx"), &Sphere::GetEx)
// Operator Exposure // Operator Exposure
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opAddAssign"), &Sphere::operator +=) .Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opAddAssign"), &Sphere::operator +=)
.Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opSubAssign"), &Sphere::operator -=) .Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opSubAssign"), &Sphere::operator -=)

View File

@ -376,7 +376,7 @@ struct Sphere
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Set the values extracted from the specified string using the specified delimiter. * 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 a randomly sized and positioned sphere. * Generate a randomly sized and positioned sphere.
@ -414,13 +414,12 @@ struct Sphere
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string. * Extract the values for components of the Sphere type from a string.
*/ */
static const Sphere & Get(CSStr str); static const Sphere & Get(const StackStrF & str);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Extract the values for components of the Sphere type from a string. * Extract the values for components of the Sphere type from a string.
*/ */
static const Sphere & Get(CSStr str, SQChar delim); static const Sphere & GetEx(SQChar delim, const StackStrF & str);
}; };
} // Namespace:: SqMod } // Namespace:: SqMod