triplet.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Copyright (c) 2001 - 2008 Marcus Boerger.  All rights reserved.
00003 *
00004 * This library is free software; you can redistribute it and/or
00005 * modify it under the terms of the GNU Lesser General Public
00006 * License as published by the Free Software Foundation; either
00007 * version 2.1 of the License, or (at your option) any later version.
00008 *
00009 * This library is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 * Lesser General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU Lesser General Public
00015 * License along with this library; if not, write to the Free Software
00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 * ========================================================================= */
00018 
00019 /* ------------------------------------------------------------------------ */
00030 /* ------------------------------------------------------------------------ */
00031 
00032 #pragma once
00033 
00034 #ifndef _TRIPLET_H_
00035 #define _TRIPLET_H_
00036 
00037 #include <utility>
00038 
00039 namespace mbo
00040 {
00041 
00042 /****************************************************************************/
00043 
00046 template<typename _Ty1, typename _Ty2, typename _Ty3>
00047 struct triplet: public std::pair<_Ty1, _Ty2>
00048 {
00049     typedef std::pair<_Ty1, _Ty2>     _Mybase;
00050     typedef triplet<_Ty1, _Ty2, _Ty3> _Myt;
00051     typedef _Ty3 third_type;
00052 
00053     triplet()
00054         : _Mybase()
00055         , third(_Ty3())
00056     {
00057     }
00058 
00059     triplet(const _Ty1& val1, const _Ty2& val2, const _Ty3& val3)
00060         : _Mybase(val1, val2)
00061         , third(val3)
00062     {
00063     }
00064 
00065     template<typename _O1, typename _O2, typename _O3>
00066     triplet(const triplet<_O1, _O2, _O3>& rhs)
00067         : _Mybase(rhs.first, rhs.second)
00068         , third(rhs.third)
00069     {
00070     }
00071 
00072     void swap(_Myt& rhs)
00073     {
00074         std::swap(first,  rhs.first);
00075         std::swap(second, rhs.second);
00076         std::swap(third,  rhs.third);
00077     }
00078 
00079     third_type   third;
00080 };
00081 
00082 template<typename _Ty1, typename _Ty2, typename _Ty3>
00083 inline bool __cdecl operator == (const triplet<_Ty1, _Ty2, _Ty3>& lhs, const triplet<_Ty1, _Ty2, _Ty3>& rhs)
00084 {
00085     return (lhs.first == rhs.first && lsh.second == rhs.second && lsh.third == rhs.third);
00086 }
00087 
00088 template<typename _Ty1, typename _Ty2, typename _Ty3>
00089 inline bool __cdecl operator != (const triplet<_Ty1, _Ty2, _Ty3>& lhs, const triplet<_Ty1, _Ty2, _Ty3>& rhs)
00090 {
00091     return (!(lhs == rhs));
00092 }
00093 
00094 template<typename _Ty1, typename _Ty2, typename _Ty3>
00095 inline bool __cdecl operator < (const triplet<_Ty1, _Ty2, _Ty3>& lhs, const triplet<_Ty1, _Ty2, _Ty3>& rhs)
00096 {
00097     return lhs::pair < rhs::pair  ||
00098         (!(rhs.first < lhs.first) && lhs.second < rhs.second) ||
00099         (!(rhs.first < lhs.first) && !(rhs.second < lhs.second) && lhs.third < rhs.third)
00100         ;
00101 }
00102 
00103 template<typename _Ty1, typename _Ty2, typename _Ty3>
00104 inline bool __cdecl operator > (const triplet<_Ty1, _Ty2, _Ty3>& lhs, const triplet<_Ty1, _Ty2, _Ty3>& rhs)
00105 {
00106     return (rhs < lhs);
00107 }
00108 
00109 template<typename _Ty1, typename _Ty2, typename _Ty3>
00110 inline bool __cdecl operator <= (const triplet<_Ty1, _Ty2, _Ty3>& lhs, const triplet<_Ty1, _Ty2, _Ty3>& rhs)
00111 {
00112     return (!(rhs < lhs));
00113 }
00114 
00115 template<typename _Ty1, typename _Ty2, typename _Ty3>
00116 inline bool __cdecl operator >= (const triplet<_Ty1, _Ty2, _Ty3>& lhs, const triplet<_Ty1, _Ty2, _Ty3>& rhs)
00117 {
00118     return (!(lhs < rhs));
00119 }
00120 
00121 template<typename _Ty1, typename _Ty2, typename _Ty3>
00122 inline triplet<_Ty1, _Ty2, _Ty3> __cdecl make_triplet(_Ty1 val1, _Ty2 val2, _Ty3 val3)
00123 {
00124     return (triplet<_Ty1, _Ty2, _Ty3>(val1, val2, val3));
00125 }
00126 
00127 template<typename _Ty1, typename _Ty2, typename _Ty3>
00128 inline void swap(triplet<_Ty1, _Ty2, _Ty3>& lhs, triplet<_Ty1, _Ty2, _Ty3>& rhs)
00129 {
00130     lhs.swap(rhs);
00131 }
00132 
00133 } // namespace mbo
00134 
00135 #endif // _TRIPLET_H_

  Hosted on code.google.com  
© Marcus Börger
Generated on Fri Jan 18 21:21:08 2008 for MBO-lib by doxygen 1.5.4