bsstorage.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00009 /*
00010   AUTHOR(S): Tang Boon Leong (tbl)
00011              Stephan Broennimann (vb)
00012 
00013   RCS information
00014    $Name: OSB_060808 $
00015    $Revision: 1.35 $
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 _BSSTORAGE_H_
00035 #define _BSSTORAGE_H_
00036 
00037 // *********************************************************************
00038 // included header files
00039 // + standard includes
00040 #include <iosfwd>
00041 #include <map>
00042 #include <vector>
00043 
00044 // + local headers
00045 #include "cdrlist.h"
00046 #include "contract.h"
00047 #include "balancesheet.h"
00048 
00049 // *********************************************************************
00050 // class declarations
00051 namespace OSB_DB {
00052     class Session;
00053 }
00054 
00055 namespace OSB_LIB {
00056     class BsPage;
00057     template<typename T> class Id;
00058 }
00059 
00060 // *********************************************************************
00061 // namespace extensions
00062 namespace OSB_LIB {
00063 
00064 // *********************************************************************
00065 // type definitions
00066 
00067 // *********************************************************************
00068 // class definitions
00075     class BsStorage {
00076     public:
00077         // Defined and documented after this class.
00078         class ContainerIter;
00083         friend class ContainerIter;
00084 
00085     private:
00087         struct BsCdrs {
00089             BsCdrs() {};
00090 
00092             BsCdrs(const Contract::Oid& coId) : bs_(BalanceSheet(coId)) {};
00093 
00095             BalanceSheet bs_;
00096 
00098             CdrList cdrs_;
00099         };
00101         typedef std::map<Contract::Oid, BsCdrs> BsMap;
00102 
00103     public:
00105         BsStorage() : numCdrs_(0) {}
00112         void reset();
00113 
00121         void insertBs(const Contract::Oid& coId);
00122 
00131         BalanceSheet& getBs(const Contract::Oid& coId);
00132 
00140         void eraseBs(const Contract::Oid& coId);
00141 
00147         void addCdr(const Cdr& cdr);
00148 
00157         void lockBs(
00158             const OSB_DB::Session& session
00159         );
00160 
00170         void assignCdrs(
00171             const OSB_DB::Session& session
00172         );
00173 
00184         void writeCdrs(
00185             long             recoveryId,
00186             OSB_DB::Session& session,
00187             Asn1Writer&      writer
00188         );
00189 
00196         void updateBs(
00197             const OSB_DB::Session& session
00198         );
00199 
00208         bool restoreCdrs(OSB_DB::Session& session);
00209 
00211         void setUnlocked();
00212 
00224         void clearRecoveryId(const OSB_DB::Session& session);
00225 
00236         void commitCdrs();
00237 
00239         long numBs() const;
00240 
00247         long numCdrs() const { return numCdrs_; }
00248 
00250         ContainerIter containerBegin();
00251 
00253         ContainerIter containerEnd();
00254     private:
00266         BsMap bsMap_;
00268         long numCdrs_;
00269     };                                  // class BsStorage
00270 
00271     // *****************************************************************
00272     // class BsStorage::ContainerIter
00276     class BsStorage::ContainerIter {
00277     public:
00279         explicit ContainerIter(BsMap::const_iterator mIter);
00280 
00287         ContainerIter(BsMap::const_iterator mIter,
00288                       BsMap::const_iterator mIter2);
00289 
00291         const CdrList& operator*() const;
00292 
00294         bool operator==(const ContainerIter& rhs) const;
00295 
00297         bool operator!=(const ContainerIter& rhs) const;
00298 
00300         ContainerIter& operator++();
00301     private:
00303         BsMap::const_iterator mIter_;
00304 
00306         BsMap::const_iterator mIterEnd_;
00307     };                                  // class BsStorage::ContainerIter
00308 }                                       // namespace OSB_LIB
00309 #endif                                  // #ifndef _BSSTORAGE_H_

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