status.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00020 /*
00021   AUTHOR(S): Stephan Broennimann (vb)
00022 
00023   RCS information
00024    $Name: OSB_060808 $
00025    $Revision: 1.57 $
00026 
00027   License
00028    OSB rating and billing library for communication networks
00029    Copyright (C) 2004, 2005, 2006  OSB systems
00030 
00031    This file may be distributed and/or modify under the terms of the
00032    GNU General Public License (GPL) as published by the Free Software
00033    Foundation which is provided in the file LICENSE.GPL included in the
00034    packaging of this file.
00035 
00036    The file is distributed in the hope that it will be useful, but WITHOUT
00037    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00038    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00039    for more details.
00040 
00041    Holders of a OSB Commercial License may use this file under the terms
00042    and conditions of this commercial license.
00043  */
00044 #ifndef _STATUS_H_
00045 #define _STATUS_H_
00046 
00047 // ************************************************************************
00048 // included header files
00049 // + standard includes
00050 #include <iosfwd>
00051 #include <string>
00052 #include <list>
00053 
00054 // + local headers
00055 #include "chrono.h"
00056 #include "osberror.h"
00057 #include "osbid.h"
00058 
00059 // + class declarations
00060 namespace OSB_DB {
00061     class StatusReasonGw;
00062     class Session;
00063 }
00064 
00065 namespace OSB_LIB {
00066     class StatusChange;
00067 }
00068 
00069 // ************************************************************************
00070 // namespace extensions
00071 namespace OSB_LIB {
00072 
00073 // ************************************************************************
00074 // forward declarations
00075     class Status;                       // needed for toChar(const Status&)
00076 
00077 // ************************************************************************
00078 // type definitions
00079 
00092     enum StatusValue {
00097         svNone        =  0,
00099         svDeactivated =  1,
00101         svCreated     =  2,
00103         svInactive    =  3,
00105         svActive      =  4
00106     };
00107 
00115     char toChar(StatusValue sv);
00116 
00124     char toChar(const Status& s);
00125 
00137     StatusValue statusValue(char c);
00138 
00148     std::ostream& operator<<(std::ostream& o, StatusValue sv);
00149 
00163     bool compatibleStatus(StatusValue parent, StatusValue child);
00164 
00177     StatusValue mkChildStatus(
00178         StatusValue parentEffStatus,
00179         StatusValue childPrefStatus
00180     );
00181 
00200     bool allowed(StatusValue from, StatusValue to);
00201 
00202 // ************************************************************************
00203 // class definitions
00204 
00211     class StatusReason {
00213         friend class OSB_DB::StatusReasonGw;
00214     private:
00216         static const long creationId_ = 1;
00217 
00218     public:
00220         typedef Id<StatusReason> Oid;
00221 
00228         enum Applicable {
00229             notDefined      = -1,       
00230             associate       =  1,       
00231             contract        =  2,       
00232             persProduct     =  4,       
00233             persProductNode =  8,       
00234             all             = 15        
00235         };
00236 
00237     public:
00250         StatusReason(const Oid& oid) :
00251             oid_(oid), applies_(notDefined),
00252             oldStatus_(svNone), newStatus_(svNone) {}
00253     public:
00259         static Oid creation()
00260         {
00261             return Oid(creationId_);
00262         }
00263     public:
00264 
00266         const Oid& oid() const
00267         {
00268             return oid_;
00269         }
00271         const std::string& name() const
00272         {
00273             return name_;
00274         }
00276         const std::string& des()  const
00277         {
00278             return des_;
00279         }
00281         StatusValue oldStatus() const
00282         {
00283             return oldStatus_;
00284         }
00286         StatusValue newStatus() const
00287         {
00288             return newStatus_;
00289         }
00290 
00292         bool operator==(const StatusReason& rhs)
00293         {
00294             return oid_ == rhs.oid_;
00295         }
00296 
00297     private:
00298         Oid         oid_;               
00299         std::string name_;              
00300         std::string des_;               
00301 
00302         Applicable  applies_;
00303         StatusValue oldStatus_;         
00304         StatusValue newStatus_;         
00305     };
00306 
00312     class StatusReasons {
00313     public:
00315 
00316 
00317         typedef std::list<StatusReason> Cont;
00319         typedef Cont::iterator Iterator;
00321         typedef Cont::const_iterator ConstIterator;
00323         typedef Cont::size_type SizeType;
00325 
00326     public:
00335 
00336         Iterator begin()
00337         {
00338             return reasons_.begin();
00339         }
00341         Iterator end()
00342         {
00343             return reasons_.end();
00344         }
00346         ConstIterator begin() const
00347         {
00348             return reasons_.begin();
00349         }
00351         ConstIterator end() const
00352         {
00353             return reasons_.end();
00354         }
00356         SizeType size() const
00357         {
00358             return reasons_.size();
00359         }
00361 
00368         long read(const OSB_DB::Session& session);
00369 
00371         void add(const StatusReason& reason)
00372         {
00373             return reasons_.push_back(reason);
00374         }
00375 
00377         const Cont& reasons() const
00378         {
00379             return reasons_;
00380         }
00381 
00389         const StatusReason* find(const StatusReason::Oid& oid);
00390 
00398         const StatusReason& get(const StatusReason::Oid& oid);
00399 
00409         bool get(StatusReason&            dest,
00410                  const StatusReason::Oid& oid);
00411 
00412     private:
00414         Cont reasons_;
00415     };                                  // class StatusReasons
00416 
00417     // ********************************************************************
00418     // TheStatusReasons
00430     class TheStatusReasons {
00431     public:
00438         static StatusReasons& instance();
00439 
00440     private:
00442         TheStatusReasons();
00444         TheStatusReasons(const TheStatusReasons& rhs);
00445 
00447         static StatusReasons* instance_;
00448     };                                  // TheStatusReasons
00449 
00456     class Status {
00457     public:
00463         Status();
00470         Status(
00471                   StatusValue        status,
00472             const StatusReason::Oid& reason
00473         );
00474 
00475     public:
00477         StatusValue status() const;
00479         StatusReason::Oid reason() const;
00480 
00487         std::ostream& write(std::ostream& os) const;
00488 
00496         bool operator==(const Status& rhs) const;
00497 
00505         bool operator==(const StatusReason::Oid& rhs) const;
00506 
00514         bool operator!=(const Status& rhs) const;
00515 
00528         bool changeStatus(
00529                   StatusValue        newStatus,
00530             const StatusReason::Oid& reasonId
00531         );
00532 
00539         bool changeStatus(const Status& newStatus);
00540 
00547         bool changeStatus(const StatusChange& sc);
00548 
00549     private:
00551         StatusValue status_;
00553         StatusReason::Oid reasonId_;
00554     };                                  // class Status
00555 
00565     std::ostream& operator<<(std::ostream& os,
00566                              const Status& s);
00567 }                                       // namespace OSB_LIB
00568 
00569 // ************************************************************************
00570 // inline definitions
00571 namespace OSB_LIB {
00572     // ********************************************************************
00573     // Status
00574     inline Status::Status()
00575       : status_(svNone)
00576     {
00577         // empty
00578     }
00579 
00580     inline StatusValue Status::status() const
00581     {
00582         return status_;
00583     }
00584 
00585     inline StatusReason::Oid Status::reason() const
00586     {
00587         return reasonId_;
00588     }
00589 
00590     inline bool Status::operator==(const Status& rhs) const
00591     {
00592         return (   status_   == rhs.status_
00593                 && reasonId_ == rhs.reasonId_);
00594     }
00595 
00596     inline bool Status::operator==(const StatusReason::Oid& rhs) const
00597     {
00598         return (reasonId_ == rhs);
00599     }
00600 
00601     inline bool Status::operator!=(const Status& rhs) const
00602     {
00603         return !(*this == rhs);
00604     }
00605 
00606     inline bool Status::changeStatus(
00607         const Status& newStatus
00608     )
00609     {
00610         return changeStatus(newStatus.status_,
00611                             newStatus.reasonId_);
00612     }
00613 }                                       // namespace OSB_LIB
00614 #endif                                  // #ifndef _STATUS_H_

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