KISSCPP
a C++ library for rapid application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
errorstate.hpp
Go to the documentation of this file.
1 // File : errorstates.hpp
2 // Author: Dirk J. Botha <bothadj@gmail.com>
3 //
4 // This file is part of kisscpp library.
5 //
6 // The kisscpp library is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // The kisscpp library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with the kisscpp library. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _ERRORSTATE_HPP_
20 #define _ERRORSTATE_HPP_
21 
22 #include <string>
23 #include <map>
24 #include <vector>
25 #include <boost/algorithm/string.hpp>
26 #include <boost/thread/mutex.hpp>
27 #include <boost/thread/locks.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include "boost_ptree.hpp"
30 #include "logstream.hpp"
31 
32 namespace kisscpp
33 {
34  //--------------------------------------------------------------------------------
35  class ErrorState
36  {
37  public:
38  ErrorState(const std::string &_id, const std::string _description = "") : id(_id), description(_description), count(0) {}
39 
41 
42  void set () { count++; }
43  void clear (const unsigned int &amount = 1) { count = count - amount; }
44  void clear_all () { count = 0; }
45  unsigned int getSetCount () { return count; }
46  bool isSet () { return (count > 0); }
47  std::string getId () { return id; }
48  std::string getDescription() { return description; }
49 
50  protected:
51  private:
52  std::string id;
53  std::string description;
54  unsigned int count;
55  };
56 
57  typedef boost::shared_ptr<ErrorState> SharedErrorState;
58  typedef std::map<std::string, SharedErrorState> ErrorStateMapType;
59  typedef ErrorStateMapType::iterator ErrorStateMapTypeIterator;
60 
61  typedef std::vector<SharedErrorState> ErrorList;
62  typedef boost::shared_ptr<ErrorList> SharedErrorList;
63  typedef ErrorList::iterator ErrorListIterator;
64 
65  //--------------------------------------------------------------------------------
67  {
68  public:
69  static ErrorStateList* instance();
70 
71  ~ErrorStateList() { kisscpp::LogStream log(__PRETTY_FUNCTION__); }
72 
73  void set (const std::string &id, const std::string &description = "");
74  void clear (const std::string &id, const unsigned int &amount = 1);
75  void clear_all(const std::string &id);
77 
78  protected:
79  private:
80  ErrorStateList () { kisscpp::LogStream log(__PRETTY_FUNCTION__); } // Private to prevent copying.
81  ErrorStateList (ErrorStateList const&){ kisscpp::LogStream log(__PRETTY_FUNCTION__); }; // Private to prevent copying.
82  ErrorStateList& operator=(ErrorStateList const&){ kisscpp::LogStream log(__PRETTY_FUNCTION__); }; // Private to prevent assignment.
83 
84  static ErrorStateList *singleton_instance;
85 
86  ErrorStateMapType errorStateMap;
87  boost::mutex errorMutex;
88  };
89 }
90 
91 #endif // _ERRORSTATE_HPP_
92 
std::string getDescription()
Definition: errorstate.hpp:48
Definition: errorstate.hpp:66
bool isSet()
Definition: errorstate.hpp:46
ErrorStateMapType::iterator ErrorStateMapTypeIterator
Definition: errorstate.hpp:59
std::map< std::string, SharedErrorState > ErrorStateMapType
Definition: errorstate.hpp:58
void set()
Definition: errorstate.hpp:42
ErrorState(const std::string &_id, const std::string _description="")
Definition: errorstate.hpp:38
unsigned int getSetCount()
Definition: errorstate.hpp:45
void clear_all()
Definition: errorstate.hpp:44
~ErrorState()
Definition: errorstate.hpp:40
void set(const std::string &id, const std::string &description="")
Definition: errorstate.cpp:36
std::string getId()
Definition: errorstate.hpp:47
boost::shared_ptr< ErrorList > SharedErrorList
Definition: errorstate.hpp:62
boost::shared_ptr< ErrorState > SharedErrorState
Definition: errorstate.hpp:57
Definition: errorstate.hpp:35
Definition: logstream.hpp:145
void clear_all(const std::string &id)
Definition: errorstate.cpp:72
void clear(const std::string &id, const unsigned int &amount=1)
Definition: errorstate.cpp:54
void clear(const unsigned int &amount=1)
Definition: errorstate.hpp:43
~ErrorStateList()
Definition: errorstate.hpp:71
static ErrorStateList * instance()
Definition: errorstate.cpp:26
SharedErrorList getStates()
Definition: errorstate.cpp:90
ErrorList::iterator ErrorListIterator
Definition: errorstate.hpp:63
std::vector< SharedErrorState > ErrorList
Definition: errorstate.hpp:61