OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4SortObjectReverse Class Reference

#include <C4FindObject.h>

Inheritance diagram for C4SortObjectReverse:
[legend]
Collaboration diagram for C4SortObjectReverse:
[legend]

Public Member Functions

 C4SortObjectReverse (C4SortObject *pSort)
 
 ~C4SortObjectReverse () override
 
void SortObjects (C4ValueArray *pArray)
 

Static Public Member Functions

static C4SortObjectCreateByValue (const C4Value &Data, const C4Object *context=nullptr)
 
static C4SortObjectCreateByValue (int32_t iType, const C4ValueArray &Data, const C4Object *context=nullptr)
 

Protected Member Functions

int32_t Compare (C4Object *pObj1, C4Object *pObj2) override
 
bool PrepareCache (const C4ValueArray *pObjs) override
 
int32_t CompareCache (int32_t iObj1, int32_t iObj2, C4Object *pObj1, C4Object *pObj2) override
 

Detailed Description

Definition at line 455 of file C4FindObject.h.

Constructor & Destructor Documentation

C4SortObjectReverse::C4SortObjectReverse ( C4SortObject pSort)
inline

Definition at line 458 of file C4FindObject.h.

459  : C4SortObject(), pSort(pSort) {}
C4SortObject()=default
C4SortObjectReverse::~C4SortObjectReverse ( )
override

Definition at line 986 of file C4FindObject.cpp.

987 {
988  delete pSort;
989 }

Member Function Documentation

int32_t C4SortObjectReverse::Compare ( C4Object pObj1,
C4Object pObj2 
)
overrideprotectedvirtual

Implements C4SortObject.

Definition at line 991 of file C4FindObject.cpp.

References C4SortObject::Compare().

992 {
993  return pSort->Compare(pObj2, pObj1);
994 }
virtual int32_t Compare(C4Object *pObj1, C4Object *pObj2)=0

Here is the call graph for this function:

int32_t C4SortObjectReverse::CompareCache ( int32_t  iObj1,
int32_t  iObj2,
C4Object pObj1,
C4Object pObj2 
)
overrideprotectedvirtual

Reimplemented from C4SortObject.

Definition at line 1001 of file C4FindObject.cpp.

References C4SortObject::CompareCache().

1002 {
1003  return pSort->CompareCache(iObj2, iObj1, pObj2, pObj1);
1004 }
virtual int32_t CompareCache(int32_t iObj1, int32_t iObj2, C4Object *pObj1, C4Object *pObj2)
Definition: C4FindObject.h:426

Here is the call graph for this function:

C4SortObject * C4SortObject::CreateByValue ( const C4Value Data,
const C4Object context = nullptr 
)
staticinherited

Definition at line 851 of file C4FindObject.cpp.

References C4Value::getArray().

Referenced by C4FindObject::CreateByValue(), and C4SortObject::CreateByValue().

852 {
853  // Must be an array
854  const C4ValueArray *pArray = C4Value(DataVal).getArray();
855  if (!pArray) return nullptr;
856  const C4ValueArray &Data = *pArray;
857  int32_t iType = Data[0].getInt();
858  return CreateByValue(iType, Data, context);
859 }
C4ValueArray * getArray() const
Definition: C4Value.h:118
static C4SortObject * CreateByValue(const C4Value &Data, const C4Object *context=nullptr)

Here is the call graph for this function:

Here is the caller graph for this function:

C4SortObject * C4SortObject::CreateByValue ( int32_t  iType,
const C4ValueArray Data,
const C4Object context = nullptr 
)
staticinherited

Definition at line 861 of file C4FindObject.cpp.

References C4SO_Distance, C4SO_Func, C4SO_Mass, C4SO_Multiple, C4SO_Random, C4SO_Reverse, C4SO_Speed, C4SO_Value, C4SortObject::CreateByValue(), C4ValueArray::GetSize(), C4Object::GetX(), C4Object::GetY(), iSize, and C4SortObjectFunc::SetPar().

862 {
863  switch (iType)
864  {
865  case C4SO_Reverse:
866  {
867  // create child sort
868  C4SortObject *pChildSort = C4SortObject::CreateByValue(Data[1], context);
869  if (!pChildSort) return nullptr;
870  // wrap
871  return new C4SortObjectReverse(pChildSort);
872  }
873 
874  case C4SO_Multiple:
875  {
876  // Trivial case (one sort)
877  if (Data.GetSize() == 2)
878  {
879  return C4SortObject::CreateByValue(Data[1], context);
880  }
881  // Create all children
882  int32_t i;
883  C4SortObject **ppSorts = new C4SortObject *[Data.GetSize() - 1];
884  for (i = 0; i < Data.GetSize() - 1; i++)
885  {
886  ppSorts[i] = C4SortObject::CreateByValue(Data[i+1], context);
887  }
888  // Count real entries, move them to start of list
889  int32_t iSize = 0;
890  for (i = 0; i < Data.GetSize() - 1; i++)
891  if (ppSorts[i])
892  if (iSize++ != i)
893  ppSorts[iSize-1] = ppSorts[i];
894  // Create
895  return new C4SortObjectMultiple(iSize, ppSorts);
896  }
897 
898  case C4SO_Distance:
899  {
900  int32_t x = Data[1].getInt();
901  int32_t y = Data[2].getInt();
902  if (context)
903  {
904  x += context->GetX();
905  y += context->GetY();
906  }
907  return new C4SortObjectDistance(x, y);
908  }
909 
910  case C4SO_Random:
911  return new C4SortObjectRandom();
912 
913  case C4SO_Speed:
914  return new C4SortObjectSpeed();
915 
916  case C4SO_Mass:
917  return new C4SortObjectMass();
918 
919  case C4SO_Value:
920  return new C4SortObjectValue();
921 
922  case C4SO_Func:
923  {
924  // Get function name
925  C4String *pStr = Data[1].getStr();
926  if (!pStr) return nullptr;
927  // Construct
928  C4SortObjectFunc *pSO = new C4SortObjectFunc(pStr);
929  // Add parameters
930  for (int i = 2; i < Data.GetSize(); i++)
931  pSO->SetPar(i - 2, Data[i]);
932  // Done
933  return pSO;
934  }
935 
936  }
937  return nullptr;
938 }
int32_t GetY() const
Definition: C4Object.h:288
int32_t GetX() const
Definition: C4Object.h:287
int32_t GetSize() const
Definition: C4ValueArray.h:36
static C4SortObject * CreateByValue(const C4Value &Data, const C4Object *context=nullptr)
void SetPar(int i, const C4Value &val)
int iSize
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

bool C4SortObjectReverse::PrepareCache ( const C4ValueArray pObjs)
overrideprotectedvirtual

Reimplemented from C4SortObject.

Definition at line 996 of file C4FindObject.cpp.

References C4SortObject::PrepareCache().

997 {
998  return pSort->PrepareCache(pObjs);
999 }
virtual bool PrepareCache(const C4ValueArray *pObjs)
Definition: C4FindObject.h:425

Here is the call graph for this function:

void C4SortObject::SortObjects ( C4ValueArray pArray)
inherited

Definition at line 940 of file C4FindObject.cpp.

References C4ValueArray::Sort().

Referenced by C4FindObject::FindMany().

941 {
942  pArray->Sort(*this);
943 }
void Sort(class C4SortObject &rSort)

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: