From fdc848cf72f755b3ce924e12625ec9923495f9bc Mon Sep 17 00:00:00 2001
From: Richard Nelson <richard@lindenlab.com>
Date: Tue, 20 Oct 2009 22:05:00 +0000
Subject: removed unnecessary static variable instantiations to improve compile
 times moved a bunch of template class statics to cpp files also added
 filename parameter to LLXUIParser::readXUI for better debugging of XUI errors

reviewed by James
---
 indra/llui/llhandle.h          | 14 ++++++------
 indra/llui/lllayoutstack.cpp   |  2 +-
 indra/llui/llnotifications.cpp |  1 +
 indra/llui/llnotifications.h   |  3 +--
 indra/llui/llpanel.cpp         |  7 +++---
 indra/llui/llrngwriter.cpp     |  3 ++-
 indra/llui/lluicolortable.cpp  |  2 +-
 indra/llui/lluictrlfactory.cpp | 40 ++++++++++++++++++++++++++++++++-
 indra/llui/lluictrlfactory.h   | 50 +++++++++++++++++++++---------------------
 indra/llui/lluistring.cpp      |  2 --
 indra/llui/lluistring.h        |  2 --
 11 files changed, 81 insertions(+), 45 deletions(-)

(limited to 'indra/llui')

diff --git a/indra/llui/llhandle.h b/indra/llui/llhandle.h
index 10a7fd4544..899f6b9326 100644
--- a/indra/llui/llhandle.h
+++ b/indra/llui/llhandle.h
@@ -60,7 +60,7 @@ template <typename T>
 class LLHandle
 {
 public:
-	LLHandle() : mTombStone(sDefaultTombStone) {}
+	LLHandle() : mTombStone(getDefaultTombStone()) {}
 	const LLHandle<T>& operator =(const LLHandle<T>& other)  
 	{ 
 		mTombStone = other.mTombStone;
@@ -74,7 +74,7 @@ public:
 
 	void markDead() 
 	{ 
-		mTombStone = sDefaultTombStone; 
+		mTombStone = getDefaultTombStone();
 	}
 
 	T* get() const
@@ -104,13 +104,13 @@ protected:
 	LLPointer<LLTombStone<T> > mTombStone;
 
 private:
-	static LLPointer<LLTombStone<T> > sDefaultTombStone;
+	static LLPointer<LLTombStone<T> >& getDefaultTombStone()
+	{
+		static LLPointer<LLTombStone<T> > sDefaultTombStone = new LLTombStone<T>;
+		return sDefaultTombStone;
+	}
 };
 
-// initialize static "empty" tombstone pointer
-template <typename T> LLPointer<LLTombStone<T> > LLHandle<T>::sDefaultTombStone = new LLTombStone<T>();
-
-
 template <typename T>
 class LLRootHandle : public LLHandle<T>
 {
diff --git a/indra/llui/lllayoutstack.cpp b/indra/llui/lllayoutstack.cpp
index 5eade72b61..24fd380bb1 100644
--- a/indra/llui/lllayoutstack.cpp
+++ b/indra/llui/lllayoutstack.cpp
@@ -229,7 +229,7 @@ static void get_attribute_bool_and_write(LLXMLNodePtr node,
 LLView* LLLayoutStack::fromXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node)
 {
 	LLLayoutStack::Params p(LLUICtrlFactory::getDefaultParams<LLLayoutStack>());
-	LLXUIParser::instance().readXUI(node, p);
+	LLXUIParser::instance().readXUI(node, p, LLUICtrlFactory::getInstance()->getCurFileName());
 
 	// Export must happen before setupParams() mungles rectangles and before
 	// this item gets added to parent (otherwise screws up last_child_rect
diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp
index 25e2475f59..a0e51151c9 100644
--- a/indra/llui/llnotifications.cpp
+++ b/indra/llui/llnotifications.cpp
@@ -34,6 +34,7 @@
 
 #include "llnotifications.h"
 
+#include "llxmlnode.h"
 #include "lluictrl.h"
 #include "lluictrlfactory.h"
 #include "lldir.h"
diff --git a/indra/llui/llnotifications.h b/indra/llui/llnotifications.h
index 19895c3293..cd05db3c30 100644
--- a/indra/llui/llnotifications.h
+++ b/indra/llui/llnotifications.h
@@ -102,7 +102,6 @@
 #include "llfunctorregistry.h"
 #include "llpointer.h"
 #include "llinitparam.h"
-#include "llxmlnode.h"
 
 class LLNotification;
 typedef boost::shared_ptr<LLNotification> LLNotificationPtr;
@@ -160,7 +159,7 @@ public:
 	LLNotificationForm();
 	LLNotificationForm(const LLSD& sd);
 	LLNotificationForm(const std::string& name, 
-		const LLPointer<LLXMLNode> xml_node);
+		const LLPointer<class LLXMLNode> xml_node);
 
 	LLSD asLLSD() const;
 
diff --git a/indra/llui/llpanel.cpp b/indra/llui/llpanel.cpp
index 742427525b..095200ddc3 100644
--- a/indra/llui/llpanel.cpp
+++ b/indra/llui/llpanel.cpp
@@ -474,7 +474,7 @@ BOOL LLPanel::initPanelXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr outpu
 			{
 				//if we are exporting, we want to export the current xml
 				//not the referenced xml
-				LLXUIParser::instance().readXUI(node, params);
+				LLXUIParser::instance().readXUI(node, params, xml_filename);
 				Params output_params(params);
 				setupParamsForExport(output_params, parent);
 				output_node->setName(node->getName()->mString);
@@ -490,14 +490,15 @@ BOOL LLPanel::initPanelXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr outpu
 				return FALSE;
 			}
 
-			LLXUIParser::instance().readXUI(referenced_xml, params);
+			LLXUIParser::instance().readXUI(referenced_xml, params, xml_filename);
 
 			// add children using dimensions from referenced xml for consistent layout
 			setShape(params.rect);
 			LLUICtrlFactory::createChildren(this, referenced_xml, child_registry_t::instance());
 		}
 
-		LLXUIParser::instance().readXUI(node, params);
+		// ask LLUICtrlFactory for filename, since xml_filename might be empty
+		LLXUIParser::instance().readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName());
 
 		if (output_node)
 		{
diff --git a/indra/llui/llrngwriter.cpp b/indra/llui/llrngwriter.cpp
index cf23e3af15..7e3d4b92d3 100644
--- a/indra/llui/llrngwriter.cpp
+++ b/indra/llui/llrngwriter.cpp
@@ -108,7 +108,8 @@ void LLRNGWriter::addDefinition(const std::string& type_name, const LLInitParam:
 		
 		LLXMLNodePtr old_element_node = mElementNode;
 		LLXMLNodePtr old_child_node = mChildrenNode;
-		addDefinition(child_name, (*LLDefaultParamBlockRegistry::instance().getValue(type))());
+		//FIXME: add LLDefaultParamBlockRegistry back when working on schema generation
+		//addDefinition(child_name, (*LLDefaultParamBlockRegistry::instance().getValue(type))());
 		mElementNode = old_element_node;
 		mChildrenNode = old_child_node;
 
diff --git a/indra/llui/lluicolortable.cpp b/indra/llui/lluicolortable.cpp
index 087a99c2b0..5827c0d627 100644
--- a/indra/llui/lluicolortable.cpp
+++ b/indra/llui/lluicolortable.cpp
@@ -278,7 +278,7 @@ bool LLUIColorTable::loadFromFilename(const std::string& filename)
 	}
 
 	Params params;
-	LLXUIParser::instance().readXUI(root, params);
+	LLXUIParser::instance().readXUI(root, params, filename);
 
 	if(params.validateBlock())
 	{
diff --git a/indra/llui/lluictrlfactory.cpp b/indra/llui/lluictrlfactory.cpp
index 209ee76940..e2368cc05c 100644
--- a/indra/llui/lluictrlfactory.cpp
+++ b/indra/llui/lluictrlfactory.cpp
@@ -34,6 +34,8 @@
 
 #include "lluictrlfactory.h"
 
+#include "llxmlnode.h"
+
 #include <fstream>
 #include <boost/tokenizer.hpp>
 
@@ -94,7 +96,7 @@ void LLUICtrlFactory::loadWidgetTemplate(const std::string& widget_tag, LLInitPa
 
 	if (LLUICtrlFactory::getLayeredXMLNode(filename, root_node))
 	{
-		LLXUIParser::instance().readXUI(root_node, block);
+		LLXUIParser::instance().readXUI(root_node, block, filename);
 	}
 }
 
@@ -410,3 +412,39 @@ void LLUICtrlFactory::popFactoryFunctions()
 		mFactoryStack.pop_back();
 	}
 }
