|
Sierra Toolkit
Version of the Day
|
00001 /* 00002 Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without 00005 modification, are permitted provided that the following conditions 00006 are met: 00007 00008 1. Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 2. Redistributions in binary form must reproduce the above copyright 00011 notice, this list of conditions and the following disclaimer in the 00012 documentation and/or other materials provided with the distribution. 00013 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 00014 its contributors may be used to endorse or promote products derived 00015 from this software without specific prior written permission. 00016 00017 THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 00018 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 00021 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00030 // EASTL/utility.h 00031 // Written and maintained by Paul Pedriana - 2005. 00033 00034 00035 00036 #ifndef EASTL_UTILITY_H 00037 #define EASTL_UTILITY_H 00038 00039 00040 #include <stk_util/util/config_eastl.h> 00041 00042 00043 #ifdef _MSC_VER 00044 #pragma warning(push) // VC++ generates a bogus warning that you cannot code away. 00045 #pragma warning(disable: 4619) // There is no warning number 'number'. 00046 #pragma warning(disable: 4217) // Member template functions cannot be used for copy-assignment or copy-construction. 00047 #pragma warning(disable: 4512) // 'class' : assignment operator could not be generated. // This disabling would best be put elsewhere. 00048 #endif 00049 00050 00051 namespace eastl 00052 { 00053 00067 namespace rel_ops 00068 { 00069 template <typename T> 00070 inline bool operator!=(const T& x, const T& y) 00071 { return !(x == y); } 00072 00073 template <typename T> 00074 inline bool operator>(const T& x, const T& y) 00075 { return (y < x); } 00076 00077 template <typename T> 00078 inline bool operator<=(const T& x, const T& y) 00079 { return !(y < x); } 00080 00081 template <typename T> 00082 inline bool operator>=(const T& x, const T& y) 00083 { return !(x < y); } 00084 } 00085 00086 00087 00093 template <typename T1, typename T2> 00094 struct pair 00095 { 00096 typedef T1 first_type; 00097 typedef T2 second_type; 00098 00099 T1 first; 00100 T2 second; 00101 00102 pair(); 00103 pair(const T1& x); 00104 pair(const T1& x, const T2& y); 00105 00106 template <typename U, typename V> 00107 pair(const pair<U, V>& p); 00108 00109 // pair(const pair& p); // Not necessary, as default version is OK. 00110 // pair& operator=(const pair& p); // Not necessary, as default version is OK. 00111 }; 00112 00113 00114 00115 00126 template <typename T> 00127 struct use_self // : public unary_function<T, T> // Perhaps we want to make it a subclass of unary_function. 00128 { 00129 typedef T result_type; 00130 00131 const T& operator()(const T& x) const 00132 { return x; } 00133 }; 00134 00142 template <typename Pair> 00143 struct use_first // : public unary_function<Pair, typename Pair::first_type> // Perhaps we want to make it a subclass of unary_function. 00144 { 00145 typedef typename Pair::first_type result_type; 00146 00147 const result_type& operator()(const Pair& x) const 00148 { return x.first; } 00149 }; 00150 00156 template <typename Pair> 00157 struct use_second // : public unary_function<Pair, typename Pair::second_type> // Perhaps we want to make it a subclass of unary_function. 00158 { 00159 typedef typename Pair::second_type result_type; 00160 00161 const result_type& operator()(const Pair& x) const 00162 { return x.second; } 00163 }; 00164 00165 00166 00167 00168 00170 // pair 00172 00173 template <typename T1, typename T2> 00174 inline pair<T1, T2>::pair() 00175 : first(), second() 00176 { 00177 // Empty 00178 } 00179 00180 00181 template <typename T1, typename T2> 00182 inline pair<T1, T2>::pair(const T1& x) 00183 : first(x), second() 00184 { 00185 // Empty 00186 } 00187 00188 00189 template <typename T1, typename T2> 00190 inline pair<T1, T2>::pair(const T1& x, const T2& y) 00191 : first(x), second(y) 00192 { 00193 // Empty 00194 } 00195 00196 00197 template <typename T1, typename T2> 00198 template <typename U, typename V> 00199 inline pair<T1, T2>::pair(const pair<U, V>& p) 00200 : first(p.first), second(p.second) 00201 { 00202 // Empty 00203 } 00204 00205 00206 00207 00209 // global operators 00211 00212 template <typename T1, typename T2> 00213 inline bool operator==(const pair<T1, T2>& a, const pair<T1, T2>& b) 00214 { 00215 return ((a.first == b.first) && (a.second == b.second)); 00216 } 00217 00218 00219 template <typename T1, typename T2> 00220 inline bool operator<(const pair<T1, T2>& a, const pair<T1, T2>& b) 00221 { 00222 // Note that we use only operator < in this expression. Otherwise we could 00223 // use the simpler: return (a.m1 == b.m1) ? (a.m2 < b.m2) : (a.m1 < b.m1); 00224 // The user can write a specialization for this operator to get around this 00225 // in cases where the highest performance is required. 00226 return ((a.first < b.first) || (!(b.first < a.first) && (a.second < b.second))); 00227 } 00228 00229 00230 template <typename T1, typename T2> 00231 inline bool operator!=(const pair<T1, T2>& a, const pair<T1, T2>& b) 00232 { 00233 return !(a == b); 00234 } 00235 00236 00237 template <typename T1, typename T2> 00238 inline bool operator>(const pair<T1, T2>& a, const pair<T1, T2>& b) 00239 { 00240 return b < a; 00241 } 00242 00243 00244 template <typename T1, typename T2> 00245 inline bool operator>=(const pair<T1, T2>& a, const pair<T1, T2>& b) 00246 { 00247 return !(a < b); 00248 } 00249 00250 00251 template <typename T1, typename T2> 00252 inline bool operator<=(const pair<T1, T2>& a, const pair<T1, T2>& b) 00253 { 00254 return !(b < a); 00255 } 00256 00257 00258 00259 00275 template <typename T1, typename T2> 00276 inline pair<T1, T2> make_pair(T1 a, T2 b) 00277 { 00278 return pair<T1, T2>(a, b); 00279 } 00280 00281 00282 template <typename T1, typename T2> 00283 inline pair<T1, T2> make_pair_ref(const T1& a, const T2& b) 00284 { 00285 return pair<T1, T2>(a, b); 00286 } 00287 00288 00289 } // namespace eastl 00290 00291 00292 #ifdef _MSC_VER 00293 #pragma warning(pop) 00294 #endif 00295 00296 00297 #endif // Header include guard