aboutsummaryrefslogtreecommitdiff
path: root/sp/src/public/dmxloader/dmxloader.h
blob: 54815ae50ba690c9d161cdef91a369e3eee9b684 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#ifndef DMXLOADER_H
#define DMXLOADER_H

#ifdef _WIN32
#pragma once
#endif

//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CUtlBuffer;
class CDmxElement;


//-----------------------------------------------------------------------------
// Serialization/Unserialization
//-----------------------------------------------------------------------------
bool SerializeDMX( CUtlBuffer &buf, CDmxElement *pRoot, const char *pFileName = NULL );
bool SerializeDMX( const char *pFileName, const char *pPathID, bool bTextMode, CDmxElement *pRoot );

bool UnserializeDMX( CUtlBuffer &buf, CDmxElement **ppRoot, const char *pFileName = NULL );
bool UnserializeDMX( const char *pFileName, const char *pPathID,  bool bTextMode, CDmxElement **ppRoot );

//-----------------------------------------------------------------------------
// DMX elements/attributes can only be accessed inside a dmx context
//-----------------------------------------------------------------------------
void BeginDMXContext( );
void EndDMXContext( bool bDecommitMemory );
void DecommitDMXMemory();


//-----------------------------------------------------------------------------
// Helper macro
//-----------------------------------------------------------------------------
class CDMXContextHelper
{
public:
	CDMXContextHelper( bool bDecommitMemory ) { m_bDecommitMemory = bDecommitMemory; BeginDMXContext(); }
	~CDMXContextHelper() { EndDMXContext( m_bDecommitMemory ); }

private:
	bool m_bDecommitMemory;
};

#define DECLARE_DMX_CONTEXT( )	CDMXContextHelper __dmxContextHelper( true );
#define DECLARE_DMX_CONTEXT_NODECOMMIT( )	CDMXContextHelper __dmxContextHelper( false );
#define DECLARE_DMX_CONTEXT_DECOMMIT( _decommit )	CDMXContextHelper __dmxContextHelper( _decommit );


//-----------------------------------------------------------------------------
// Used for allocation. All will be freed when we leave the DMX context
//-----------------------------------------------------------------------------
void* DMXAlloc( size_t size );


//-----------------------------------------------------------------------------
// Helper macro
//-----------------------------------------------------------------------------
#define DECLARE_DMX_ALLOCATOR( )												\
	public:																		\
		inline void* operator new( size_t size ) { MEM_ALLOC_CREDIT_( "DMXAlloc" ); return DMXAlloc(size); }   \
		inline void* operator new( size_t size, int nBlockUse, const char *pFileName, int nLine ) { MEM_ALLOC_CREDIT_( "DMXAlloc" ); return DMXAlloc(size); }   \
		inline void  operator delete( void* p ) { }		\
		inline void  operator delete( void* p, int nBlockUse, const char *pFileName, int nLine ) { }   \

#endif // DMXLOADER_H