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

Implement dynamic comparison for the Routine type.

This commit is contained in:
Sandu Liviu Catalin 2016-08-24 18:47:18 +03:00
parent d31c77341c
commit 99da8892a4
2 changed files with 71 additions and 39 deletions

View File

@ -595,23 +595,6 @@ Routine::~Routine()
Forget(this); 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 CSStr Routine::ToString() const
{ {
@ -1002,8 +985,9 @@ void Register_Routine(HSQUIRRELVM vm)
RootTable(vm).Bind(_SC("SqRoutine"), RootTable(vm).Bind(_SC("SqRoutine"),
Class< Routine, NoConstructor< Routine > >(vm, _SC("SqRoutine")) Class< Routine, NoConstructor< Routine > >(vm, _SC("SqRoutine"))
// Meta-methods // Meta-methods
.Func(_SC("_cmp"), &Routine::Cmp)
.SquirrelFunc(_SC("_typename"), &Routine::Typename) .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) .Func(_SC("_tostring"), &Routine::ToString)
// Properties // Properties
.Prop(_SC("Tag"), &Routine::GetTag, &Routine::SetTag) .Prop(_SC("Tag"), &Routine::GetTag, &Routine::SetTag)

View File

@ -147,26 +147,6 @@ private:
Routine(Object & env, Function & func, Interval interval, Iterator iterations Routine(Object & env, Function & func, Interval interval, Iterator iterations
, Object & a1, Object & a2, Object & a3, Object & a4, Object & a5); , 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: private:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
@ -222,15 +202,83 @@ private:
public: public:
/* --------------------------------------------------------------------------------------------
* Copy constructor. (disabled)
*/
Routine(const Routine & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor. (disabled)
*/
Routine(Routine && o) = delete;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Destructor. * Destructor.
*/ */
~Routine(); ~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. * 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. * Used by the script engine to convert an instance of this type to a string.