diff options
Diffstat (limited to 'indra/llxml')
| -rw-r--r-- | indra/llxml/llcontrol.cpp | 86 | ||||
| -rw-r--r-- | indra/llxml/llcontrol.h | 30 | 
2 files changed, 92 insertions, 24 deletions
| diff --git a/indra/llxml/llcontrol.cpp b/indra/llxml/llcontrol.cpp index c5d86f161a..c967855e93 100644 --- a/indra/llxml/llcontrol.cpp +++ b/indra/llxml/llcontrol.cpp @@ -101,7 +101,7 @@ bool LLControlVariable::llsd_compare(const LLSD& a, const LLSD & b)  LLControlVariable::LLControlVariable(const std::string& name, eControlType type,  							 LLSD initial, const std::string& comment, -							 BOOL persist) +							 bool persist)  	: mName(name),  	  mComment(comment),  	  mType(type), @@ -121,7 +121,7 @@ LLControlVariable::~LLControlVariable()  {  } -void LLControlVariable::setValue(const LLSD& value, bool saved_value) +LLSD LLControlVariable::getComparableValue(const LLSD& value)  {  	// *FIX:MEP - The following is needed to make the LLSD::ImplString   	// work with boolean controls... @@ -131,11 +131,11 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value)  		BOOL temp;  		if(LLStringUtil::convertToBOOL(value.asString(), temp))   		{ -			storable_value = temp; +			storable_value = (bool)temp;  		}  		else  		{ -			storable_value = FALSE; +			storable_value = false;  		}  	}  	else @@ -143,6 +143,12 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value)  		storable_value = value;  	} +	return storable_value; +} + +void LLControlVariable::setValue(const LLSD& value, bool saved_value) +{ +	LLSD storable_value = getComparableValue(value);  	bool value_changed = llsd_compare(getValue(), storable_value) == FALSE;  	if(saved_value)  	{ @@ -184,12 +190,46 @@ void LLControlVariable::setValue(const LLSD& value, bool saved_value)      }  } +void LLControlVariable::setDefaultValue(const LLSD& value) +{ +	// Set the control variables value and make it  +	// the default value. If the active value is changed, +	// send the signal. +	// *NOTE: Default values are not saved, only read. + +	LLSD comparable_value = getComparableValue(value); +	bool value_changed = (llsd_compare(getValue(), comparable_value) == FALSE); +	resetToDefault(false); +	mValues[0] = comparable_value; +	if(value_changed) +	{ +		firePropertyChanged(); +	} +} + +void LLControlVariable::setPersist(bool state) +{ +	mPersist = state; +} + +void LLControlVariable::setComment(const std::string& comment) +{ +	mComment = comment; +} +  void LLControlVariable::resetToDefault(bool fire_signal)  {  	//The first setting is always the default  	//Pop to it and fire off the listener -	while(mValues.size() > 1) mValues.pop_back(); -	if(fire_signal) firePropertyChanged(); +	while(mValues.size() > 1) +	{ +		mValues.pop_back(); +	} +	 +	if(fire_signal)  +	{ +		firePropertyChanged(); +	}  }  bool LLControlVariable::isSaveValueDefault() @@ -206,10 +246,10 @@ LLSD LLControlVariable::getSaveValue() const  	return mValues[0];  } -LLControlVariable*	LLControlGroup::getControl(const std::string& name) +LLPointer<LLControlVariable> LLControlGroup::getControl(const std::string& name)  {  	ctrl_name_table_t::iterator iter = mNameTable.find(name); -	return iter == mNameTable.end() ? NULL : iter->second; +	return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second;  } @@ -238,7 +278,6 @@ LLControlGroup::~LLControlGroup()  void LLControlGroup::cleanup()  { -	for_each(mNameTable.begin(), mNameTable.end(), DeletePairedPointer());  	mNameTable.clear();  } @@ -264,6 +303,7 @@ BOOL LLControlGroup::declareControl(const std::string& name, eControlType type,  		mNameTable[name]->setValue(initial_val);  		return TRUE;  	} +  	// if not, create the control and add it to the name table  	LLControlVariable* control = new LLControlVariable(name, type, initial_val, comment, persist);  	mNameTable[name] = control;	 @@ -979,7 +1019,7 @@ U32 LLControlGroup::saveToFile(const std::string& filename, BOOL nondefault_only  	return num_saved;  } -U32 LLControlGroup::loadFromFile(const std::string& filename) +U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_values)  {  	std::string name;  	LLSD settings; @@ -1002,7 +1042,7 @@ U32 LLControlGroup::loadFromFile(const std::string& filename)  	}  	U32	validitems = 0; -	int persist = 1; +	bool persist = false;  	for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr)  	{  		name = (*itr).first; @@ -1017,11 +1057,31 @@ U32 LLControlGroup::loadFromFile(const std::string& filename)  		LLControlVariable* existing_control = getControl(name);  		if(existing_control)  		{ -			// Check persistence. If not persisted, we shouldn't be loading. -			if(existing_control->isPersisted()) +			if(set_default_values)  			{ +				// Override all previously set properties of this control. +				// ... except for type. The types must match. +				eControlType new_type = typeStringToEnum(control_map["Type"].asString()); +				if(existing_control->isType(new_type)) +				{ +					existing_control->setDefaultValue(control_map["Value"]); +					existing_control->setPersist(persist); +					existing_control->setComment(control_map["Comment"].asString()); +				} +				else +				{ +					llerrs << "Mismatched type of control variable '" +						   << name << "' found while loading '" +						   << filename << "'." << llendl; +				} +			} +			else if(existing_control->isPersisted()) +			{ +				  				existing_control->setValue(control_map["Value"]);  			} +			// *NOTE: If not persisted and not setting defaults,  +			// the value should not get loaded.  		}  		else  		{ diff --git a/indra/llxml/llcontrol.h b/indra/llxml/llcontrol.h index 289e85b8a4..b67c237071 100644 --- a/indra/llxml/llcontrol.h +++ b/indra/llxml/llcontrol.h @@ -83,7 +83,7 @@ typedef enum e_control_type  	TYPE_COUNT  } eControlType; -class LLControlVariable +class LLControlVariable : public LLRefCount  {  	friend class LLControlGroup;  	typedef boost::signal<void(const LLSD&)> signal_t; @@ -92,7 +92,7 @@ private:  	std::string		mName;  	std::string		mComment;  	eControlType	mType; -	BOOL			mPersist; +	bool mPersist;  	std::vector<LLSD> mValues;  	signal_t mSignal; @@ -100,7 +100,7 @@ private:  public:  	LLControlVariable(const std::string& name, eControlType type,  					  LLSD initial, const std::string& comment, -					  BOOL persist = TRUE); +					  bool persist = true);  	virtual ~LLControlVariable(); @@ -108,33 +108,41 @@ public:  	const std::string& getComment() const { return mComment; }  	eControlType type()		{ return mType; } -	BOOL isType(eControlType tp) { return tp == mType; } +	bool isType(eControlType tp) { return tp == mType; } -	void resetToDefault(bool fire_signal = TRUE); +	void resetToDefault(bool fire_signal = false);  	signal_t* getSignal() { return &mSignal; }  	bool isDefault() { return (mValues.size() == 1); }  	bool isSaveValueDefault();  	bool isPersisted() { return mPersist; } -	void set(const LLSD& val)	{ setValue(val); }  	LLSD get()			const	{ return getValue(); } -	LLSD getDefault()	const	{ return mValues.front(); }  	LLSD getValue()		const	{ return mValues.back(); } +	LLSD getDefault()	const	{ return mValues.front(); }  	LLSD getSaveValue() const; + +	void set(const LLSD& val)	{ setValue(val); }  	void setValue(const LLSD& value, bool saved_value = TRUE); +	void setDefaultValue(const LLSD& value); +	void setPersist(bool state); +	void setComment(const std::string& comment); +  	void firePropertyChanged()  	{  		mSignal(mValues.back());  	} -	bool llsd_compare(const LLSD& a, const LLSD& b); +private: +	LLSD getComparableValue(const LLSD& value); +	bool llsd_compare(const LLSD& a, const LLSD & b); +  };  //const U32 STRING_CACHE_SIZE = 10000;  class LLControlGroup  {  protected: -	typedef std::map<std::string, LLControlVariable* > ctrl_name_table_t; +	typedef std::map<std::string, LLPointer<LLControlVariable> > ctrl_name_table_t;  	ctrl_name_table_t mNameTable;  	std::set<std::string> mWarnings;  	std::string mTypeString[TYPE_COUNT]; @@ -146,7 +154,7 @@ public:  	~LLControlGroup();  	void cleanup(); -	LLControlVariable*	getControl(const std::string& name); +	LLPointer<LLControlVariable> getControl(const std::string& name);  	struct ApplyFunctor  	{ @@ -213,7 +221,7 @@ public:  	// as the given type.  	U32	loadFromFileLegacy(const std::string& filename, BOOL require_declaration = TRUE, eControlType declare_as = TYPE_STRING);   	U32 saveToFile(const std::string& filename, BOOL nondefault_only); - 	U32	loadFromFile(const std::string& filename); + 	U32	loadFromFile(const std::string& filename, bool default_values = false);  	void	resetToDefaults(); | 
