osbid.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.15 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _OSBID_H_
00031 #define _OSBID_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include<iosfwd>
00037 #include<functional>
00038 
00039 // + libraries
00040 
00041 // + local headers
00042 #include "osbconst.h"
00043 
00044 // ************************************************************************
00045 // namespace extensions
00046 namespace OSB_LIB {
00047 
00048 // ************************************************************************
00049 // class definitions
00086     template<typename T> struct Id {
00087     public:
00091         explicit Id(long id = ID_NOT_SET) : id_(id) {}
00093         long id() const { return id_; }
00095         bool notSet() const { return ID_NOT_SET == id_; }
00097         bool isSet() const { return !notSet(); }
00102         bool operator==(const Id& rhs) const { return id_ == rhs.id_; }
00103         bool operator!=(const Id& rhs) const { return id_ != rhs.id_; }
00104         bool operator< (const Id& rhs) const { return id_ <  rhs.id_; }
00105         bool operator> (const Id& rhs) const { return id_ >  rhs.id_; }
00106         bool operator<=(const Id& rhs) const { return id_ <= rhs.id_; }
00107         bool operator>=(const Id& rhs) const { return id_ >= rhs.id_; }
00109     private:
00111         long id_;
00112     };
00113 
00115     template<typename T>
00116     std::ostream& operator<<(std::ostream& o, Id<T> id)
00117     {
00118         return o << id.id();
00119     }
00120 
00135     template<typename I> struct Id2 {
00137         Id2() : id1_(ID_NOT_SET), id2_(ID_NOT_SET) {}
00139         explicit Id2(long id1) : id1_(id1), id2_(ID_NOT_SET) {}
00141         Id2(long id1, long id2) : id1_(id1), id2_(id2) {}
00142 
00148         bool isSet() const
00149         {
00150             return ID_NOT_SET != id1_ || ID_NOT_SET != id2_;
00151         }
00157         bool notSet() const { return !isSet(); }
00159         bool id1Set() const { return ID_NOT_SET != id1_; }
00161         bool id2Set() const { return ID_NOT_SET != id2_; }
00162 
00168         bool operator==(const Id2& rhs) const
00169         {
00170             return id1_ == rhs.id1_ && id2_ == rhs.id2_;
00171         }
00172 
00173         bool operator!=(const Id2& rhs) const
00174         {
00175             return !(*this == rhs);
00176         }
00177 
00178         bool operator<(const Id2& rhs) const
00179         {
00180             return id1_ == rhs.id1_ ?
00181                    id2_ < rhs.id2_  :
00182                    id1_ < rhs.id1_;
00183         }
00184 
00185         bool operator>(const Id2& rhs) const
00186         {
00187             return rhs < *this;
00188         }
00189 
00190         bool operator<=(const Id2& rhs) const
00191         {
00192             return !(rhs < *this);
00193         }
00194 
00195         bool operator>=(const Id2& rhs) const
00196         {
00197             return !(*this < rhs);
00198         }
00200 
00201     public:
00203         long id1_;
00205         long id2_;
00206     };
00207 
00209     template<typename I>
00210     std::ostream& operator<<(std::ostream& o, Id2<I> id)
00211     {
00212         return o << id.id1_ << '.' << id.id2_;
00213     }
00214 
00221     template < class T, class Oid =Id<T> >
00222     class MatchOid : public std::unary_function <T, bool> {
00223         Oid oid_;
00224     public:
00225         explicit MatchOid(const Oid& oid) : oid_(oid) {}
00226         bool operator() (const T& t) const { return t.oid() == oid_; }
00227     };
00228 
00235     template<class T, class Oid>
00236     class MatchOid<T*, Oid> : public std::unary_function<T*, bool> {
00237         Oid oid_;
00238     public:
00239         explicit MatchOid(const Oid& oid) : oid_(oid) {}
00240         bool operator() (const T* t) const { return t->oid() == oid_; }
00241     };
00242 }                                       // namespace OSB_LIB
00243 #endif                                  // #ifndef _OSBID_H_

Generated on Sat Sep 2 14:06:33 2006 for OSB Library by  doxygen 1.4.7