+
+//static 
+void LLUICtrlFactory::copyName(LLXMLNodePtr src, LLXMLNodePtr dest)
+{
+	dest->setName(src->getName()->mString);
+}
+
+// adds a widget and its param block to various registries
+//static 
+void LLUICtrlFactory::registerWidget(const std::type_info* widget_type, const std::type_info* param_block_type, dummy_widget_creator_func_t creator_func, const std::string& tag)
+{
+	// associate parameter block type with template .xml file
+	std::string* existing_tag = LLWidgetNameRegistry::instance().getValue(param_block_type);
+	if (existing_tag != NULL && *existing_tag != tag)
+	{
+		llerrs << "Duplicate entry for T::Params, try creating empty param block in derived classes that inherit T::Params" << llendl;
+	}
+	LLWidgetNameRegistry ::instance().defaultRegistrar().add(param_block_type, tag);
+	// associate widget type with factory function
+	LLDefaultWidgetRegistry::instance().defaultRegistrar().add(widget_type, creator_func);
+	LLWidgetTypeRegistry::instance().defaultRegistrar().add(tag, widget_type);
+	//FIXME: comment this in when working on schema generation
+	//LLDefaultParamBlockRegistry::instance().defaultRegistrar().add(widget_type, &getEmptyParamBlock<T>);
+}
+
+//static
+dummy_widget_creator_func_t* LLUICtrlFactory::getDefaultWidgetFunc(const std::type_info* widget_type)
+{
+	return LLDefaultWidgetRegistry::instance().getValue(widget_type);
+}
+
+//static 
+const std::string* LLUICtrlFactory::getWidgetTag(const std::type_info* widget_type)
+{
+	return LLWidgetNameRegistry::instance().getValue(widget_type);
+}
diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h
index 5e6dad312c..17e32dc7a9 100644
--- a/indra/llui/lluictrlfactory.h
+++ b/indra/llui/lluictrlfactory.h
@@ -36,7 +36,7 @@
 #include "llcallbackmap.h"
 #include "llinitparam.h"
 #include "llregistry.h"
