aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-01-21 15:53:04 +0000
committerGravatar Sadie Powell2022-01-21 16:36:43 +0000
commita51d044c82d2e39a2d9a79dd2ce181ef7bd32b02 (patch)
tree3df8fc518ec12122c4096431d521d9deef58b5b0 /include
parentFix aliases which require routing to be broadcast out. (diff)
Fix various edge cases in extensible synchronisation.
- Fix not forwarding the accountid extensible if it is set. - Rename the variadic Set() overload to SetFwd(). - Re-add the `const T&` overload of Set(). - Move `bool synced` to SimpleExtItem from StringExtItem. - Only sync extensibles if their instance is marked as syncable.
Diffstat (limited to 'include')
-rw-r--r--include/extensible.h36
1 files changed, 23 insertions, 13 deletions
diff --git a/include/extensible.h b/include/extensible.h
index a416f91a4..0e86f8272 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -191,14 +191,20 @@ template <typename T, typename Del = std::default_delete<T>>
class SimpleExtItem
: public ExtensionItem
{
+ protected:
+ /** Whether to sync this StringExtItem across the network. */
+ bool synced;
+
public:
/** Initializes an instance of the SimpleExtItem class.
* @param parent The module which created this SimpleExtItem.
* @param Key The name of the extension item (e.g. foo_bar).
* @param exttype The type of Extensible that this SimpleExtItem applies to.
+ * @param sync Whether this SimpleExtItem should be broadcast to other servers.
*/
- SimpleExtItem(Module* parent, const std::string& Key, ExtensionType exttype)
+ SimpleExtItem(Module* parent, const std::string& Key, ExtensionType exttype, bool sync = false)
: ExtensionItem(parent, Key, exttype)
+ , synced(sync)
{
}
@@ -211,20 +217,28 @@ class SimpleExtItem
{
T* old = static_cast<T*>(SetRaw(container, value));
Delete(container, old);
- if (sync)
+ if (sync && synced)
Sync(container, value);
}
+ inline void Set(Extensible* container, const T& value, bool sync = true)
+ {
+ Set(container, new T(value), sync);
+ }
+
template <typename... Args>
- inline void Set(Extensible* container, Args&&... args)
+ inline void SetFwd(Extensible* container, Args&&... args)
{
- Set(container, new T(std::forward<Args>(args)...));
+ // Forwarded arguments are for complex types which are assumed to not
+ // be synced across the network. You can manually call Sync() if this
+ // is not the case.
+ Set(container, new T(std::forward<Args>(args)...), false);
}
inline void Unset(Extensible* container, bool sync = true)
{
Delete(container, UnsetRaw(container));
- if (sync)
+ if (synced && sync)
Sync(container, nullptr);
}
@@ -239,10 +253,6 @@ class SimpleExtItem
class CoreExport StringExtItem
: public SimpleExtItem<std::string>
{
- protected:
- /** Whether to sync this StringExtItem across the network. */
- bool synced;
-
public:
/** Initializes an instance of the StringExtItem class.
* @param owner The module which created this StringExtItem.
@@ -300,7 +310,7 @@ class CoreExport IntExtItem
/** Sets a value for this IntExtItem.
* @param container A container that the IntExtItem should be set on.
* @param value The new value for this IntExtItem.
- * @param sync Whether to sync this value to other servers.
+ * @param sync If syncable then whether to sync this value to other servers.
*/
void Set(Extensible* container, intptr_t value, bool sync = true);
@@ -312,7 +322,7 @@ class CoreExport IntExtItem
/** Removes the value for this IntExtItem.
* @param container A container the ExtensionItem should be removed from.
- * @param sync Whether to sync this unset to the network.
+ * @param sync If syncable then whether to sync this unset to the network.
*/
void Unset(Extensible* container, bool sync = true);
};
@@ -360,13 +370,13 @@ class CoreExport BoolExtItem
/** Sets a value for this BoolExtItem.
* @param container A container that the BoolExtItem should be set on.
- * @param sync Whether to sync this set to the network.
+ * @param sync If syncable then whether to sync this set to the network.
*/
void Set(Extensible* container, bool sync = true);
/** Removes the value for this BoolExtItem.
* @param container A container the ExtensionItem should be removed from.
- * @param sync Whether to sync this unset to the network.
+ * @param sync If syncable then whether to sync this unset to the network.
*/
void Unset(Extensible* container, bool sync = true);
};