Pair.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 /************************************************************************
00032  * Pair.h: definition of pairs for dictionaries and sets.
00033 ************************************************************************/
00034 
00035 #if defined(external_templates)
00036 #pragma interface
00037 #endif
00038 
00039 #if !defined(_Pair_h_)
00040 #define _Pair_h_
00041 
00042 //#ifdef STL...
00043 //#include <stl.h>
00044 //#else
00045 
00046 /************************************************************************
00047  * template<class T1, class T2> struct pdpair
00048 ************************************************************************/
00049 
00050 // Note that pdpaired classes must provide operator== and operator<
00051 
00052 template<class T1, class T2>
00053 struct pdpair {
00054  public: //needed so nt build doesn't think members are private
00055   T1 first;
00056   T2 second;
00057 
00058   bool operator==(const pdpair<T1, T2>& p) {
00059     return (first == p.first) && (second == p.second); 
00060   }
00061   bool operator!=(const pdpair<T1, T2>& p) {
00062     return !((first == p.first) && (second == p.second));
00063   }
00064   /*
00065   bool operator<(const pdpair<T1, T2>& p) { 
00066     return (first < p.first) || (!(p.first < first) && second < p.second); 
00067   }
00068   bool operator>(const pdpair<T1, T2>& p) {
00069     return (p.first < first) || (!(first < p.first) && p.second < second);
00070   }
00071   */
00072   pdpair () : first(), second()                                    {}
00073   pdpair (const T1& k) : first(k), second(0)                       {}
00074   pdpair (const T1& k, const T2& v) : first(k), second(v)          {}
00075   pdpair(const pdpair<T1, T2>& p) : first(p.first), second(p.second) {}
00076 };
00077 
00078 // Return a T1 pair containing the min and max elements of a  vector of
00079 // type T2<T1>. If the vector contains no elements a 0,0 pair is returned.
00080 template <class T1, class T2>
00081 pdpair<T1, T1> min_max_pdpair (const T2 & vect)
00082 {
00083     if (vect.size() == 0) {
00084     T1 def = 0;
00085     return pdpair<T1,T1>(def, def);
00086     }
00087 
00088     if (vect.size() == 1) {
00089     return pdpair<T1,T1>(vect[0], vect[0]);
00090     }
00091     
00092     T1 min = vect[0];
00093     T1 max = vect[0];
00094   
00095     for (unsigned int i = 0; i < vect.size (); i++) {
00096     if (vect[i] < min)
00097         min = vect[i];
00098     
00099     if (vect[i] > max)
00100         max = vect[i];
00101     }
00102     
00103     return pdpair<T1,T1>(min, max);
00104 }
00105 
00106 //#endif
00107 
00108 #endif /* !defined(_PDPair_h_) */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1