-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpccErrorCollector.h
57 lines (43 loc) · 1.4 KB
/
cpccErrorCollector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* *****************************************
* File: cpccErrorCollector.h
* Purpose: Portable (cross-platform), light-weight, class
* to help with the error reporting from inside your classes
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2016 StarMessage software.
* License: Free for opensource projects.
* Commercial license exists for closed source projects.
* Web: http://www.StarMessageSoftware.com/cpcclibrary
* Download: https://code.google.com/p/cpcc/
* email: sales -at- starmessage.info
* *****************************************
*/
#pragma once
#include <iostream>
#include "cpccUnicodeSupport.h"
class cpccErrorCollector
{
private:
public:
cpcc_stringstream m_errorDump;
void clearErrors(void) { m_errorDump.str( _T("")); }
bool hasErrors(void) const { return m_errorDump.str().length()>0; }
const cpcc_string getErrorTextAndClearErrors(void)
{ cpcc_string txt = m_errorDump.str();
clearErrors();
return txt;
}
};
// global error collector, to replace all text written to std::out, std::err
cpccErrorCollector &gblErrorCollector(void)
{
static cpccErrorCollector errPtr = NULL;
if (!errPtr)
errPtr = cpccErrorCollector();
return *errPtr;
}
cpcc_stringstream &gblErrorDump(void)
{
return gblErrorCollector().m_errorDump;
}