SundanceOrderedTuple.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_ORDEREDTUPLE_H
00032 #define SUNDANCE_ORDEREDTUPLE_H
00033 
00034 #include "SundanceDefs.hpp"
00035 
00036 
00037 #ifndef DOXYGEN_DEVELOPER_ONLY
00038 
00039 namespace Sundance
00040 {
00041   using namespace Teuchos;
00042 
00043   /** OrderedPair provides a means of lexigraphic comparison of a pair of
00044    * objects. The pair {a1, b1} is compared to {a2, b2} by first
00045    * comparing the most significant entries a1 and a2, and if they are
00046    * equal, comparing the least significant entries b1 and b2. */
00047   template<class A, class B>
00048     class OrderedPair
00049     {
00050     public:
00051       /** */
00052       OrderedPair(const A& _a, const B& _b)
00053         : a_(_a), b_(_b) {;}
00054 
00055       /** */
00056       inline bool operator<(const OrderedPair<A, B>& other) const
00057         {
00058           if ( a_ < other.a_ ) 
00059             {
00060               return true;
00061             }
00062           if ( other.a_ < a_) 
00063             {
00064               return false;
00065             }
00066 
00067           bool rtn = b_ < other.b_;
00068           return rtn;
00069         }
00070 
00071       /** */
00072       const A& first() const {return a_;}
00073 
00074       /** */
00075       const B& second() const {return b_;}
00076 
00077     private:
00078       A a_;
00079       B b_;
00080     };
00081 
00082   /** Lexigraphically-comparable triple of objects. */
00083   template<class A, class B, class C>
00084     class OrderedTriple : public OrderedPair<A, OrderedPair<B, C> >
00085     {
00086     public:
00087       /** */
00088       OrderedTriple(const A& _a, const B& _b, const C& _c)
00089         : OrderedPair<A, OrderedPair<B, C> >(_a, OrderedPair<B,C>(_b,_c))
00090         {;}
00091 
00092       const A& a() const {return this->first();}
00093 
00094       const B& b() const {return this->second().first();}
00095 
00096       const C& c() const {return this->second().second();}
00097     };
00098 
00099   /** Lexigraphically-comparable quartet of objects. */
00100   template<class A, class B, class C, class D>
00101     class OrderedQuartet : public OrderedPair<A, OrderedTriple<B, C, D> >
00102     {
00103     public:
00104       /** */
00105       OrderedQuartet(const A& _a, const B& _b, const C& _c, const D& _d)
00106         : OrderedPair<A, OrderedTriple<B, C, D> >(_a, OrderedTriple<B,C,D>(_b,_c,_d))
00107         {;}
00108 
00109       const A& a() const {return this->first();}
00110       const B& b() const {return this->second().first();}
00111       const C& c() const {return this->second().second().first();}
00112       const D& d() const {return this->second().second().second();}
00113     };
00114 
00115   /** */
00116   template <class A, class B>
00117   inline std::ostream& operator<<(std::ostream& os, const OrderedPair<A,B>& p)
00118   {
00119     os << "{" << p.first() << ", " << p.second() << "}";
00120     return os;
00121   }
00122 
00123 }
00124 
00125 
00126 #endif /* DOXYGEN_DEVELOPER_ONLY */
00127 #endif

Site Contact