summaryrefslogtreecommitdiff
path: root/replay/spew.h
blob: a567ad3be5825776b674de1c99154810635b080a (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//

#ifndef SPEW_H
#define SPEW_H
#ifdef _WIN32
#pragma once
#endif

//----------------------------------------------------------------------------------------

class ISpewer
{
public:
	virtual ~ISpewer() {}

	virtual void PrintBlockStart() const = 0;
	virtual void PrintBlockEnd() const = 0;
	virtual void PrintEmptyLine() const = 0;
	virtual void PrintEventStartMsg( const char *pMsg ) const = 0;
	virtual void PrintEventResult( bool bSuccess ) const = 0;
	virtual void PrintEventError( const char *pError ) const = 0;
	virtual void PrintTestHeader( const char *pHeader ) const = 0;
	virtual void PrintMsg( const char *pMsg ) const = 0;
	virtual void PrintValue( const char *pWhat, const char *pValue ) const = 0;
};

//----------------------------------------------------------------------------------------

extern ISpewer *g_pDefaultSpewer;
extern ISpewer *g_pBlockSpewer;
extern ISpewer *g_pSimpleSpewer;
extern ISpewer *g_pNullSpewer;

//----------------------------------------------------------------------------------------

class CSpewScope
{
public:
	CSpewScope( ISpewer *pSpewer )
	{
		m_pOldSpewer = g_pDefaultSpewer;
		g_pDefaultSpewer = pSpewer;
	}

	~CSpewScope()
	{
		g_pDefaultSpewer = m_pOldSpewer;
	}

private:
	ISpewer	*m_pOldSpewer;
};

//----------------------------------------------------------------------------------------

class CBaseSpewer : public ISpewer
{
public:
	CBaseSpewer( ISpewer *pSpewer = g_pDefaultSpewer );

	//
	// ISpewer implementation for shorthand.
	//
	virtual void PrintBlockStart() const { m_pSpewer->PrintBlockStart(); }
	virtual void PrintBlockEnd() const { m_pSpewer->PrintBlockEnd(); }
	virtual void PrintEmptyLine() const { m_pSpewer->PrintEmptyLine(); }
	virtual void PrintEventStartMsg( const char *pMsg ) const { m_pSpewer->PrintEventStartMsg( pMsg ); }
	virtual void PrintEventResult( bool bSuccess ) const { m_pSpewer->PrintEventResult( bSuccess ); }
	virtual void PrintEventError( const char *pError ) const { m_pSpewer->PrintEventError( pError ); }
	virtual void PrintTestHeader( const char *pHeader ) const { m_pSpewer->PrintTestHeader( pHeader ); }
	virtual void PrintMsg( const char *pMsg ) const { m_pSpewer->PrintMsg( pMsg ); }
	virtual void PrintValue( const char *pWhat, const char *pValue ) const { m_pSpewer->PrintValue( pWhat, pValue ); }

private:
	ISpewer *m_pSpewer;
};

//----------------------------------------------------------------------------------------

#endif	// SPEW_H