-#include "llxmlnode.h"
+#include "v4color.h"
 #include "llfasttimer.h"
 
 #include "llxuiparser.h"
@@ -98,10 +98,11 @@ class LLDefaultWidgetRegistry
 {};
 
 // lookup function for generating empty param block by widget type
-typedef const LLInitParam::BaseBlock& (*empty_param_block_func_t)();
-class LLDefaultParamBlockRegistry
-:	public LLRegistrySingleton<const std::type_info*, empty_param_block_func_t, LLDefaultParamBlockRegistry, LLCompareTypeID>
-{};
+// this is used for schema generation
+//typedef const LLInitParam::BaseBlock& (*empty_param_block_func_t)();
+//class LLDefaultParamBlockRegistry
+//:	public LLRegistrySingleton<const std::type_info*, empty_param_block_func_t, LLDefaultParamBlockRegistry, LLCompareTypeID>
+//{};
 
 extern LLFastTimer::DeclareTimer FTM_WIDGET_SETUP;
 extern LLFastTimer::DeclareTimer FTM_WIDGET_CONSTRUCTION;
@@ -124,7 +125,7 @@ private:
 			// recursively initialize from base class param block
 			((typename PARAM_BLOCK::base_block_t&)mPrototype).fillFrom(ParamDefaults<typename PARAM_BLOCK::base_block_t, DUMMY>::instance().get());
 			// after initializing base classes, look up template file for this param block
-			std::string* param_block_tag = LLWidgetNameRegistry::instance().getValue(&typeid(PARAM_BLOCK));
+			const std::string* param_block_tag = getWidgetTag(&typeid(PARAM_BLOCK));
 			if (param_block_tag)
 			{
 				LLUICtrlFactory::loadWidgetTemplate(*param_block_tag, mPrototype);
@@ -241,7 +242,7 @@ fail:
 	template<class T>
 	static T* getDefaultWidget(const std::string& name)
 	{
-		dummy_widget_creator_func_t* dummy_func = LLDefaultWidgetRegistry::instance().getValue(&typeid(T));
+		dummy_widget_creator_func_t* dummy_func = getDefaultWidgetFunc(&typeid(T));
 		return dummy_func ? dynamic_cast<T*>((*dummy_func)(name)) : NULL;
 	}
 
@@ -254,6 +255,8 @@ fail:
 		return create<T>(params);
 	}
 
