TexGen
ShinyMacros.h
Go to the documentation of this file.
1/*
2The zlib/libpng License
3
4Copyright (c) 2007 Aidin Abedi (www.*)
5
6This software is provided 'as-is', without any express or implied warranty. In no event will
7the authors be held liable for any damages arising from the use of this software.
8
9Permission is granted to anyone to use this software for any purpose, including commercial
10applications, and to alter it and redistribute it freely, subject to the following
11restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not claim that
14 you wrote the original software. If you use this software in a product,
15 an acknowledgment in the product documentation would be appreciated but is
16 not required.
17
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20
21 3. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef SHINY_MACROS_H
25#define SHINY_MACROS_H
26
27#include "ShinyManager.h"
28
29#if SHINY_PROFILER == TRUE
30
31
32//-----------------------------------------------------------------------------
33// public preprocessors
34
35#define PROFILER_UPDATE \
36 Shiny::ProfileManager::instance.update
37
38#define PROFILER_OUTPUT \
39 Shiny::ProfileManager::instance.output
40
41#define PROFILER_OUTPUT_TREE_STRING() \
42 Shiny::ProfileManager::instance.outputNodesAsString()
43
44#define PROFILER_OUTPUT_FLAT_STRING() \
45 Shiny::ProfileManager::instance.outputZonesAsString()
46
47#define PROFILER_DESTROY() \
48 Shiny::ProfileManager::instance.destroy()
49
50
51//-----------------------------------------------------------------------------
52// public preprocessor
53
54#define PROFILE_ROOT_DATA() \
55 Shiny::ProfileManager::instance.rootZone.data
56
57
58//-----------------------------------------------------------------------------
59// public preprocessor
60
61#define PROFILE_END() \
62 Shiny::ProfileManager::instance._endCurNode()
63
64
65//-----------------------------------------------------------------------------
66// public preprocessor
67
68#define PROFILE_BEGIN( name ) \
69 \
70 static _PROFILE_ZONE_DEFINE(_PROFILE_ID_ZONE(name), #name); \
71 _PROFILE_ZONE_BEGIN(_PROFILE_ID_ZONE(name));
72
73
74//-----------------------------------------------------------------------------
75// public preprocessor
76
77#define PROFILE_BLOCK( name ) \
78 \
79 _PROFILE_BLOCK_DEFINE(_PROFILE_ID_BLOCK()); \
80 PROFILE_BEGIN(name);
81
82
83//-----------------------------------------------------------------------------
84// public preprocessor
85
86#define PROFILE_FUNC() \
87 \
88 _PROFILE_BLOCK_DEFINE(_PROFILE_ID_BLOCK()); \
89 static _PROFILE_ZONE_DEFINE(_PROFILE_ID_ZONE_FUNC(), __FUNCTION__); \
90 _PROFILE_ZONE_BEGIN(_PROFILE_ID_ZONE_FUNC());
91
92
93//-----------------------------------------------------------------------------
94// public preprocessor
95
96#define PROFILE_CODE( code ) \
97 { \
98 static _PROFILE_ZONE_DEFINE(_PROFILE_ID_ZONE_CODE(), #code); \
99 _PROFILE_ZONE_BEGIN(_PROFILE_ID_ZONE_CODE()); \
100 { code; } \
101 PROFILE_END(); \
102 }
103
104
105//-----------------------------------------------------------------------------
106// public preprocessor
107
108#define PROFILE_SHARED_EXTERN( name ) \
109 \
110 _PROFILE_ZONE_DECLARE(extern, _PROFILE_ID_ZONE_SHARED(name));
111
112
113//-----------------------------------------------------------------------------
114// public preprocessor
115
116#define PROFILE_SHARED_STATIC( name ) \
117 \
118 _PROFILE_ZONE_DECLARE(static, _PROFILE_ID_ZONE_SHARED(name));
119
120
121//-----------------------------------------------------------------------------
122// public preprocessor
123
124#define PROFILE_SHARED_DEFINE( name ) \
125 \
126 _PROFILE_ZONE_DEFINE(_PROFILE_ID_ZONE_SHARED(name), #name);
127
128
129//-----------------------------------------------------------------------------
130// public preprocessor
131
132#define PROFILE_SHARED_BEGIN( name ) \
133 \
134 _PROFILE_ZONE_BEGIN(_PROFILE_ID_ZONE_SHARED(name));
135
136
137//-----------------------------------------------------------------------------
138// public preprocessor
139
140#define PROFILE_SHARED_BLOCK( name ) \
141 \
142 _PROFILE_BLOCK_DEFINE(_PROFILE_ID_BLOCK()); \
143 _PROFILE_ZONE_BEGIN(_PROFILE_ID_ZONE_SHARED(name));
144
145
146//-----------------------------------------------------------------------------
147// public preprocessor
148
149#define PROFILE_SHARED_DATA( name ) \
150 \
151 _PROFILE_ID_ZONE_SHARED(name).data \
152
153
154//-----------------------------------------------------------------------------
155// internal preprocessors
156
157#define _PROFILE_ID_ZONE( name ) __ShinyZone_##name
158#define _PROFILE_ID_ZONE_FUNC() __ShinyZoneFunc
159#define _PROFILE_ID_ZONE_CODE() __ShinyZoneCode
160#define _PROFILE_ID_ZONE_SHARED( name ) name##__ShinyZoneShared
161#define _PROFILE_ID_BLOCK() __ShinyBlock
162
163
164//-----------------------------------------------------------------------------
165// internal preprocessor
166
167#define _PROFILE_ZONE_DEFINE( id, string ) \
168 \
169 Shiny::ProfileZone id = { \
170 NULL, Shiny::ProfileZone::STATE_HIDDEN, string, \
171 { { 0, 0 }, { 0, 0 }, { 0, 0 } } \
172 };
173
174
175//-----------------------------------------------------------------------------
176// internal preprocessor
177
178#define _PROFILE_ZONE_DECLARE( prefix, id ) \
179 \
180 prefix Shiny::ProfileZone id;
181
182
183//-----------------------------------------------------------------------------
184// internal preprocessor
185
186#define _PROFILE_BLOCK_DEFINE( id ) \
187 \
188 Shiny::ProfileAutoEndNode SHINY_UNUSED id;
189
190
191//-----------------------------------------------------------------------------
192// internal preprocessor
193
194#define _PROFILE_ZONE_BEGIN( id ) \
195 { \
196 static Shiny::ProfileNodeCache cache = \
197 &Shiny::ProfileNode::_dummy; \
198 \
199 Shiny::ProfileManager::instance._beginNode(&cache, &id); \
200 }
201
202//-----------------------------------------------------------------------------
203
204#else // #if SHINY_PROFILER == TRUE
205
206namespace Shiny {
207
208 SHINY_INLINE ProfileData GetEmptyData() {
209 ProfileData a = { { 0, 0 }, { 0, 0 }, { 0, 0 } };
210 return a;
211 }
212
213 SHINY_INLINE void DummyUpdate(float a = 0.0f) { /* meditate */ }
214 SHINY_INLINE bool DummyOutput(const char *a = NULL) { return false; }
215 SHINY_INLINE bool DummyOutput(std::ostream &a) { return false; }
216
217}
218
219#define PROFILER_UPDATE DummyUpdate
220#define PROFILER_OUTPUT DummyOutput
221#define PROFILER_OUTPUT_TREE_STRING() std::string()
222#define PROFILER_OUTPUT_FLAT_STRING() std::string()
223#define PROFILER_DESTROY()
224#define PROFILE_BEGIN(name)
225#define PROFILE_BLOCK(name)
226#define PROFILE_FUNC()
227#define PROFILE_CODE(code) { code; }
228#define PROFILE_SHARED_EXTERN(name)
229#define PROFILE_SHARED_STATIC(name)
230#define PROFILE_SHARED_DEFINE(name)
231#define PROFILE_SHARED_BEGIN(name)
232#define PROFILE_SHARED_BLOCK(name)
233#define PROFILE_SHARED_DATA(name) Shiny::GetEmptyData()
234#define PROFILE_ROOT_DATA() Shiny::GetEmptyData()
235
236#endif
237
238#endif // ifndef SHINY_*_H
#define NULL
Definition: ShinyConfig.h:50
#define SHINY_INLINE
Definition: ShinyPrereqs.h:55