Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

KeyPair.h

Go to the documentation of this file.
00001 #ifndef ANP_KEYPAIR_H
00002 #define ANP_KEYPAIR_H
00003 
00004 #include <iostream>
00005 
00006 namespace Anp
00007 {
00008    template <typename T>
00009       class KeyPair
00010    {
00011    public:
00012       
00013       KeyPair();
00014       KeyPair(const T key1, const T key2);
00015       ~KeyPair() {}
00016 
00017       bool SetKeys(const T key1, const T key2);
00018 
00019       const T Key1() const { return fKey1; }
00020       const T Key2() const { return fKey2; }
00021       
00022       bool operator<(const KeyPair &rhs) const;
00023       
00024       void Print() const;
00025       void Print(std::ostream& o) const;
00026 
00027    private:
00028       
00029       bool fInit;
00030 
00031       T fKey1;
00032       T fKey2;
00033    };
00034 
00035 #ifndef __CINT__
00036 
00037    //---------------------------------------------------------------------------
00038    template <typename T>
00039       KeyPair<T>::KeyPair()
00040       :fInit(false), fKey1(), fKey2()
00041    {
00042    }
00043 
00044    //---------------------------------------------------------------------------
00045    template <typename T>
00046       KeyPair<T>::KeyPair(const T key1, const T key2)      
00047       :fInit(true), fKey1(key1), fKey2(key2)
00048    {
00049    }
00050 
00051 
00052    //---------------------------------------------------------------------------
00053    template <typename T>
00054       bool KeyPair<T>::SetKeys(const T key1, const T key2)
00055    {
00056       if(!fInit)
00057       {
00058          fInit = true; fKey1 = key1; fKey2 = key2;
00059          return true;
00060       }
00061 
00062       std::cerr << "This KeyPair is already set" << std::endl;
00063       return false;
00064    }
00065    
00066    //---------------------------------------------------------------------------
00067    template <typename T>
00068       inline bool KeyPair<T>::operator<(const KeyPair &rhs) const
00069    {
00070       if(fKey1 < rhs.fKey1)
00071       {
00072          return true;
00073       }
00074       else if(rhs.fKey1 < fKey1)
00075       {
00076          return false;
00077       }
00078       else if(fKey2 < rhs.fKey2)
00079       {
00080          return true;
00081       }
00082 
00083       return false;
00084    }
00085 
00086    //---------------------------------------------------------------------------
00087    template <typename T>
00088       void KeyPair<T>::Print(std::ostream& o) const
00089    {
00090       o << "KeyPair: key 1 = " << fKey1 << " and key 2 = " << fKey2 << std::endl;
00091    }
00092 
00093    //---------------------------------------------------------------------------
00094    template <typename T>
00095       void KeyPair<T>::Print() const
00096    {
00097       this -> Print(std::cout);
00098    }
00099 
00100    //---------------------------------------------------------------------------
00101    template <typename T>
00102       std::ostream& operator<<(std::ostream& o, const KeyPair<T> &self)
00103    {
00104       self.Print(o);
00105       return o;
00106    }
00107 
00108 #endif
00109 }
00110 
00111 #endif

Generated on Mon Feb 15 11:06:50 2010 for loon by  doxygen 1.3.9.1