Index: ps/trunk/source/i18n/L10n.h =================================================================== --- ps/trunk/source/i18n/L10n.h +++ ps/trunk/source/i18n/L10n.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -20,8 +20,8 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef L10N_H -#define L10N_H +#ifndef INCLUDED_L10N +#define INCLUDED_L10N #include #include @@ -41,16 +41,7 @@ */ class L10n : public Singleton { - /** - * Marks the L10n class as ‘noncopyable’. - * - * This is required, as the class works as a singleton. - * - * @sa #NONCOPYABLE(className) - */ - NONCOPYABLE(L10n); public: - /** * Creates an instance of L10n. * @@ -590,4 +581,4 @@ icu::DateFormat* CreateDateTimeInstance(const DateTimeType& type, const icu::DateFormat::EStyle& style, const icu::Locale& locale) const; }; -#endif // L10N_H +#endif // INCLUDED_L10N Index: ps/trunk/source/lib/code_annotation.h =================================================================== --- ps/trunk/source/lib/code_annotation.h +++ ps/trunk/source/lib/code_annotation.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2017 Wildfire Games. +/* Copyright (c) 2019 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -216,7 +216,7 @@ */ #define NONCOPYABLE(className) \ className(const className&) = delete; \ - const className& operator=(const className&) = delete + className& operator=(const className&) = delete #if ICC_VERSION # define ASSUME_ALIGNED(ptr, multiple) __assume_aligned(ptr, multiple) Index: ps/trunk/source/ps/ConfigDB.h =================================================================== --- ps/trunk/source/ps/ConfigDB.h +++ ps/trunk/source/ps/ConfigDB.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -50,12 +50,8 @@ #define g_ConfigDB CConfigDB::GetSingleton() -class CConfigDB: public Singleton +class CConfigDB : public Singleton { - static std::map m_Map[]; - static VfsPath m_ConfigFile[]; - static bool m_HasChanges[]; - public: CConfigDB(); @@ -165,6 +161,11 @@ bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value, const VfsPath& path); bool WriteValueToFile(EConfigNamespace ns, const CStr& name, const CStr& value); + +private: + static std::map m_Map[]; + static VfsPath m_ConfigFile[]; + static bool m_HasChanges[]; }; Index: ps/trunk/source/ps/Profile.h =================================================================== --- ps/trunk/source/ps/Profile.h +++ ps/trunk/source/ps/Profile.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -65,36 +65,6 @@ class CProfileNode { NONCOPYABLE(CProfileNode); - - friend class CProfileManager; - friend class CProfileNodeTable; - - const char* name; - - int calls_frame_current; - int calls_turn_current; - RingBuf calls_per_frame; - RingBuf calls_per_turn; - - double time_frame_current; - double time_turn_current; - RingBuf time_per_frame; - RingBuf time_per_turn; - - long mallocs_frame_current; - long mallocs_turn_current; - RingBuf mallocs_per_frame; - RingBuf mallocs_per_turn; - - double start; - long start_mallocs; - int recursion; - - CProfileNode* parent; - std::vector children; - std::vector script_children; - CProfileNodeTable* display_table; - public: typedef std::vector::iterator profile_iterator; typedef std::vector::const_iterator const_profile_iterator; @@ -132,17 +102,40 @@ void Call(); // Leaves the node. Returns true if the node has actually been left bool Return(); -}; -class CProfileManager : public Singleton -{ - CProfileNode* root; - CProfileNode* current; +private: + friend class CProfileManager; + friend class CProfileNodeTable; - bool needs_structural_reset; + const char* name; - void PerformStructuralReset(); + int calls_frame_current; + int calls_turn_current; + RingBuf calls_per_frame; + RingBuf calls_per_turn; + + double time_frame_current; + double time_turn_current; + RingBuf time_per_frame; + RingBuf time_per_turn; + + long mallocs_frame_current; + long mallocs_turn_current; + RingBuf mallocs_per_frame; + RingBuf mallocs_per_turn; + + double start; + long start_mallocs; + int recursion; + + CProfileNode* parent; + std::vector children; + std::vector script_children; + CProfileNodeTable* display_table; +}; +class CProfileManager : public Singleton +{ public: CProfileManager(); ~CProfileManager(); @@ -166,6 +159,14 @@ inline const CProfileNode* GetCurrent() { return( current ); } inline const CProfileNode* GetRoot() { return( root ); } + +private: + CProfileNode* root; + CProfileNode* current; + + bool needs_structural_reset; + + void PerformStructuralReset(); }; #define g_Profiler CProfileManager::GetSingleton() Index: ps/trunk/source/ps/Singleton.h =================================================================== --- ps/trunk/source/ps/Singleton.h +++ ps/trunk/source/ps/Singleton.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -15,58 +15,59 @@ * along with 0 A.D. If not, see . */ -/* - * template base class for Singletons - */ - -/* -USAGE: class myClass : Singleton{}; - -Modified from http://gamedev.net/reference/articles/article1954.asp -*/ - #ifndef INCLUDED_SINGLETON #define INCLUDED_SINGLETON #include "lib/debug.h" +/** + * Template base class for singletons. + * + * Usage: + * class MyClass : public Singleton {}; + * MyClass::GetSingleton().MyMethod(); + * + * Modified from http://gamedev.net/reference/articles/article1954.asp + */ template class Singleton { - static T* ms_singleton; - + NONCOPYABLE(Singleton); public: Singleton() { - ENSURE( !ms_singleton ); + ENSURE(!ms_singleton); ms_singleton = static_cast(this); } ~Singleton() { - ENSURE( ms_singleton ); - ms_singleton = 0; + ENSURE(ms_singleton); + ms_singleton = nullptr; } static T& GetSingleton() { - ENSURE( ms_singleton ); + ENSURE(ms_singleton); return *ms_singleton; } static T* GetSingletonPtr() { - ENSURE( ms_singleton ); + ENSURE(ms_singleton); return ms_singleton; } static bool IsInitialised() { - return (ms_singleton != 0); + return ms_singleton != nullptr; } + +private: + static T* ms_singleton; }; template -T* Singleton::ms_singleton = 0; +T* Singleton::ms_singleton = nullptr; -#endif +#endif // INCLUDED_SINGLETON Index: ps/trunk/source/scriptinterface/ScriptEngine.h =================================================================== --- ps/trunk/source/scriptinterface/ScriptEngine.h +++ ps/trunk/source/scriptinterface/ScriptEngine.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -34,13 +34,13 @@ public: ScriptEngine() { - ENSURE(m_Runtimes.size() == 0 && "JS_Init must be called before any runtimes are created!"); + ENSURE(m_Runtimes.empty() && "JS_Init must be called before any runtimes are created!"); JS_Init(); } ~ScriptEngine() { - ENSURE(m_Runtimes.size() == 0 && "All runtimes must be destroyed before calling JS_ShutDown!"); + ENSURE(m_Runtimes.empty() && "All runtimes must be destroyed before calling JS_ShutDown!"); JS_ShutDown(); } @@ -48,7 +48,6 @@ void UnRegisterRuntime(const JSRuntime* rt) { m_Runtimes.remove(rt); } private: - std::list m_Runtimes; };