00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 #ifndef lestes___equality_hh___included 00029 #define lestes___equality_hh___included 00030 00031 /*! \file 00032 \brief Equality templates. 00033 00034 Defines equality and comparison templates. 00035 Attempt for unified handling of simple types and objects. 00036 A call of the template on simple types dispatches to the respective operator, 00037 while a call on objects dispatches to a respective method. 00038 NULL values for objects are supported. 00039 \author pt 00040 */ 00041 00042 #include <lestes/common.hh> 00043 00044 package(lestes); 00045 00046 /*! 00047 Tests equality of two values of arbitrary types. 00048 \param Left The type of the left operand. 00049 \param Right The type of the right operand. 00050 \param left The first value to compare. 00051 \param right The second value to compare. 00052 \return true If both values are is_equal. 00053 */ 00054 template <typename Left, typename Right> 00055 bool is_equal(const Left &left, const Right &right) 00056 { 00057 return left == right; 00058 } 00059 00060 /*! 00061 Tests equality of two values of arbitrary ptr types. 00062 \param Left The type of the pointee of the left operand. 00063 \param Right The type of the pointee of the right operand. 00064 \param left The first value to compare. 00065 \param right The second value to compare. 00066 \return true If both values are null or equals returns true. 00067 */ 00068 template <typename Left, typename Right> 00069 bool is_equal(const ptr<Left> &left, const ptr<Right> &right) 00070 { 00071 // either both are null, or method call succeeded 00072 if (!left) return !right; 00073 return left->equals(right); 00074 } 00075 00076 /*! 00077 Tests equality of two values of arbitrary ptr types. 00078 \param Left The type of the pointee of the left operand. 00079 \param Right The type of the pointee of the right operand. 00080 \param left The first value to compare. 00081 \param right The second value to compare. 00082 \return true If both values are null or equals returns true. 00083 */ 00084 template <typename Left, typename Right> 00085 bool is_equal(const srp<Left> &left, const ptr<Right> &right) 00086 { 00087 // either both are null, or method call succeeded 00088 if (!left) return !right; 00089 return left->equals(right); 00090 } 00091 00092 /*! 00093 Tests equality of two values of arbitrary ptr types. 00094 \param Left The type of the pointee of the left operand. 00095 \param Right The type of the pointee of the right operand. 00096 \param left The first value to compare. 00097 \param right The second value to compare. 00098 \return true If both values are null or equals returns true. 00099 */ 00100 template <typename Left, typename Right> 00101 bool is_equal(const srp<Left> &left, const srp<Right> &right) 00102 { 00103 // either both are null, or method call succeeded 00104 if (!left) return !right; 00105 return left->equals(right); 00106 } 00107 00108 /*! 00109 Tests equality of two values of arbitrary ptr types. 00110 \param Left The type of the pointee of the left operand. 00111 \param Right The type of the pointee of the right operand. 00112 \param left The first value to compare. 00113 \param right The second value to compare. 00114 \return true If both values are null or equals returns true. 00115 */ 00116 template <typename Left, typename Right> 00117 bool is_equal(const ptr<Left> &left, const srp<Right> &right) 00118 { 00119 // either both are null, or method call succeeded 00120 if (!left) return !right; 00121 return left->equals(right); 00122 } 00123 00124 /*! 00125 Tests inequality of two values of arbitrary types. 00126 \param Left The type of the left operand. 00127 \param Right The type of the right operand. 00128 \param first The first value to compare. 00129 \param second The second value to compare. 00130 \return true If first < second. 00131 */ 00132 template <typename Left, typename Right> 00133 bool is_less(const Left &left, const Right &right) 00134 { 00135 return left < right; 00136 } 00137 /*! 00138 Tests inequality of two values of arbitrary ptr types. 00139 \param Left The type of the pointee of the left operand. 00140 \param Right The type of the pointee of the right operand. 00141 \param left The first value to compare. 00142 \param right The second value to compare. 00143 \return true If only left operand is null or left->less_than(right). 00144 */ 00145 template <typename Left, typename Right> 00146 bool is_less(const ptr<Left> &left, const ptr<Right> &right) 00147 { 00148 // either left is null so right decides 00149 if (!left) return right; 00150 // or method call decides 00151 return left->less_than(right); 00152 } 00153 00154 end_package(lestes); 00155 00156 #endif 00157 /* vim: set ft=lestes : */
1.5.1-20070107