From 6a82ff08d9d47f70e3a5a8021f964dd91a55a7da Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 28 May 2015 16:52:09 -0400 Subject: MAINT-5232: Normalize LLGlobalEconomy's use of LLSingleton. LLSingleton currently presents two different usage styles: deriving MyClass from LLSingleton, or just using a typedef. Turns out LLGlobalEconomy is the ONLY class using the typedef style -- and the apologetic comment talks about a potential maintenance that hasn't actually happened. Derive LLGlobalEconomy from LLSingleton, like everyone else. --- indra/llinventory/lleconomy.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'indra/llinventory/lleconomy.h') diff --git a/indra/llinventory/lleconomy.h b/indra/llinventory/lleconomy.h index 47fcf688a2..9c27ac5fb3 100755 --- a/indra/llinventory/lleconomy.h +++ b/indra/llinventory/lleconomy.h @@ -42,17 +42,12 @@ public: virtual void onEconomyDataChange() = 0; }; -class LLGlobalEconomy +class LLGlobalEconomy: public LLSingleton { public: LLGlobalEconomy(); virtual ~LLGlobalEconomy(); - // This class defines its singleton internally as a typedef instead of inheriting from - // LLSingleton like most others because the LLRegionEconomy sub-class might also - // become a singleton and this pattern will more easily disambiguate them. - typedef LLSingleton Singleton; - void initSingleton() { } virtual void print(); -- cgit v1.2.3 From 7deca6951fb4991fcebb1e89aad8b851aa2bc883 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 24 Jun 2015 20:57:32 -0400 Subject: MAINT-5232: Finish 7724e79aaf62: remove LLGlobalEconomy::initSingleton() --- indra/llinventory/lleconomy.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/llinventory/lleconomy.h') diff --git a/indra/llinventory/lleconomy.h b/indra/llinventory/lleconomy.h index 9c27ac5fb3..83836b7ce1 100755 --- a/indra/llinventory/lleconomy.h +++ b/indra/llinventory/lleconomy.h @@ -48,8 +48,6 @@ public: LLGlobalEconomy(); virtual ~LLGlobalEconomy(); - void initSingleton() { } - virtual void print(); void addObserver(LLEconomyObserver* observer); -- cgit v1.2.3 From d2c3c2f9fe197b1856e9a8ed37aeb56b77e2ff07 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 15 Sep 2016 20:18:12 -0400 Subject: MAINT-5232: Normalize LLSingleton subclasses. A shocking number of LLSingleton subclasses had public constructors -- and in several instances, were being explicitly instantiated independently of the LLSingleton machinery. This breaks the new LLSingleton dependency-tracking machinery. It seems only fair that if you say you want an LLSingleton, there should only be ONE INSTANCE! Introduce LLSINGLETON() and LLSINGLETON_EMPTY_CTOR() macros. These handle the friend class LLSingleton; and explicitly declare a private nullary constructor. To try to enforce the LLSINGLETON() convention, introduce a new pure virtual LLSingleton method you_must_use_LLSINGLETON_macro() which is, as you might suspect, defined by the macro. If you declare an LLSingleton subclass without using LLSINGLETON() or LLSINGLETON_EMPTY_CTOR() in the class body, you can't instantiate the subclass for lack of a you_must_use_LLSINGLETON_macro() implementation -- which will hopefully remind the coder. Trawl through ALL LLSingleton subclass definitions, sprinkling in LLSINGLETON() or LLSINGLETON_EMPTY_CTOR() as appropriate. Remove all explicit constructor declarations, public or private, along with relevant 'friend class LLSingleton' declarations. Where destructors are declared, move them into private section as well. Where the constructor was inline but nontrivial, move out of class body. Fix several LLSingleton abuses revealed by making ctors/dtors private: LLGlobalEconomy was both an LLSingleton and the base class for LLRegionEconomy, a non-LLSingleton. (Therefore every LLRegionEconomy instance contained another instance of the LLGlobalEconomy "singleton.") Extract LLBaseEconomy; LLGlobalEconomy is now a trivial subclass of that. LLRegionEconomy, as you might suspect, now derives from LLBaseEconomy. LLToolGrab, an LLSingleton, was also explicitly instantiated by LLToolCompGun's constructor. Extract LLToolGrabBase, explicitly instantiated, with trivial subclass LLToolGrab, the LLSingleton instance. (WARNING: LLToolGrabBase methods have an unnerving tendency to go after LLToolGrab::getInstance(). I DO NOT KNOW what should be the relationship between the instance in LLToolCompGun and the LLToolGrab singleton instance.) LLGridManager declared a variant constructor accepting (const std::string&), with the comment: // initialize with an explicity grid file for testing. As there is no evidence of this being called from anywhere, delete it. LLChicletBar's constructor accepted an optional (const LLSD&). As the LLSD parameter wasn't used, and as there is no evidence of it being passed from anywhere, delete the parameter. LLViewerWindow::shutdownViews() was checking LLNavigationBar:: instanceExists(), then deleting its getInstance() pointer -- leaving a dangling LLSingleton instance pointer, a land mine if any subsequent code should attempt to reference it. Use deleteSingleton() instead. ~LLAppViewer() was calling LLViewerEventRecorder::instance() and then explicitly calling ~LLViewerEventRecorder() on that instance -- leaving the LLSingleton instance pointer pointing to an allocated-but-destroyed instance. Use deleteSingleton() instead. --- indra/llinventory/lleconomy.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'indra/llinventory/lleconomy.h') diff --git a/indra/llinventory/lleconomy.h b/indra/llinventory/lleconomy.h index 83836b7ce1..cdfde171c1 100644 --- a/indra/llinventory/lleconomy.h +++ b/indra/llinventory/lleconomy.h @@ -42,11 +42,11 @@ public: virtual void onEconomyDataChange() = 0; }; -class LLGlobalEconomy: public LLSingleton +class LLBaseEconomy { public: - LLGlobalEconomy(); - virtual ~LLGlobalEconomy(); + LLBaseEconomy(); + virtual ~LLBaseEconomy(); virtual void print(); @@ -54,7 +54,7 @@ public: void removeObserver(LLEconomyObserver* observer); void notifyObservers(); - static void processEconomyData(LLMessageSystem *msg, LLGlobalEconomy* econ_data); + static void processEconomyData(LLMessageSystem *msg, LLBaseEconomy* econ_data); S32 calculateTeleportCost(F32 distance) const; S32 calculateLightRent(const LLVector3& object_size) const; @@ -101,8 +101,12 @@ private: std::list mObservers; }; +class LLGlobalEconomy: public LLSingleton, public LLBaseEconomy +{ + LLSINGLETON_EMPTY_CTOR(LLGlobalEconomy); +}; -class LLRegionEconomy : public LLGlobalEconomy +class LLRegionEconomy : public LLBaseEconomy { public: LLRegionEconomy(); -- cgit v1.2.3