+	static void copyName(LLXMLNodePtr src, LLXMLNodePtr dest);
+
 	template<typename T>
 	static T* defaultBuilder(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node)
 	{
@@ -262,7 +265,7 @@ fail:
 		//#pragma message("Generating LLUICtrlFactory::defaultBuilder")
 		typename T::Params params(getDefaultParams<T>());
 
-		LLXUIParser::instance().readXUI(node, params);
+		LLXUIParser::instance().readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName());
 
 		if (output_node)
 		{
@@ -271,7 +274,7 @@ fail:
 			T::setupParamsForExport(output_params, parent);
 			// Export only the differences between this any default params
 			typename T::Params default_params(getDefaultParams<T>());
-			output_node->setName(node->getName()->mString);
+			copyName(node, output_node);
 			LLXUIParser::instance().writeXUI(
 				output_node, output_params, &default_params);
 		}
@@ -320,7 +323,15 @@ fail:
 
 	static void loadWidgetTemplate(const std::string& widget_tag, LLInitParam::BaseBlock& block);
 
+	// helper function for adding widget type info to various registries
+	static void registerWidget(const std::type_info* widget_type, const std::type_info* param_block_type, dummy_widget_creator_func_t creator_func, const std::string& tag);
+
 private:
+	// return default widget instance factory func for a given type
+	static dummy_widget_creator_func_t* getDefaultWidgetFunc(const std::type_info* widget_type);
+
+	static const std::string* getWidgetTag(const std::type_info* widget_type);
+
 	// this exists to get around dependency on llview
 	static void setCtrlParent(LLView* view, LLView* parent, S32 tab_group);
 
@@ -347,23 +358,12 @@ template<typename T>
 LLChildRegistry<DERIVED>::Register<T>::Register(const char* tag, LLWidgetCreatorFunc func)
 :	LLChildRegistry<DERIVED>::StaticRegistrar(tag, func.empty() ? (LLWidgetCreatorFunc)&LLUICtrlFactory::defaultBuilder<T> : func)
 {
-	const std::type_info* widget_type_infop = &typeid(T);
-	// associate parameter block type with template .xml file
-	std::string* existing_tag = LLWidgetNameRegistry ::instance().getValue(&typeid(typename T::Params));
-	if (existing_tag != NULL && *existing_tag != tag)
-	{
-		// duplicate entry for T::Params
-		// try creating empty param block in derived classes that inherit T::Params
-		int* crash = 0;
-		*crash = 0;
-	}
-	LLWidgetNameRegistry ::instance().defaultRegistrar().add(&typeid(typename T::Params), tag);
-	// associate widget type with factory function
-	LLDefaultWidgetRegistry::instance().defaultRegistrar().add(widget_type_infop, &LLUICtrlFactory::createDefaultWidget<T>);
-	LLWidgetTypeRegistry::instance().defaultRegistrar().add(tag, widget_type_infop);
-	LLDefaultParamBlockRegistry::instance().defaultRegistrar().add(widget_type_infop, &getEmptyParamBlock<T>);
+	// add this widget to various registries
+	LLUICtrlFactory::instance().registerWidget(&typeid(T), &typeid(typename T::Params), &LLUICtrlFactory::createDefaultWidget<T>, tag);
+	
+	// since registry_t depends on T, do this in line here
 	typedef typename T::child_registry_t registry_t;
-	LLChildRegistryRegistry::instance().defaultRegistrar().add(widget_type_infop, registry_t::instance());
+	LLChildRegistryRegistry::instance().defaultRegistrar().add(&typeid(T), registry_t::instance());
 }
 
 
diff --git a/indra/llui/lluistring.cpp b/indra/llui/lluistring.cpp
index 20ff71378e..3a1e656364 100644
--- a/indra/llui/lluistring.cpp
+++ b/indra/llui/lluistring.cpp
@@ -35,8 +35,6 @@
 #include "llsd.h"
 #include "lltrans.h"
 
-const LLStringUtil::format_map_t LLUIString::sNullArgs;
-
 LLFastTimer::DeclareTimer FTM_UI_STRING("UI String");
 
 
diff --git a/indra/llui/lluistring.h b/indra/llui/lluistring.h
index 195f21a6a7..763de4d6a3 100644
--- a/indra/llui/lluistring.h
+++ b/indra/llui/lluistring.h
@@ -95,8 +95,6 @@ public:
 	void insert(S32 charidx, const LLWString& wchars);
 	void replace(S32 charidx, llwchar wc);
 	
-	static const LLStringUtil::format_map_t sNullArgs;
-
 private:
 	void format();	
 	
-- 
cgit v1.2.3