]> git.lyx.org Git - features.git/commitdiff
Properly implement the singleton pattern
authorRichard Kimberly Heck <rikiheck@lyx.org>
Mon, 9 Nov 2020 20:39:20 +0000 (15:39 -0500)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Wed, 11 Nov 2020 17:07:56 +0000 (12:07 -0500)
src/Buffer.cpp
src/mathed/InsetMathMacro.cpp
src/mathed/InsetMathNest.cpp
src/mathed/MacroTable.cpp
src/mathed/MacroTable.h
src/mathed/MathFactory.cpp

index 9562cb8c72eca39f98b48c9a9baab7146542a1c8..14169709cd8cd8f174e869a2da9222e0a70e228f 100644 (file)
@@ -3686,7 +3686,7 @@ MacroData const * Buffer::getMacro(docstring const & name,
        }
 
        if (global) {
-               data = MacroTable::globalMacros().get(name);
+               data = MacroTable::get().getMacro(name);
                if (data != nullptr)
                        return data;
        }
index 57294c075354d889ad4513b406b4fd9ebe22d717..600562f2fcbe58ca80ec9723d4c18a38d1888489 100644 (file)
@@ -938,7 +938,7 @@ MacroData const * InsetMathMacro::macroBackup() const
 {
        if (macro())
                return &d->macroBackup_;
-       if (MacroData const * data = MacroTable::globalMacros().get(name()))
+       if (MacroData const * data = MacroTable::get().getMacro(name()))
                return data;
        return nullptr;
 }
@@ -957,7 +957,7 @@ void InsetMathMacro::validate(LaTeXFeatures & features) const
                features.require(d->required_);
        else if (!d->macro_) {
                // Update requires for known global macros.
-               MacroData const * data = MacroTable::globalMacros().get(name());
+               MacroData const * data = MacroTable::get().getMacro(name());
                if (data && !data->required().empty())
                        features.require(data->required());
        }
index ada0400f18f51045eff592b219a648477c3d8820..19aa745d50b193d644d11e00305b9412100b0a11 100644 (file)
@@ -2106,7 +2106,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
 
        // fill in global macros
        macros.clear();
-       MacroTable::globalMacros().getMacroNames(macros, false);
+       MacroTable::get().getMacroNames(macros, false);
        //lyxerr << "Globals completion macros: ";
        for (it = macros.begin(); it != macros.end(); ++it) {
                //lyxerr << "\\" + *it << " ";
index 218c8492e284a83a5f76ca5dde60f77655592d0e..2bc427b221c20f7a9cd74fe304cd7e92ae30c56f 100644 (file)
@@ -215,14 +215,14 @@ int MacroData::write(odocstream & os, bool overwriteRedefinition) const
 //
 /////////////////////////////////////////////////////////////////////
 
-MacroTable & MacroTable::globalMacros()
+MacroTable & MacroTable::get()
 {
        static MacroTable theGlobalMacros;
        return theGlobalMacros;
 }
 
 
-MacroData const * MacroTable::get(docstring const & name) const
+MacroData const * MacroTable::getMacro(docstring const & name) const
 {
        const_iterator it = find(name);
        return it == end() ? 0 : &it->second;
index 77b306fccdd8bc41f8d28e2c39140e4e8ef655e0..ab3c6b486fffe8ba7881ba337aba54ea76c663a0 100644 (file)
@@ -160,19 +160,22 @@ class MacroSet : public std::set<MacroData const *> {};
 class MacroTable : public std::map<docstring, MacroData>
 {
 public:
+       /// We are a singleton
+       MacroTable() = default;
+       MacroTable(MacroTable const &) = delete;
+       void operator=(MacroTable const &) = delete;
+       /// the global list: our unique instance
+       static MacroTable & get();
        /// Parse full "\\def..." or "\\newcommand..." or ...
        iterator insert(Buffer * buf, docstring const & definition);
        /// Insert pre-digested macro definition
        iterator insert(docstring const & name, MacroData const & data);
        ///
-       MacroData const * get(docstring const & name) const;
+       MacroData const * getMacro(docstring const & name) const;
        ///
        void dump();
        ///
        void getMacroNames(std::set<docstring> & names, bool gethidden) const;
-
-       /// the global list
-       static MacroTable & globalMacros();
 };
 
 
index 54fe012857007c3a554ba66e05ba0fba05f3fae4..f9569737f66b6fcd094f5f287a9fdbc1ef850833 100644 (file)
@@ -202,7 +202,7 @@ void initSymbols()
                                        required = "";
                        } else
                                htmlname = xmlname = "";
-                       MacroTable::iterator it = MacroTable::globalMacros().insert(
+                       MacroTable::iterator it = MacroTable::get().insert(
                                        0, from_utf8(macro));
                        if (!extra.empty() || !htmlname.empty() || !xmlname.empty() || !required.empty()) {
                                MathWordList::iterator wit = theMathWordList.find(it->first);