@@ -23,6 +23,7 @@ distribution.
2323*/
2424
2525#pragma once
26+
2627#include " Export.h"
2728#include " ColorText.h"
2829#include < deque>
@@ -31,13 +32,8 @@ distribution.
3132#include < iostream>
3233#include < string>
3334#include < vector>
34- #include < algorithm>
35- #include < functional>
36- #include < map>
3735#include < memory>
3836
39- union SDL_Event;
40-
4137namespace DFHack
4238{
4339 class CommandHistory
@@ -126,38 +122,17 @@ namespace DFHack
126122
127123 class DFHACK_EXPORT Console : public color_ostream
128124 {
129- protected:
130- using FactoryFunc = std::function<std::unique_ptr<Console>()>;
131- struct RegistryEntry {
132- FactoryFunc func;
133- int priority;
125+ public:
126+ enum class Type {
127+ Posix,
128+ SDL,
129+ Windows,
130+ DUMMY
134131 };
135132
136- static void registerConsole (const std::string &name, FactoryFunc func, int priority) {
137- getRegistry ().emplace (name, RegistryEntry{func, priority});
138- }
139- private:
140- static std::map<std::string, RegistryEntry> &getRegistry () {
141- static std::map<std::string, RegistryEntry> registry;
142- return registry;
143- }
144-
145- static auto getAvailableConsoles () {
146- std::vector<std::pair<std::string, RegistryEntry>> result;
147- auto & registry = getRegistry ();
148-
149- for (const auto &entry : registry) {
150- result.emplace_back (entry.first , entry.second );
151- }
152-
153- std::sort (result.begin (), result.end (), [](const auto & a, const auto & b) {
154- return a.second .priority > b.second .priority ;
155- });
156-
157- return result;
158- }
159-
160133 protected:
134+ Type con_type{Type::DUMMY};
135+
161136 virtual void begin_batch () {};
162137 virtual void add_text (color_value color, const std::string &text) {};
163138 virtual void end_batch () {};
@@ -166,6 +141,7 @@ namespace DFHack
166141 public:
167142 // /ctor, NOT thread-safe
168143 Console () = default ;
144+ Console (Type type) : con_type(type) {}
169145 // /dtor, NOT thread-safe
170146 virtual ~Console () = default ;
171147 // / initialize the console. NOT thread-safe
@@ -202,15 +178,14 @@ namespace DFHack
202178 virtual bool hide () { return false ; };
203179 virtual bool show () { return false ; };
204180
205- virtual bool sdl_event_hook (SDL_Event& event) { return false ; };
206181 virtual void cleanup () {};
182+ Type get_type () const { return con_type; }
207183
208- static std::unique_ptr<Console> makeConsole () {
209- auto availableConsoles = getAvailableConsoles ();
210- if (!availableConsoles.empty ()) {
211- return availableConsoles[0 ].second .func ();
212- }
213- return std::make_unique<Console>();
184+ template <typename T>
185+ T& as () {
186+ return static_cast <T&>(*this );
214187 }
188+
189+ static std::unique_ptr<Console> makeConsole ();
215190 };
216191}
0 commit comments