proxygen
|
#include <Settings.h>
Public Member Functions | |
template<class T , std::atomic< uint64_t > * P> | |
detail::SnapshotSettingWrapper< T > | operator() (detail::SettingWrapper< T, P > &&setting) |
Snapshot ()=default | |
void | publish () override |
bool | setFromString (StringPiece settingName, StringPiece newValue, StringPiece reason) override |
Optional< SettingsInfo > | getAsString (StringPiece settingName) const override |
bool | resetToDefault (StringPiece settingName) override |
void | forEachSetting (const std::function< void(const SettingMetadata &, StringPiece, StringPiece)> &func) const override |
Friends | |
template<typename T > | |
class | detail::SnapshotSettingWrapper |
Captures the current state of all setting values and allows updating multiple settings at once, with verification and rollback.
A single snapshot cannot be used concurrently from different threads. Multiple concurrent snapshots are safe. Passing a single snapshot from one thread to another is safe as long as the user properly synchronizes the handoff.
Example usage:
folly::settings::Snapshot snapshot; // FOLLY_SETTING(project, name) refers to the globally visible value // snapshot(FOLLY_SETTING(project, name)) refers to the value saved in the // snapshot FOLLY_SETTING(project, name).set(new_value); assert(*FOLLY_SETTING(project, name) == new_value); assert(*snapshot(FOLLY_SETTING(project, name)) == old_value);
snapshot(FOLLY_SETTING(project, name)).set(new_snapshot_value); assert(*FOLLY_SETTING(project, name) == new_value); assert(*snapshot(FOLLY_SETTING(project, name)) == new_snapshot_value);
// At this point we can discard the snapshot and forget new_snapshot_value, // or choose to publish: snapshot.publish(); assert(*FOLLY_SETTING(project, name) == new_snapshot_value);
Definition at line 267 of file Settings.h.
|
default |
Returns a snapshot of all current setting values. Global settings changes will not be visible in the snapshot, and vice versa.
|
override |
Iterates over all known settings and calls func(meta, to<string>(value), reason) for each.
Definition at line 95 of file Settings.cpp.
References map(), and folly::value().
Referenced by TEST().
|
override |
Definition at line 75 of file Settings.cpp.
References folly::none, and folly::Range< Iter >::str().
Referenced by TEST().
|
inline |
Wraps a global FOLLY_SETTING(a, b) and returns a snapshot-local wrapper.
Definition at line 273 of file Settings.h.
|
override |
Apply all settings updates from this snapshot to the global state unconditionally.
Definition at line 176 of file Settings.cpp.
Referenced by TEST().
|
override |
Reset the value of the setting identified by name to its default value. The reason will be set to "default".
Definition at line 85 of file Settings.cpp.
References folly::Range< Iter >::str().
Referenced by TEST().
|
override |
Look up a setting by name, and update the value from a string representation.
std::runtime_error | If there's a conversion error. |
Definition at line 62 of file Settings.cpp.
References folly::Range< Iter >::str().
Referenced by TEST().
|
friend |
Definition at line 328 of file Settings.h.