osbunit.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00010 /*
00011   AUTHOR(S): Narendranath Reddy (nr)
00012 
00013   RCS information
00014    $Name: OSB_060808 $
00015    $Revision: 1.26.2.1 $
00016 
00017   License
00018    OSB rating and billing library for communication networks
00019    Copyright (C) 2004, 2005, 2006  OSB systems
00020 
00021    This file may be distributed and/or modify under the terms of the
00022    GNU General Public License (GPL) as published by the Free Software
00023    Foundation which is provided in the file LICENSE.GPL included in the
00024    packaging of this file.
00025 
00026    The file is distributed in the hope that it will be useful, but WITHOUT
00027    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00028    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00029    for more details.
00030 
00031    Holders of a OSB Commercial License may use this file under the terms
00032    and conditions of this commercial license.
00033  */
00034 #ifndef _OSBUNIT_H_
00035 #define _OSBUNIT_H_
00036 
00037 // ************************************************************************
00038 // included header files
00039 // + standard includes
00040 #include<string>
00041 #include<map>
00042 
00043 // + local headers
00044 #include "osbtype.h"
00045 
00046 // ************************************************************************
00047 // class declarations
00048 namespace OSB_LIB {
00049     class Decimal;
00050 }
00051 
00052 namespace OSB_DB {
00053     class  Session;
00054     struct UnitGw;
00055 }
00056 
00057 // ************************************************************************
00058 // namespace extensions
00059 namespace OSB_LIB {
00060 
00061 // ************************************************************************
00062 // class definitions
00063     class Unit {
00064         friend class OSB_DB::UnitGw;
00065     public:
00067         typedef TypeId<Unit> Oid;
00071         enum UnitId {
00072             uiSeconds      =  1,
00073             uiMinutes      =  2,
00074             uiHours        =  3,
00075             uiDays         =  4,
00076             uiMonths       =  5,
00077             uiYears        =  6,
00078             uiBilledPeriod =  7,
00079             uiBytes        =  8,
00080             uiMessages     =  9,
00081             uiMax          = uiMessages
00082         };
00083     public:
00085         static UnitId unitId(const Oid& oid);
00086     public:
00088         Oid oid() const;
00090         UnitId unitId() const;
00092         const std::string& name() const;
00093 
00095         static bool canConvert(
00096             const Oid& lhs,
00097             const Oid& rhs
00098         );
00110         static Decimal convert(
00111             const Oid&     lhs,
00112             const Oid&     rhs,
00113             const Decimal& value
00114         );
00115 
00116     private:
00118         Oid oid_;
00120         std::string name_;
00121     };
00122 
00126     class UnitList {
00128         friend class OSB_DB::UnitGw;
00129     public:
00131         typedef std::map<Unit::Oid, Unit> Cont;
00133         typedef Cont::const_iterator ConstIterator;
00134     public:
00136         size_t size() const;
00138         ConstIterator begin() const;
00140         ConstIterator end() const;
00147         size_t read(const OSB_DB::Session& session);
00155         const Unit& getUnit(const Unit::Oid& oid) const;
00163         Unit::Oid getUnit(const std::string& name) const;
00164     private:
00165         Cont cont_;
00166     };
00167 }                                       // namespace OSB_LIB
00168 #endif                                  // #ifndef _OSBUNIT_H_

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