]> git.cworth.org Git - vogl/blob - src/voglcore/vogl_console.h
Initial vogl checkin
[vogl] / src / voglcore / vogl_console.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 // File: vogl_console.h
28 #pragma once
29
30 #include "vogl_core.h"
31 #include "vogl_dynamic_string.h"
32
33 namespace vogl
34 {
35     class dynamic_string;
36     class data_stream;
37     class mutex;
38
39     enum eConsoleMessageType
40     {
41         cDebugConsoleMessage,    // debugging messages
42         cProgressConsoleMessage, // progress messages
43         cInfoConsoleMessage,     // ordinary messages
44         cConsoleConsoleMessage,  // user console output
45         cMessageConsoleMessage,  // high importance messages
46         cWarningConsoleMessage,  // warnings
47         cErrorConsoleMessage,    // errors
48         cHeader1ConsoleMessage,  // header1
49         cCMTTotal
50     };
51
52     typedef bool (*console_output_func)(eConsoleMessageType type, const char *pMsg, void *pData);
53
54     class console
55     {
56     public:
57         static void init();
58         static void deinit();
59
60         static bool is_initialized()
61         {
62             return m_pMutex != NULL;
63         }
64
65         static const char *get_message_type_str(eConsoleMessageType type);
66         static eConsoleMessageType get_message_type_from_str(const char *str);
67
68         static void set_default_category(eConsoleMessageType category);
69         static eConsoleMessageType get_default_category();
70
71         static void add_console_output_func(console_output_func pFunc, void *pData);
72         static void remove_console_output_func(console_output_func pFunc);
73
74         static void printf(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
75
76         static void vprintf(eConsoleMessageType type, const char *p, va_list args);
77         static void printf(eConsoleMessageType type, const char *p, ...) VOGL_ATTRIBUTE_PRINTF(2, 3);
78
79         static void cons(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
80         static void debug(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
81         static void progress(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
82         static void info(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
83         static void message(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
84         static void warning(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
85         static void error(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
86         static void header1(const char *p, ...) VOGL_ATTRIBUTE_PRINTF(1, 2);
87
88         static void disable_prefixes()
89         {
90             m_prefixes = false;
91         }
92         static void enable_prefixes()
93         {
94             m_prefixes = true;
95         }
96         static bool get_prefixes()
97         {
98             return m_prefixes;
99         }
100         static bool get_at_beginning_of_line()
101         {
102             return m_at_beginning_of_line;
103         }
104
105         static void set_tool_prefix(const char *pPrefix)
106         {
107             strcpy(m_tool_prefix, pPrefix);
108         }
109         static const char *get_tool_prefix()
110         {
111             return m_tool_prefix;
112         }
113
114         static void disable_output()
115         {
116             m_output_disabled = true;
117         }
118         static void enable_output()
119         {
120             m_output_disabled = false;
121         }
122         static bool get_output_disabled()
123         {
124             return m_output_disabled;
125         }
126
127         static void set_log_stream(data_stream *pStream)
128         {
129             m_pLog_stream = pStream;
130         }
131         static data_stream *get_log_stream()
132         {
133             return m_pLog_stream;
134         }
135
136         static uint get_total_messages(eConsoleMessageType type)
137         {
138             return m_num_messages[type];
139         }
140
141     private:
142         static eConsoleMessageType m_default_category;
143
144         struct console_func
145         {
146             console_func(console_output_func func = NULL, void *pData = NULL)
147                 : m_func(func), m_pData(pData)
148             {
149             }
150
151             console_output_func m_func;
152             void *m_pData;
153         };
154
155         enum
156         {
157             cMaxOutputFuncs = 16
158         };
159         static uint m_num_output_funcs;
160         static console_func m_output_funcs[cMaxOutputFuncs];
161
162         static bool m_prefixes, m_output_disabled;
163         static data_stream *m_pLog_stream;
164         static mutex *m_pMutex;
165         static uint m_num_messages[cCMTTotal];
166         static bool m_at_beginning_of_line;
167         static char m_tool_prefix[256];
168     };
169
170     int vogl_getch();
171     int vogl_kbhit();
172
173 } // namespace vogl