Unify duplicate Breadth-First-Search traversing of the LayeredPainter and SmoothEleva...
[0ad.git] / source / scriptinterface / ScriptEngine.h
blob07c342cd7119f04a545f9119e934c259291f5f1e
1 /* Copyright (C) 2016 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_SCRIPTENGINE
19 #define INCLUDED_SCRIPTENGINE
21 #include "ScriptTypes.h"
22 #include "ps/Singleton.h"
24 /**
25 * A class using the RAII (Resource Acquisition Is Initialization) idiom to manage initialization
26 * and shutdown of the SpiderMonkey script engine. It also keeps a count of active script runtimes
27 * in order to validate the following constraints:
28 * 1. JS_Init must be called before any ScriptRuntimes are initialized
29 * 2. JS_Shutdown must be called after all ScriptRuntimes have been destroyed
32 class ScriptEngine : public Singleton<ScriptEngine>
34 public:
35 ScriptEngine()
37 ENSURE(m_Runtimes.size() == 0 && "JS_Init must be called before any runtimes are created!");
38 JS_Init();
41 ~ScriptEngine()
43 ENSURE(m_Runtimes.size() == 0 && "All runtimes must be destroyed before calling JS_ShutDown!");
44 JS_ShutDown();
47 void RegisterRuntime(const JSRuntime* rt) { m_Runtimes.push_back(rt); }
48 void UnRegisterRuntime(const JSRuntime* rt) { m_Runtimes.remove(rt); }
50 private:
52 std::list<const JSRuntime*> m_Runtimes;
55 #endif // INCLUDED_SCRIPTENGINE