diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2013-07-25 16:46:51 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2013-07-25 16:46:51 -0400 |
commit | d2386652f8a44c5adcc7fbcc65741649dd90aa2b (patch) | |
tree | 3e760a558cf5cdb02d2472d294b1007a8c188142 /indra/llxml | |
parent | 35bc91fc5dee77133fff0c0066e3e34689941dfd (diff) |
CHOP-962: Make LLControlVariable::setPersist() accept only enum.
Initial change made LLControlVariable::mPersist an enum, but retained
bool/BOOL public API. setPersist(true) set one value, setPersist(false) set
another, forcePersist() set the third. Per code review, expose enum to public,
make setPersist() (and LLControlVariable constructor, and LLControlGroup::
declareControl(), and all the LLControlGroup::declareMumble() methods, and all
the unit-test dummy declareMumble() method bodies) accept that enum. Remove
forcePersist(). Fix calls to LLControlGroup::declareMumble() accordingly.
Also rename PERSIST_YES to PERSIST_NONDFT, also per code review.
Diffstat (limited to 'indra/llxml')
-rwxr-xr-x | indra/llxml/llcontrol.cpp | 75 | ||||
-rwxr-xr-x | indra/llxml/llcontrol.h | 42 |
2 files changed, 56 insertions, 61 deletions
diff --git a/indra/llxml/llcontrol.cpp b/indra/llxml/llcontrol.cpp index 6e11a5f6f3..16f2290787 100755 --- a/indra/llxml/llcontrol.cpp +++ b/indra/llxml/llcontrol.cpp @@ -132,14 +132,14 @@ 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 hidefromsettingseditor) + ePersist persist, bool hidefromsettingseditor) : mName(name), mComment(comment), mType(type), - mPersist(persist? PERSIST_YES : PERSIST_NO), + mPersist(persist), mHideFromSettingsEditor(hidefromsettingseditor) { - if (persist && mComment.empty()) + if ((persist != PERSIST_NO) && mComment.empty()) { llerrs << "Must supply a comment for control " << mName << llendl; } @@ -260,14 +260,9 @@ void LLControlVariable::setDefaultValue(const LLSD& value) } } -void LLControlVariable::setPersist(bool state) +void LLControlVariable::setPersist(ePersist state) { - mPersist = state? PERSIST_YES : PERSIST_NO; -} - -void LLControlVariable::forcePersist() -{ - mPersist = PERSIST_ALWAYS; + mPersist = state; } void LLControlVariable::setHiddenFromSettingsEditor(bool hide) @@ -307,13 +302,13 @@ bool LLControlVariable::shouldSave(bool nondefault_only) if (mPersist == PERSIST_ALWAYS) return true; - // PERSIST_YES + // PERSIST_NONDFT // If caller doesn't need us to filter, just save. if (! nondefault_only) return true; - // PERSIST_YES, but caller only wants us to save this variable if its - // value differs from default. + // PERSIST_NONDFT: caller only wants us to save this variable if its value + // differs from default. if (isDefault()) // never been altered return false; @@ -379,12 +374,12 @@ std::string LLControlGroup::typeEnumToString(eControlType typeenum) return mTypeString[typeenum]; } -LLControlVariable* LLControlGroup::declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist, BOOL hidefromsettingseditor) +LLControlVariable* LLControlGroup::declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, LLControlVariable::ePersist persist, BOOL hidefromsettingseditor) { LLControlVariable* existing_control = getControl(name); if (existing_control) { - if (persist && existing_control->isType(type)) + if ((persist != LLControlVariable::PERSIST_NO) && existing_control->isType(type)) { if (!existing_control->llsd_compare(existing_control->getDefault(), initial_val)) { @@ -407,57 +402,57 @@ LLControlVariable* LLControlGroup::declareControl(const std::string& name, eCont return control; } -LLControlVariable* LLControlGroup::declareU32(const std::string& name, const U32 initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareU32(const std::string& name, const U32 initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_U32, (LLSD::Integer) initial_val, comment, persist); } -LLControlVariable* LLControlGroup::declareS32(const std::string& name, const S32 initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareS32(const std::string& name, const S32 initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_S32, initial_val, comment, persist); } -LLControlVariable* LLControlGroup::declareF32(const std::string& name, const F32 initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareF32(const std::string& name, const F32 initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_F32, initial_val, comment, persist); } -LLControlVariable* LLControlGroup::declareBOOL(const std::string& name, const BOOL initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareBOOL(const std::string& name, const BOOL initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_BOOLEAN, initial_val, comment, persist); } -LLControlVariable* LLControlGroup::declareString(const std::string& name, const std::string& initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareString(const std::string& name, const std::string& initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_STRING, initial_val, comment, persist); } -LLControlVariable* LLControlGroup::declareVec3(const std::string& name, const LLVector3 &initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareVec3(const std::string& name, const LLVector3 &initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_VEC3, initial_val.getValue(), comment, persist); } -LLControlVariable* LLControlGroup::declareVec3d(const std::string& name, const LLVector3d &initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareVec3d(const std::string& name, const LLVector3d &initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_VEC3D, initial_val.getValue(), comment, persist); } -LLControlVariable* LLControlGroup::declareRect(const std::string& name, const LLRect &initial_val, const std::string& comment, BOOL persist) +LLControlVariable* LLControlGroup::declareRect(const std::string& name, const LLRect &initial_val, const std::string& comment, LLControlVariable::ePersist persist) { return declareControl(name, TYPE_RECT, initial_val.getValue(), comment, persist); } -LLControlVariable* LLControlGroup::declareColor4(const std::string& name, const LLColor4 &initial_val, const std::string& comment, BOOL persist ) +LLControlVariable* LLControlGroup::declareColor4(const std::string& name, const LLColor4 &initial_val, const std::string& comment, LLControlVariable::ePersist persist ) { return declareControl(name, TYPE_COL4, initial_val.getValue(), comment, persist); } -LLControlVariable* LLControlGroup::declareColor3(const std::string& name, const LLColor3 &initial_val, const std::string& comment, BOOL persist ) +LLControlVariable* LLControlGroup::declareColor3(const std::string& name, const LLColor3 &initial_val, const std::string& comment, LLControlVariable::ePersist persist ) { return declareControl(name, TYPE_COL3, initial_val.getValue(), comment, persist); } -LLControlVariable* LLControlGroup::declareLLSD(const std::string& name, const LLSD &initial_val, const std::string& comment, BOOL persist ) +LLControlVariable* LLControlGroup::declareLLSD(const std::string& name, const LLSD &initial_val, const std::string& comment, LLControlVariable::ePersist persist ) { return declareControl(name, TYPE_LLSD, initial_val, comment, persist); } @@ -688,11 +683,11 @@ U32 LLControlGroup::loadFromFileLegacy(const std::string& filename, BOOL require switch(declare_as) { case TYPE_COL4: - declareColor4(name, LLColor4::white, LLStringUtil::null, NO_PERSIST); + declareColor4(name, LLColor4::white, LLStringUtil::null, LLControlVariable::PERSIST_NO); break; case TYPE_STRING: default: - declareString(name, LLStringUtil::null, LLStringUtil::null, NO_PERSIST); + declareString(name, LLStringUtil::null, LLStringUtil::null, LLControlVariable::PERSIST_NO); break; } } @@ -877,13 +872,14 @@ U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_v for(LLSD::map_const_iterator itr = settings.beginMap(); itr != settings.endMap(); ++itr) { - bool persist = true; + LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT; std::string const & name = itr->first; LLSD const & control_map = itr->second; if(control_map.has("Persist")) { - persist = control_map["Persist"].asInteger(); + persist = control_map["Persist"].asInteger()? + LLControlVariable::PERSIST_NONDFT : LLControlVariable::PERSIST_NO; } // Sometimes we want to use the settings system to provide cheap persistence, but we @@ -939,13 +935,6 @@ U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_v // the initial set of default settings files (set_default_values) // -- or we're loading user settings last saved by a viewer that // supports a superset of the variables we know. - LLControlVariable* control = declareControl(name, - typeStringToEnum(control_map["Type"].asString()), - control_map["Value"], - control_map["Comment"].asString(), - persist, - hidefromsettingseditor - ); // CHOP-962: if we're loading an unrecognized user setting, make // sure we save it later. If you try an experimental viewer, tweak // a new setting, briefly revert to an old viewer, then return to @@ -953,12 +942,12 @@ U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_v // setting you changed. if (! set_default_values) { - // Using forcePersist() insists that saveToFile() (which calls + // Using PERSIST_ALWAYS insists that saveToFile() (which calls // LLControlVariable::shouldSave()) must save this control // variable regardless of its value. We can safely set this // LLControlVariable persistent because the 'persistent' flag // is not itself persisted! - control->forcePersist(); + persist = LLControlVariable::PERSIST_ALWAYS; // We want to mention unrecognized user settings variables // (e.g. from a newer version of the viewer) in the log. But // we also arrive here for Boolean variables generated by @@ -974,6 +963,14 @@ U32 LLControlGroup::loadFromFile(const std::string& filename, bool set_default_v << " settings variable " << name << LL_ENDL; } } + + declareControl(name, + typeStringToEnum(control_map["Type"].asString()), + control_map["Value"], + control_map["Comment"].asString(), + persist, + hidefromsettingseditor + ); } ++validitems; diff --git a/indra/llxml/llcontrol.h b/indra/llxml/llcontrol.h index 5d6ac33780..e1f9be80dd 100755 --- a/indra/llxml/llcontrol.h +++ b/indra/llxml/llcontrol.h @@ -72,8 +72,6 @@ class LLVector3d; class LLColor4; class LLColor3; -const BOOL NO_PERSIST = FALSE; - typedef enum e_control_type { TYPE_U32 = 0, @@ -100,17 +98,18 @@ public: typedef boost::signals2::signal<bool(LLControlVariable* control, const LLSD&), boost_boolean_combiner> validate_signal_t; typedef boost::signals2::signal<void(LLControlVariable* control, const LLSD&, const LLSD&)> commit_signal_t; -private: - enum + enum ePersist { PERSIST_NO, // don't save this var - PERSIST_YES, // save this var if differs from default + PERSIST_NONDFT, // save this var if differs from default PERSIST_ALWAYS // save this var even if has default value - } mPersist; + }; +private: std::string mName; std::string mComment; eControlType mType; + ePersist mPersist; bool mHideFromSettingsEditor; std::vector<LLSD> mValues; @@ -120,7 +119,7 @@ private: public: LLControlVariable(const std::string& name, eControlType type, LLSD initial, const std::string& comment, - bool persist = true, bool hidefromsettingseditor = false); + ePersist persist = PERSIST_NONDFT, bool hidefromsettingseditor = false); virtual ~LLControlVariable(); @@ -148,8 +147,7 @@ public: 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); // persist or not depending on value - void forcePersist(); // always persist regardless of value + void setPersist(ePersist); void setHiddenFromSettingsEditor(bool hide); void setComment(const std::string& comment); @@ -215,18 +213,18 @@ public: }; void applyToAll(ApplyFunctor* func); - LLControlVariable* declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, BOOL persist, BOOL hidefromsettingseditor = FALSE); - LLControlVariable* declareU32(const std::string& name, U32 initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareS32(const std::string& name, S32 initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareF32(const std::string& name, F32 initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareBOOL(const std::string& name, BOOL initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareString(const std::string& name, const std::string &initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareVec3(const std::string& name, const LLVector3 &initial_val,const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareVec3d(const std::string& name, const LLVector3d &initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareRect(const std::string& name, const LLRect &initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareColor4(const std::string& name, const LLColor4 &initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareColor3(const std::string& name, const LLColor3 &initial_val, const std::string& comment, BOOL persist = TRUE); - LLControlVariable* declareLLSD(const std::string& name, const LLSD &initial_val, const std::string& comment, BOOL persist = TRUE); + LLControlVariable* declareControl(const std::string& name, eControlType type, const LLSD initial_val, const std::string& comment, LLControlVariable::ePersist persist, BOOL hidefromsettingseditor = FALSE); + LLControlVariable* declareU32(const std::string& name, U32 initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareS32(const std::string& name, S32 initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareF32(const std::string& name, F32 initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareBOOL(const std::string& name, BOOL initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareString(const std::string& name, const std::string &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareVec3(const std::string& name, const LLVector3 &initial_val,const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareVec3d(const std::string& name, const LLVector3d &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareRect(const std::string& name, const LLRect &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareColor4(const std::string& name, const LLColor4 &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareColor3(const std::string& name, const LLColor3 &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); + LLControlVariable* declareLLSD(const std::string& name, const LLSD &initial_val, const std::string& comment, LLControlVariable::ePersist persist = LLControlVariable::PERSIST_NONDFT); std::string getString(const std::string& name); std::string getText(const std::string& name); @@ -375,7 +373,7 @@ private: init_value = convert_to_llsd(default_value); if(type < TYPE_COUNT) { - group.declareControl(name, type, init_value, comment, FALSE); + group.declareControl(name, type, init_value, comment, LLControlVariable::PERSIST_NO); return true; } return false; |