00001 #ifndef GSGL_DATA_TUPLE_H 00002 #define GSGL_DATA_TUPLE_H 00003 00004 // 00005 // $Id: tuple.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "data/data.hpp" 00038 #include "data/exception.hpp" 00039 #include "data/comparable.hpp" 00040 00041 namespace gsgl 00042 { 00043 00044 namespace data 00045 { 00046 00047 template <typename T, typename U> 00048 class pair 00049 : public data_object 00050 { 00051 public: 00052 T first; 00053 U second; 00054 00055 pair(); 00056 pair(const T & first, const U & second); 00057 pair(const pair<T,U> & p); 00058 pair<T,U> & operator= (const pair<T,U> & p); 00059 virtual ~pair(); 00060 00061 bool operator== (const pair<T,U> & p) const 00062 { 00063 return first == p.first && second == p.second; 00064 } 00065 }; // class pair 00066 00067 00068 // 00069 00070 template <typename T, typename U> 00071 pair<T,U>::pair() 00072 : data_object() 00073 { 00074 } // pair<T,U>::pair() 00075 00076 00077 template <typename T, typename U> 00078 pair<T,U>::pair(const T & first, const U & second) 00079 : data_object(), first(first), second(second) 00080 { 00081 } // pair<T,U>::pair() 00082 00083 00084 template <typename T, typename U> 00085 pair<T,U>::pair(const pair<T,U> & p) 00086 : data_object(), first(p.first), second(p.second) 00087 { 00088 } // pair<T,U>::pair() 00089 00090 00091 template <typename T, typename U> 00092 pair<T,U> & pair<T,U>::operator= (const pair<T,U> & p) 00093 { 00094 first = p.first; 00095 second = p.second; 00096 00097 return *this; 00098 } // pair<T,U>::operator= () 00099 00100 00101 template <typename T, typename U> 00102 pair<T,U>::~pair() 00103 { 00104 } // pair<T,U>::~pair() 00105 00106 00107 //template <typename T, typename U> 00108 //int pair<T,U>::compare(const comparable & p) const 00109 //{ 00110 // const pair<T,U> *pp = dynamic_cast<const pair<T,U> *>(&p); 00111 00112 // if (pp) 00113 // { 00114 // if (first < pp->first) 00115 // return -1; 00116 // if (first > pp->first) 00117 // return 1; 00118 // if (second < pp->second) 00119 // return -1; 00120 // if (second > pp->second) 00121 // return 1; 00122 00123 // return 0; 00124 // } 00125 // else 00126 // { 00127 // throw internal_exception(__FILE__, __LINE__, L"attempt to compare unlike types"); 00128 // } 00129 //} // pair<T,U>::compare() 00130 00131 } // namespace data 00132 00133 } // namespace data 00134 00135 #endif