source: cpp/gdk/errmanager.h @ 100

Last change on this file since 100 was 66, checked in by Maciej Komosinski, 14 years ago

set 'eol-style' to 'native'

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// This file is a part of the Framsticks GDK library.
2// Copyright (C) 2002-2011  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#ifndef _ERRMANAGER_H_
6#define _ERRMANAGER_H_
7
8#include "list.h"
9#include "sstring.h"
10#include "framsg.h"
11
12class ErrorHandlerBase;
13
14class ErrorManager
15{
16friend class ErrorHandlerBase;
17SListTempl<ErrorHandlerBase*> handlers;
18void send(int level,const char *o,const char *m,const char *bl,int w);
19  public:
20int find(ErrorHandlerBase *r) {return handlers.find(r);}
21int add(ErrorHandlerBase *r);
22void remove(int i);
23void remove(ErrorHandlerBase *r);
24void removeAll();
25void send(const char *o,const char *m,const char *bl,int w)
26        {send(handlers.size()-1,o,m,bl,w);}
27~ErrorManager() {removeAll();}
28};
29
30extern ErrorManager globalErrorManager;
31
32////////////////////////////////////////
33
34class ErrorHandlerBase
35{
36friend class ErrorManager;
37  protected:
38ErrorManager* mgr;
39int options;
40
41  public:
42
43enum HandlerOptions
44 { DontBlock=1, CannotBeBlocked=2, DontEnable=4 };
45
46void FMprintf(const char *o,const char *m,int w,const char *bl, ...);
47void send(const char *o,const char *m,const char *bl,int w);
48
49bool isEnabled() {return mgr?1:0;}
50void enable();
51void disable();
52
53ErrorHandlerBase(int opts=0):options(opts),mgr(0)
54        {if (!(options&DontEnable)) enable();}
55~ErrorHandlerBase()
56        {disable();}
57
58virtual void handle(const char *o,const char *m,const char *bl,int w) {}
59};
60
61///////////////////////////////////////////
62
63class ErrorHandler: public ErrorHandlerBase
64{
65  protected:
66int maxlevel,errcount,warncount,storlevel,storcount,infocount;
67SString msgs;
68
69  public:
70
71void reset() {maxlevel=FMLV_INFO-1; errcount=warncount=storcount=infocount=0; msgs=0;}
72
73enum Options2
74 { StoreFirstMessage=8, StoreAllMessages=16 };
75
76int getErrorCount()       {return errcount;}
77int getWarningCount()     {return warncount;}
78int getInfoCount()        {return infocount;}
79int getStoredCount()      {return storcount;}
80int getErrorLevel()       {return maxlevel;}
81const SString& getMessages() {return msgs;}
82
83ErrorHandler(int opts=0,int store=FMLV_ERROR):ErrorHandlerBase(opts),storlevel(store)
84        {reset();}
85
86void handle(const char *o,const char *m,const char *bl,int w);
87};
88
89#endif
90
Note: See TracBrowser for help on using the repository browser.