Vuo  2.0.0
VuoLog.h
Go to the documentation of this file.
1 
10 // Don't use `#pragma once` here, since this header is included both from the source tree and from Vuo.framework.
11 #ifndef VUO_LOG
12 #define VUO_LOG
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include <stdbool.h>
19 
28 double VuoLogGetTime(void);
29 double VuoLogGetElapsedTime(void);
30 bool VuoIsDebugEnabled(void);
31 char *VuoLog_copyCFDescription(const void *variable);
32 
33 void VuoLog_backtrace(void);
34 #ifdef __cplusplus
35 }
36 #include <vector>
37 std::vector<std::string> VuoLog_getBacktrace(void);
38 extern "C" {
39 #endif
40 
41 
52 #define VuoLog_status(format, ...) VuoLog_statusF(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__)
53 
57 #ifdef DOXYGEN
58 void VuoLog_statusF(const char *file, const unsigned int linenumber, const char *function, const char *format, ...);
59 #else
60 void VuoLog_statusF(const char *file, const unsigned int linenumber, const char *function, const char *format, ...) __attribute__((format(printf, 4, 5)));
61 #endif
62 
68 #ifdef DOXYGEN
69 void VuoLog(const char *file, const unsigned int linenumber, const char *function, const char *format, ...);
70 #else
71 void VuoLog(const char *file, const unsigned int linenumber, const char *function, const char *format, ...) __attribute__((format(printf, 4, 5)));
72 #endif
73 
86 #define VL() VuoLog(__FILE__, __LINE__, __func__, "")
87 
102 #define VLog(format, ...) VuoLog(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__)
103 
109 #define VUserLog(format, ...) VuoLog(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__)
110 
116 #define VDebugLog(format, ...) do { if (VuoIsDebugEnabled()) VuoLog(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__); } while(0)
117 
130 #define VLogHeap(heapPointer) do { \
131  char *description = VuoHeap_getDescription(heapPointer); \
132  VLog("%s = %p (registered at %s)", #heapPointer, heapPointer, description); \
133  free(description); \
134  } while(0)
135 
136 
137 void VuoLog_recordTime(const char *name, double time);
138 
139 #ifdef VUO_PROFILE
140 #define VUOLOG_PROFILE_BEGIN(object) double VuoLog_time_ ## object = VuoLogGetTime();
141 #define VUOLOG_PROFILE_END(object) VuoLog_recordTime(#object, VuoLogGetTime() - VuoLog_time_ ## object);
142 #else
143 
154 #define VUOLOG_PROFILE_BEGIN(object)
155 
159 #define VUOLOG_PROFILE_END(object)
160 #endif
161 
174 #ifndef DOXYGEN
175 // Executes the block passed to it (an adapter in order to use `__attribute__((cleanup(…)))` with C Blocks).
176 static inline void VuoDeferCleanup(void (^*b)(void)) { if (*b) (*b)(); }
177 
178 // Combines two strings into an identifier.
179 #define VuoDeferMerge(a,b) a##b
180 
181 // Create the name of the defer scope variable.
182 #define VuoDeferVarName(a) VuoDeferMerge(VuoDeferScopeVar, a)
183 #endif
184 
199 #define VuoDefer __attribute__((cleanup(VuoDeferCleanup),unused)) void (^VuoDeferVarName(__COUNTER__))(void) =
200 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 #endif