[5284] | 1 | // comparable_v.hpp, created on 30.06.2009 by Sebastian Mies
|
---|
| 2 |
|
---|
| 3 | #ifndef COMPARABLE_V_HPP_
|
---|
| 4 | #define COMPARABLE_V_HPP_
|
---|
| 5 |
|
---|
| 6 | #include "vfacade.hpp"
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * TODO: Doc
|
---|
| 10 | *
|
---|
| 11 | * @author Sebastian Mies <mies@tm.uka.de>
|
---|
| 12 | */
|
---|
| 13 | class comparable_v {
|
---|
| 14 | public:
|
---|
| 15 | //--- comparable_v --------------------------------------------------------
|
---|
| 16 |
|
---|
| 17 | /// implements comparison operators
|
---|
| 18 | virtual int compare_to(const comparable_v& rhs) const = 0;
|
---|
| 19 |
|
---|
| 20 | /// convenience method for comparison
|
---|
| 21 | inline int compare_to(const comparable_v* rhs) const {
|
---|
| 22 | return compare_to(*rhs);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /// convenience method for comparison
|
---|
| 26 | inline bool operator==(const comparable_v& rhs) const {
|
---|
| 27 | return compare_to(rhs) == 0;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | /// convenience method for comparison
|
---|
| 31 | inline bool operator!=(const comparable_v& rhs) const {
|
---|
| 32 | return compare_to(rhs) != 0;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | /// convenience method for comparison
|
---|
| 36 | inline bool operator<(const comparable_v& rhs) const {
|
---|
| 37 | return compare_to(rhs) < 0;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /// convenience method for comparison
|
---|
| 41 | inline bool operator<=(const comparable_v& rhs) const {
|
---|
| 42 | return compare_to(rhs) <= 0;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | /// convenience method for comparison
|
---|
| 46 | inline bool operator>(const comparable_v& rhs) const {
|
---|
| 47 | return compare_to(rhs) > 0;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | /// convenience method for comparison
|
---|
| 51 | inline bool operator>=(const comparable_v& rhs) const {
|
---|
| 52 | return compare_to(rhs) >= 0;
|
---|
| 53 | }
|
---|
| 54 | };
|
---|
| 55 |
|
---|
| 56 | typedef vfacade<comparable_v> comparable_vf;
|
---|
| 57 |
|
---|
| 58 | template<class NonVirtual, class AdaptorType>
|
---|
| 59 | class vobject_hull<NonVirtual, comparable_v, AdaptorType> : public comparable_v {
|
---|
| 60 | private:
|
---|
| 61 | typename AdaptorType::template adaptor_type<NonVirtual> obj;
|
---|
| 62 |
|
---|
| 63 | public:
|
---|
| 64 | template<typename T>
|
---|
| 65 | explicit vobject_hull(T& obj) :
|
---|
| 66 | obj(obj) {
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | explicit vobject_hull() :
|
---|
| 70 | obj() {
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | //--- comparable_v --------------------------------------------------------
|
---|
| 74 |
|
---|
| 75 | /// implements comparison operators
|
---|
| 76 | virtual int compare_to(const comparable_v& rhs) const {
|
---|
| 77 | return obj->compare_to(rhs);
|
---|
| 78 | }
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | #endif /* COMPARABLE_V_HPP_ */
|
---|