osbtype.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.19 $
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 _OSBTYPE_H_
00031 #define _OSBTYPE_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <ostream>
00037 
00038 // + libraries
00039 
00040 // + local headers
00041 
00042 // ************************************************************************
00043 // class declarations
00044 
00045 // ************************************************************************
00046 // namespace extensions
00047 namespace OSB_LIB {
00048 
00049 // ************************************************************************
00050 // class definitions
00120     template<typename T, int ST = 1> class TypeId {
00121     public:                                 // construction
00129         explicit TypeId(long type = notSet_) : type_(type)
00130         {
00131             if (!notSet()) {
00132                 if (   type_ < minType_
00133                     || type_ > maxType_) type_ = unknown_;
00134             }
00135         }
00136     public:
00138         static long minType() { return minType_; }
00140         static long maxType() { return maxType_; }
00142         static TypeId mkUnknown() { return TypeId(unknown_); }
00143     public:
00150         bool valid() const
00151         {
00152             return type_ != notSet_ && type_ != unknown_;
00153         }
00155         bool notSet() const
00156         {
00157             return type_ == notSet_;
00158         }
00160         bool unKnown() const
00161         {
00162             return type_ == unknown_;
00163         }
00165         bool operator==(const TypeId& rhs) const
00166         {
00167             return type_ == rhs.type_;
00168         }
00170         bool operator!=(const TypeId& rhs) const
00171         {
00172             return !operator==(rhs);
00173         }
00175         bool operator<(const TypeId& rhs) const
00176         {
00177             return type_ < rhs.type_;
00178         }
00179     public:
00189         long toLong() const
00190         {
00191             return type_;
00192         }
00193     private:
00195         long type_;
00196     private:
00198         static const long notSet_  = 0;
00200         static const long unknown_ = -1;
00209         static const long minType_;
00218         static const long maxType_;
00219     };
00220 
00222     template<typename T, int ST>
00223     inline std::ostream& operator<<(
00224               std::ostream&  os,
00225         const TypeId<T, ST>& t
00226     )
00227     {
00228         return os << t.toLong();
00229     }
00230 }                                       // namespace OSB_LIB
00231 
00232 // ************************************************************************
00233 // inline definitions
00234 namespace OSB_LIB {
00235     template<typename T, int ST> const long TypeId<T, ST>::notSet_;
00236     template<typename T, int ST> const long TypeId<T, ST>::unknown_;
00237 }                                       // namespace OSB_LIB
00238 #endif                                  // #ifndef _OSBTYPE_H_
00239 

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