From 99da8892a4a71668819d3a6afd315e4694efdabf Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 24 Aug 2016 18:47:18 +0300 Subject: [PATCH] Implement dynamic comparison for the Routine type. --- source/Routine.cpp | 20 ++--------- source/Routine.hpp | 90 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 71 insertions(+), 39 deletions(-) diff --git a/source/Routine.cpp b/source/Routine.cpp index feafd2ff..dd5da1b4 100644 --- a/source/Routine.cpp +++ b/source/Routine.cpp @@ -595,23 +595,6 @@ Routine::~Routine() Forget(this); } -// ------------------------------------------------------------------------------------------------ -Int32 Routine::Cmp(const Routine & o) const -{ - if (m_Interval == o.m_Interval) - { - return 0; - } - else if (m_Interval > o.m_Interval) - { - return 1; - } - else - { - return -1; - } -} - // ------------------------------------------------------------------------------------------------ CSStr Routine::ToString() const { @@ -1002,8 +985,9 @@ void Register_Routine(HSQUIRRELVM vm) RootTable(vm).Bind(_SC("SqRoutine"), Class< Routine, NoConstructor< Routine > >(vm, _SC("SqRoutine")) // Meta-methods - .Func(_SC("_cmp"), &Routine::Cmp) .SquirrelFunc(_SC("_typename"), &Routine::Typename) + // We cannot set _cmp for c++ classes so we use this instead + .SquirrelFunc(_SC("cmp"), &SqCmpFwd< Routine, SQInteger, SQFloat, bool, CSStr, std::nullptr_t, Routine >) .Func(_SC("_tostring"), &Routine::ToString) // Properties .Prop(_SC("Tag"), &Routine::GetTag, &Routine::SetTag) diff --git a/source/Routine.hpp b/source/Routine.hpp index a7e7f75b..c3dbd8bf 100644 --- a/source/Routine.hpp +++ b/source/Routine.hpp @@ -147,26 +147,6 @@ private: Routine(Object & env, Function & func, Interval interval, Iterator iterations , Object & a1, Object & a2, Object & a3, Object & a4, Object & a5); - /* -------------------------------------------------------------------------------------------- - * Copy constructor. (disabled) - */ - Routine(const Routine & o) = delete; - - /* -------------------------------------------------------------------------------------------- - * Move constructor. (disabled) - */ - Routine(Routine && o) = delete; - - /* -------------------------------------------------------------------------------------------- - * Copy assignment operator. (disabled) - */ - Routine & operator = (const Routine & o) = delete; - - /* -------------------------------------------------------------------------------------------- - * Move assignment operator. (disabled) - */ - Routine & operator = (Routine && o) = delete; - private: /* -------------------------------------------------------------------------------------------- @@ -222,15 +202,83 @@ private: public: + /* -------------------------------------------------------------------------------------------- + * Copy constructor. (disabled) + */ + Routine(const Routine & o) = delete; + + /* -------------------------------------------------------------------------------------------- + * Move constructor. (disabled) + */ + Routine(Routine && o) = delete; + /* -------------------------------------------------------------------------------------------- * Destructor. */ ~Routine(); + /* -------------------------------------------------------------------------------------------- + * Copy assignment operator. (disabled) + */ + Routine & operator = (const Routine & o) = delete; + + /* -------------------------------------------------------------------------------------------- + * Move assignment operator. (disabled) + */ + Routine & operator = (Routine && o) = delete; + /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare two instances of this type. */ - Int32 Cmp(const Routine & o) const; + Int32 Cmp(const Routine & o) const + { + return Cmp(static_cast< SQInteger >(o.m_Interval)); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with an integer. + */ + Int32 Cmp(SQInteger interval) const + { + if (m_Interval == interval) return 0; + else if (m_Interval > interval) return 1; + else return -1; + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with an float. + */ + Int32 Cmp(SQFloat interval) const + { + return Cmp(static_cast< SQInteger >(interval)); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with an string. + */ + Int32 Cmp(CSStr tag) const + { + return m_Tag.compare(tag); + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a boolean. + */ + Int32 Cmp(bool suspended) const + { + if (m_Suspended == suspended) return 0; + else if (m_Suspended > suspended) return 1; + else return -1; + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a null pointer. + */ + Int32 Cmp(std::nullptr_t) const + { + if (m_Terminated == true) return 0; + else return 1; + } /* -------------------------------------------------------------------------------------------- * Used by the script engine to convert an instance of this type to a string.