osbmsgcat.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.7 $
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 _OSBMSGCAT_H_
00031 #define _OSBMSGCAT_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <map>
00037 
00038 // + libraries
00039 
00040 // + local headers
00041 #include "osberror.h"
00042 #include "mutex.h"
00043 
00044 // + class declarations
00045 
00046 // ************************************************************************
00047 // namespace extensions
00048 namespace OSB_LIB {
00049 
00050 // ************************************************************************
00051 // forward declarations
00052     class ErrList;
00053 
00054 // ************************************************************************
00055 // type definitions
00056 
00057 // ************************************************************************
00058 // class definitions
00059 
00063     class MsgCat {
00064     public:
00069         struct Init {
00079             Init(bool useLocks);
00080         };                              // struct Init
00082         friend struct Init;
00083 
00084     public:
00086         static void useLocks();
00087 
00091         static void msg(
00092             const BaseError&   e,
00093                   std::string& dest
00094         );
00095 
00097         static MsgCat& instance();
00098 
00099     public:
00103         void mkMsg(
00104             const BaseError&   e,
00105                   std::string& dest
00106         );
00107 
00108     private:
00116         MsgCat();
00118         ~MsgCat();
00120         MsgCat(const MsgCat&);
00121 
00122     private:
00124         Guard lock();
00126         ErrList& errList(const BaseError& e);
00127 
00128     private:
00130         typedef std::map<std::string, ErrList*> ErrLists;
00131 
00139         bool useLocks_;
00141         Mutex mutex_;
00143         MutexUnlock unlock_;
00145         ErrLists errLists_;
00146 
00147     private:
00152         struct Destroy {
00154             ~Destroy();
00155         };                              // struct Destroy
00157         friend struct Destroy;
00158 
00159     private:
00161         static Destroy destroy_;
00163         static MsgCat* instance_;
00164     };                                  // class MsgCat
00165 
00173     class ErrList {
00175         friend class MsgCat;
00176     public:
00178         const std::string& errMsg() const
00179         {
00180             return errMsg_;
00181         }
00182 
00197         bool mkErrorMsg(
00198                   std::string&       dest,
00199                   BaseError::ErrorNo errNo,
00200             const BaseError::Args&   errArgs
00201         ) const;
00202 
00203     private:
00205         typedef std::vector<std::string> BaseText;
00207         typedef std::map<BaseError::ErrorNo, BaseText> TextMap;
00208 
00210         ErrList(const std::string& filename);
00212         ErrList(const ErrList&);
00214         ErrList& operator=(const ErrList&);
00215 
00223         void separate(
00224                   BaseText&    dest,
00225             const std::string& errStr
00226         );
00227 
00235         const BaseText* getText(OsbBaseError::ErrorNo errNo) const;
00236 
00245         void compose(
00246                   std::string&     dest,
00247             const BaseText&        text,
00248             const BaseError::Args& errArgs
00249         ) const;
00250 
00259         void compose(
00260                   std::string&     dest,
00261             const std::string&     errMsg,
00262             const BaseError::Args& errArgs
00263         ) const;
00264 
00266         TextMap textMap_;
00268         std::string errMsg_;
00269     };                                  // class ErrList
00270 }                                       // namespace OSB_LIB
00271 
00272 // ************************************************************************
00273 // inline definitions
00274 namespace OSB_LIB {
00275 }                                       // namespace OSB_LIB
00276 #endif                                  // #ifndef _OSBMSGCAT_H_

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