From 759318d48e34be74b3fa868539651b5edff3387e Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 16 Nov 2016 16:19:38 +0200 Subject: [PATCH] Adjust the Sphere type functions to use the new method of receiving formatted strings. --- source/Base/Sphere.cpp | 21 ++++++++++----------- source/Base/Sphere.hpp | 7 +++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/source/Base/Sphere.cpp b/source/Base/Sphere.cpp index ae8f748f..3035feea 100644 --- a/source/Base/Sphere.cpp +++ b/source/Base/Sphere.cpp @@ -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 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 sphere.Clear(); // Is the specified string empty? - if (!str || *str == '\0') + if (str.mLen <= 0) { return sphere; // Return the value as is! } @@ -491,7 +491,7 @@ const Sphere & Sphere::Get(CSStr str, SQChar delim) fs[9] = delim; fs[14] = delim; // 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 sphere; } @@ -573,19 +573,18 @@ void Register_Sphere(HSQUIRRELVM vm) .Func(_SC("SetValues"), &Sphere::SetValues) .Func(_SC("SetPosition"), &Sphere::SetPosition) .Func(_SC("SetPositionEx"), &Sphere::SetPositionEx) - .Func(_SC("SetStr"), &Sphere::SetStr) + .FmtFunc(_SC("SetStr"), &Sphere::SetStr) .Func(_SC("Clear"), &Sphere::Clear) // Member Overloads .Overload< void (Sphere::*)(void) >(_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, 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 .StaticFunc(_SC("GetDelimiter"), &SqGetDelimiter< Sphere >) .StaticFunc(_SC("SetDelimiter"), &SqSetDelimiter< Sphere >) + .StaticFmtFunc(_SC("FromStr"), &Sphere::Get) + .StaticFmtFunc(_SC("FromStrEx"), &Sphere::GetEx) // Operator Exposure .Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opAddAssign"), &Sphere::operator +=) .Func< Sphere & (Sphere::*)(const Sphere &) >(_SC("opSubAssign"), &Sphere::operator -=) diff --git a/source/Base/Sphere.hpp b/source/Base/Sphere.hpp index 127330b6..c62b68da 100644 --- a/source/Base/Sphere.hpp +++ b/source/Base/Sphere.hpp @@ -376,7 +376,7 @@ struct Sphere /* -------------------------------------------------------------------------------------------- * 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. @@ -414,13 +414,12 @@ struct Sphere /* -------------------------------------------------------------------------------------------- * 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. */ - static const Sphere & Get(CSStr str, SQChar delim); - + static const Sphere & GetEx(SQChar delim, const StackStrF & str); }; } // Namespace:: SqMod