From 667ca55bad0108c4bdf8f007b89e1a52fc766aad Mon Sep 17 00:00:00 2001 From: Kent Quirk Date: Mon, 5 Jan 2009 18:59:12 +0000 Subject: svn merge -r106715:HEAD svn+ssh://svn.lindenlab.com/svn/linden/branches/q/notifications-merge-r106715 . QAR-1149 -- Final merge of notifications to trunk. --- indra/llui/llui.h | 237 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) (limited to 'indra/llui/llui.h') diff --git a/indra/llui/llui.h b/indra/llui/llui.h index e2629ee2a4..4366c38740 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -42,6 +42,7 @@ #include "llgl.h" // *TODO: break this dependency #include //#include "llimagegl.h" +#include // LLUIFactory #include "llsd.h" @@ -150,11 +151,13 @@ typedef void (*LLUIAudioCallback)(const LLUUID& uuid); class LLUI { + LOG_CLASS(LLUI); public: // // Methods // static void initClass(LLControlGroup* config, + LLControlGroup* ignores, LLControlGroup* colors, LLImageProviderInterface* image_provider, LLUIAudioCallback audio_callback = NULL, @@ -190,6 +193,7 @@ public: // Data // static LLControlGroup* sConfigGroup; + static LLControlGroup* sIgnoresGroup; static LLControlGroup* sColorsGroup; static LLImageProviderInterface* sImageProvider; static LLUIAudioCallback sAudioCallback; @@ -597,4 +601,237 @@ public: virtual void cleanUp() = 0; }; +// This mix-in class adds support for tracking all instances of the specificed class parameter T +// The (optional) key associates a value of type KEY with a given instance of T, for quick lookup +// If KEY is not provided, then instances are stored in a simple list +template +class LLInstanceTracker : boost::noncopyable +{ +public: + typedef typename std::map::iterator instance_iter; + typedef typename std::map::const_iterator instance_const_iter; + + static T* getInstance(KEY k) { instance_iter found = sInstances.find(k); return (found == sInstances.end()) ? NULL : found->second; } + + static instance_iter beginInstances() { return sInstances.begin(); } + static instance_iter endInstances() { return sInstances.end(); } + static S32 instanceCount() { return sInstances.size(); } +protected: + LLInstanceTracker(KEY key) { add(key); } + virtual ~LLInstanceTracker() { remove(); } + virtual void setKey(KEY key) { remove(); add(key); } + virtual const KEY& getKey() const { return mKey; } + +private: + void add(KEY key) + { + mKey = key; + sInstances[key] = static_cast(this); + } + void remove() { sInstances.erase(mKey); } + +private: + + KEY mKey; + static std::map sInstances; +}; + +template +class LLInstanceTracker : boost::noncopyable +{ +public: + typedef typename std::set::iterator instance_iter; + typedef typename std::set::const_iterator instance_const_iter; + + static instance_iter instancesBegin() { return sInstances.begin(); } + static instance_iter instancesEnd() { return sInstances.end(); } + static S32 instanceCount() { return sInstances.size(); } + +protected: + LLInstanceTracker() { sInstances.insert(static_cast(this)); } + virtual ~LLInstanceTracker() { sInstances.erase(static_cast(this)); } + + static std::set sInstances; +}; + +template std::map LLInstanceTracker::sInstances; +template std::set LLInstanceTracker::sInstances; + +class LLCallbackRegistry +{ +public: + typedef boost::signal callback_signal_t; + + void registerCallback(const callback_signal_t::slot_type& slot) + { + mCallbacks.connect(slot); + } + + void fireCallbacks() + { + mCallbacks(); + } + +private: + callback_signal_t mCallbacks; +}; + +class LLInitClassList : + public LLCallbackRegistry, + public LLSingleton +{ + friend class LLSingleton; +private: + LLInitClassList() {} +}; + +class LLDestroyClassList : + public LLCallbackRegistry, + public LLSingleton +{ + friend class LLSingleton; +private: + LLDestroyClassList() {} +}; + +template +class LLRegisterWith +{ +public: + LLRegisterWith(boost::function func) + { + T::instance().registerCallback(func); + } + + // this avoids a MSVC bug where non-referenced static members are "optimized" away + // even if their constructors have side effects + void reference() + { + S32 dummy; + dummy = 0; + } +}; + +template +class LLInitClass +{ +public: + LLInitClass() { sRegister.reference(); } + + static LLRegisterWith sRegister; +private: + + static void initClass() + { + llerrs << "No static initClass() method defined for " << typeid(T).name() << llendl; + } +}; + +template +class LLDestroyClass +{ +public: + LLDestroyClass() { sRegister.reference(); } + + static LLRegisterWith sRegister; +private: + + static void destroyClass() + { + llerrs << "No static destroyClass() method defined for " << typeid(T).name() << llendl; + } +}; + +template LLRegisterWith LLInitClass::sRegister(&T::initClass); +template LLRegisterWith LLDestroyClass::sRegister(&T::destroyClass); + + +template +class LLParamBlock +{ +protected: + LLParamBlock() { sBlock = (DERIVED*)this; } + + typedef typename boost::add_const::type Tconst; + + template + class LLMandatoryParam + { + public: + typedef typename boost::add_const::type T_const; + + LLMandatoryParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} + LLMandatoryParam(const LLMandatoryParam& other) : mVal(other.mVal) {} + + DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } + operator T() const { return mVal; } + T operator=(T_const set_value) { mVal = set_value; return mVal; } + + private: + T mVal; + DERIVED* mBlock; + }; + + template + class LLOptionalParam + { + public: + typedef typename boost::add_const::type T_const; + + LLOptionalParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} + LLOptionalParam() : mBlock(sBlock) {} + LLOptionalParam(const LLOptionalParam& other) : mVal(other.mVal) {} + + DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } + operator T() const { return mVal; } + T operator=(T_const set_value) { mVal = set_value; return mVal; } + + private: + T mVal; + DERIVED* mBlock; + }; + + // specialization that requires initialization for reference types + template + class LLOptionalParam + { + public: + typedef typename boost::add_const::type T_const; + + LLOptionalParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} + LLOptionalParam(const LLOptionalParam& other) : mVal(other.mVal) {} + + DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } + operator T&() const { return mVal; } + T& operator=(T_const set_value) { mVal = set_value; return mVal; } + + private: + T& mVal; + DERIVED* mBlock; + }; + + // specialization that initializes pointer params to NULL + template + class LLOptionalParam + { + public: + typedef typename boost::add_const::type T_const; + + LLOptionalParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} + LLOptionalParam() : mVal((T*)NULL), mBlock(sBlock) {} + LLOptionalParam(const LLOptionalParam& other) : mVal(other.mVal) {} + + DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } + operator T*() const { return mVal; } + T* operator=(T_const set_value) { mVal = set_value; return mVal; } + private: + T* mVal; + DERIVED* mBlock; + }; + + static DERIVED* sBlock; +}; + +template T* LLParamBlock::sBlock = NULL; + #endif -- cgit v1.2.3