Changeset 417 for cafu/trunk

Show
Ignore:
Timestamp:
11/02/11 08:25:12 (7 months ago)
Author:
Carsten
Message:

Added operators == and != to class ArrayT<T>, and replaced the comparison function callback for the QuickSort() method with a template parameter,
so that the compiler can possibly inline the comparison function, and optionally "functors" can be used in their place.

References #31.

Location:
cafu/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/GuiEditor/Commands/SetWinProp.cpp

    r415 r417  
    4646 
    4747    // If the new value isn't different from the old, don't put this command into the command history. 
    48     // if (m_NewValue==m_OldValue) return false; 
     48    if (m_NewValue==m_OldValue) return false; 
    4949 
    5050    m_Value=m_NewValue; 
  • cafu/trunk/Libs/Templates/Array.hpp

    r285 r417  
    2020*/ 
    2121 
    22 /*********************/ 
    23 /*** Array Library ***/ 
    24 /*********************/ 
    25  
    26 #ifndef _CA_ARRAY_HPP_ 
    27 #define _CA_ARRAY_HPP_ 
     22#ifndef _CF_ARRAY_HPP_ 
     23#define _CF_ARRAY_HPP_ 
    2824 
    2925#include <stdlib.h> 
    3026#include <cassert> 
    31  
    32 #if defined(_WIN32) && defined(_MSC_VER) 
    33     #if (_MSC_VER<1300) 
    34         #define for if (false) ; else for 
    35  
    36         // Turn off warning 4786: "Bezeichner wurde auf '255' Zeichen in den Debug-Informationen reduziert." 
    37         #pragma warning(disable:4786) 
    38     #endif 
    39 #endif 
    4027 
    4128 
     
    6249   ~ArrayT();                                                   ///< Destructor 
    6350    ArrayT<T>& operator = (const ArrayT<T>& OldArray);          ///< Assignment operator 
     51    bool operator == (const ArrayT<T>& Other) const;            ///< Equality operator 
     52    bool operator != (const ArrayT<T>& Other) const;            ///< Inequality operator 
    6453 
    6554    unsigned long Size() const;                                 ///< Get size of array 
     
    7867    void          RemoveAt(unsigned long Index); 
    7968    void          RemoveAtAndKeepOrder(unsigned long Index); 
    80     void          QuickSort(bool (*IsLess)(const T& E1, const T& E2)); 
     69    template<typename Function> 
     70    void          QuickSort(Function IsLess); 
    8171 // void          QuickSort(unsigned long FirstIndex, unsigned long LastIndex, bool (*IsLess)(const T& E1, const T& E2)); 
    8272    int           Find(const T& Element) const; 
     
    120110    Elements       =NewElements; 
    121111    return *this; 
     112} 
     113 
     114 
     115template<class T> inline bool ArrayT<T>::operator == (const ArrayT<T>& Other) const 
     116{ 
     117    if (NrOfElements != Other.NrOfElements) 
     118        return false; 
     119 
     120    for (unsigned long Nr=0; Nr<NrOfElements; Nr++) 
     121        if (Elements[Nr] != Other.Elements[Nr]) 
     122            return false; 
     123 
     124    return true; 
     125} 
     126 
     127 
     128template<class T> inline bool ArrayT<T>::operator != (const ArrayT<T>& Other) const 
     129{ 
     130    return !(this->operator == (Other)); 
    122131} 
    123132 
     
    279288 
    280289 
    281 template<class T> inline void ArrayT<T>::QuickSort(bool (*IsLess)(const T& E1, const T& E2)) 
     290template<class T> template<typename Function> inline void ArrayT<T>::QuickSort(Function IsLess) 
    282291{ 
    283292    static ArrayT<unsigned long> ToDoRanges;