library of assembled shared sources |
http://lass.cocamware.com |
00001 /** @file 00002 * @author Bram de Greve (bramz@users.sourceforge.net) 00003 * @author Tom De Muer (tomdemuer@users.sourceforge.net) 00004 * 00005 * *** BEGIN LICENSE INFORMATION *** 00006 * 00007 * The contents of this file are subject to the Common Public Attribution License 00008 * Version 1.0 (the "License"); you may not use this file except in compliance with 00009 * the License. You may obtain a copy of the License at 00010 * http://lass.sourceforge.net/cpal-license. The License is based on the 00011 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 00012 * use of software over a computer network and provide for limited attribution for 00013 * the Original Developer. In addition, Exhibit A has been modified to be consistent 00014 * with Exhibit B. 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 00017 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific 00018 * language governing rights and limitations under the License. 00019 * 00020 * The Original Code is LASS - Library of Assembled Shared Sources. 00021 * 00022 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer. 00023 * The Original Developer is the Initial Developer. 00024 * 00025 * All portions of the code written by the Initial Developer are: 00026 * Copyright (C) 2004-2007 the Initial Developer. 00027 * All Rights Reserved. 00028 * 00029 * Contributor(s): 00030 * 00031 * Alternatively, the contents of this file may be used under the terms of the 00032 * GNU General Public License Version 2 or later (the GPL), in which case the 00033 * provisions of GPL are applicable instead of those above. If you wish to allow use 00034 * of your version of this file only under the terms of the GPL and not to allow 00035 * others to use your version of this file under the CPAL, indicate your decision by 00036 * deleting the provisions above and replace them with the notice and other 00037 * provisions required by the GPL License. If you do not delete the provisions above, 00038 * a recipient may use your version of this file under either the CPAL or the GPL. 00039 * 00040 * *** END LICENSE INFORMATION *** 00041 */ 00042 00043 namespace lass 00044 { 00045 namespace stde 00046 { 00047 00048 // --- public -------------------------------------------------------------------------------------- 00049 00050 00051 /** default constructor 00052 * The default constructor creates a vlaue triple with triples that are initialized by the 00053 * default constructor of their type. Because of language rules, an explicit call of a default 00054 * constructor also initializes fundamental data types such as @c int. 00055 */ 00056 template <typename T1, typename T2, typename T3> 00057 triple<T1, T2, T3>::triple(): 00058 first(T1()), 00059 second(T2()), 00060 third(T3()) 00061 { 00062 } 00063 00064 00065 00066 /** constructor for three values 00067 */ 00068 template <typename T1, typename T2, typename T3> 00069 triple<T1, T2, T3>::triple(typename util::CallTraits<T1>::TParam a, 00070 typename util::CallTraits<T2>::TParam b, 00071 typename util::CallTraits<T3>::TParam c): 00072 first(a), 00073 second(b), 00074 third(c) 00075 { 00076 } 00077 00078 00079 00080 /** copy constructor with implicit conversions 00081 * This template version of the copy constructor provided here is ussed when implicit 00082 * conversions are necessary. If an object of type Triple gets copied, the normal implicitly 00083 * generated default copy constructor is called, which is nice. 00084 */ 00085 template <typename T1, typename T2, typename T3> 00086 template <typename U1, typename U2, typename U3> 00087 triple<T1, T2, T3>::triple(const triple<U1, U2, U3>& other): 00088 first(other.first), 00089 second(other.second), 00090 third(other.third) 00091 { 00092 } 00093 00094 00095 00096 // --- protected ----------------------------------------------------------------------------------- 00097 00098 00099 00100 // --- private ------------------------------------------------------------------------------------- 00101 00102 00103 00104 // --- free ---------------------------------------------------------------------------------------- 00105 00106 /** two triples are identical if all elements (first, second, third) are identical. 00107 * @relates triple 00108 */ 00109 template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3> 00110 bool operator==(const triple<T1, T2, T3>& x, const triple<U1, U2, U3>& y) 00111 { 00112 return x.first == y.first && x.second == y.second && x.third == y.third; 00113 } 00114 00115 /** return true if x is "less" than y. 00116 * @relates triple 00117 * 00118 * As for std::pair, the "less than" comparison is implemented for Triples in a similar way. 00119 * The first value has higher priority than the second and third, and the second value has higher 00120 * priority than the third. Thus, if the first values of two pairs differ, the result of their 00121 * comparison is used as the result of the comparison of the whole triples. If the first values 00122 * are equal, the comparison of the second values yields the result if they differ. If the 00123 * second values are equal too, the comparison of the third values finally yields the result. 00124 */ 00125 template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3> 00126 bool operator<(const triple<T1, T2, T3>& x, const triple<U1, U2, U3>& y) 00127 { 00128 return x.first < y.first || (!(y.first < x.first) && 00129 (x.second < y.second || (!(y.second < x.second) && x.third < y.third))); 00130 } 00131 00132 /** equivalent to !(x == y), see operator< 00133 * @relates triple 00134 */ 00135 template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3> 00136 bool operator!=(const triple<T1, T2, T3>& x, const triple<U1, U2, U3>& y) 00137 { 00138 return !(x == y); 00139 } 00140 00141 /** equivalent to y < x, see operator< 00142 * @relates triple 00143 */ 00144 template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3> 00145 bool operator>(const triple<T1, T2, T3>& x, const triple<U1, U2, U3>& y) 00146 { 00147 return y < x; 00148 } 00149 00150 /** equivalent to !(y < x), see operator< 00151 * @relates triple 00152 */ 00153 template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3> 00154 bool operator<=(const triple<T1, T2, T3>& x, const triple<U1, U2, U3>& y) 00155 { 00156 return !(y < x); 00157 } 00158 00159 /** equivalent to !(x < y), see operator< 00160 * @relates triple 00161 */ 00162 template <typename T1, typename T2, typename T3, typename U1, typename U2, typename U3> 00163 bool operator>=(const triple<T1, T2, T3>& x, const triple<U1, U2, U3>& y) 00164 { 00165 return !(x < y); 00166 } 00167 00168 00169 00170 /* 00171 * @relates triple 00172 */ 00173 template <typename T1, typename T2, typename T3> 00174 std::ostream& operator<<(std::ostream& stream, const triple<T1, T2, T3>& x) 00175 { 00176 return stream << "(" << x.first << ", " << x.second << ", " << x.third << ")"; 00177 } 00178 00179 00180 00181 /** convenience function to create a lass::stde::triple. 00182 * @relates triple 00183 * 00184 * The make_triple template function enables you to create a value triple without writing the 00185 * types explicitly. In particular the make_triple function makes it convenient to pass three 00186 * values of a triple directly to a function that requires a triple as its argument. 00187 * It works even when the types do not match exactly becuase the template copy constructor 00188 * provides implicit type conversion. 00189 * 00190 * using make_triple should cost no runtime. The compiler should always optimize any implied 00191 * overhead. 00192 */ 00193 template <typename T1, typename T2, typename T3> 00194 triple<T1, T2, T3> make_triple(const T1& a, const T2& b, const T3& c) 00195 { 00196 return triple<T1, T2, T3>(a, b, c); 00197 } 00198 00199 00200 00201 } 00202 00203 } 00204 00205 // EOF
Generated on Mon Nov 10 14:22:01 2008 for Library of Assembled Shared Sources by 1.5.7.1 |