From ffdcf33364ebfdc1829cb7c7eea6ae4c908d12f1 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 12 Jun 2024 16:42:39 -0400 Subject: Extract TempSet from llcallbacklist.cpp into its own tempset.h. --- indra/llcommon/tempset.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 indra/llcommon/tempset.h (limited to 'indra/llcommon/tempset.h') diff --git a/indra/llcommon/tempset.h b/indra/llcommon/tempset.h new file mode 100755 index 0000000000..e1496bd5fc --- /dev/null +++ b/indra/llcommon/tempset.h @@ -0,0 +1,41 @@ +/** + * @file tempset.h + * @author Nat Goodspeed + * @date 2024-06-12 + * @brief Temporarily override a variable for scope duration, then restore + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Copyright (c) 2024, Linden Research, Inc. + * $/LicenseInfo$ + */ + +#if ! defined(LL_TEMPSET_H) +#define LL_TEMPSET_H + +// RAII class to set specified variable to specified value +// only for the duration of containing scope +template +class TempSet +{ +public: + TempSet(VAR& var, const VALUE& value): + mVar(var), + mOldValue(mVar) + { + mVar = value; + } + + TempSet(const TempSet&) = delete; + TempSet& operator=(const TempSet&) = delete; + + ~TempSet() + { + mVar = mOldValue; + } + +private: + VAR& mVar; + VALUE mOldValue; +}; + +#endif /* ! defined(LL_TEMPSET_H) */ -- cgit v1.2.3 From 68313aa2defcc7d6e5ebbd96344d78f3a31fdb9a Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 20 Aug 2024 20:55:48 -0400 Subject: Fix TempSet to use type VAR to store mOldValue. In fact we set mOldValue from mVar, and restore mVar from mOldValue, so the VAR type makes the most sense. The previous way, you'd get actual errors if you tried to use TempSet(pointervar, nullptr): that declared mOldValue to be nullptr_t, which you can't initialize from mVar. --- indra/llcommon/tempset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/tempset.h') diff --git a/indra/llcommon/tempset.h b/indra/llcommon/tempset.h index e1496bd5fc..07e607a576 100755 --- a/indra/llcommon/tempset.h +++ b/indra/llcommon/tempset.h @@ -35,7 +35,7 @@ public: private: VAR& mVar; - VALUE mOldValue; + VAR mOldValue; }; #endif /* ! defined(LL_TEMPSET_H) */ -- cgit v1.2.3 From 03d7f2b84daf9ab991de6cad7d6149abda1ef716 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 28 Aug 2024 21:16:56 -0400 Subject: Ditch trailing spaces. --- indra/llcommon/tempset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/tempset.h') diff --git a/indra/llcommon/tempset.h b/indra/llcommon/tempset.h index 07e607a576..773f19f756 100755 --- a/indra/llcommon/tempset.h +++ b/indra/llcommon/tempset.h @@ -3,7 +3,7 @@ * @author Nat Goodspeed * @date 2024-06-12 * @brief Temporarily override a variable for scope duration, then restore - * + * * $LicenseInfo:firstyear=2024&license=viewerlgpl$ * Copyright (c) 2024, Linden Research, Inc. * $/LicenseInfo$ -- cgit v1.2.3