summaryrefslogtreecommitdiff
path: root/src/mongo/base/encoded_value_storage.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/base/encoded_value_storage.h')
-rw-r--r--src/mongo/base/encoded_value_storage.h81
1 files changed, 39 insertions, 42 deletions
diff --git a/src/mongo/base/encoded_value_storage.h b/src/mongo/base/encoded_value_storage.h
index 9d83aa7617b..c7022de6821 100644
--- a/src/mongo/base/encoded_value_storage.h
+++ b/src/mongo/base/encoded_value_storage.h
@@ -33,54 +33,51 @@
namespace mongo {
- struct ZeroInitTag_t {
- ZeroInitTag_t() {
- };
- };
+struct ZeroInitTag_t {
+ ZeroInitTag_t(){};
+};
- const ZeroInitTag_t kZeroInitTag;
+const ZeroInitTag_t kZeroInitTag;
- template<typename Layout, typename ConstView, typename View>
- class EncodedValueStorage {
- protected:
- EncodedValueStorage() {
- }
+template <typename Layout, typename ConstView, typename View>
+class EncodedValueStorage {
+protected:
+ EncodedValueStorage() {}
- // This explicit constructor is provided to allow for easy zeroing
- // during creation of a value. You might prefer this over an
- // uninitialised value if the zeroed version provides a useful base
- // state. Such cases might include a set of counters that begin at
- // zero, flags that start off false or a larger structure where some
- // significant portion of storage falls into those kind of use cases.
- // Use this where you might have used calloc(1, sizeof(type)) in C.
- //
- // The added value of providing it as a constructor lies in the ability
- // of subclasses to easily inherit a zeroed base state during
- // initialization.
- explicit EncodedValueStorage(ZeroInitTag_t) {
- std::memset(_data, 0, sizeof(_data));
- }
+ // This explicit constructor is provided to allow for easy zeroing
+ // during creation of a value. You might prefer this over an
+ // uninitialised value if the zeroed version provides a useful base
+ // state. Such cases might include a set of counters that begin at
+ // zero, flags that start off false or a larger structure where some
+ // significant portion of storage falls into those kind of use cases.
+ // Use this where you might have used calloc(1, sizeof(type)) in C.
+ //
+ // The added value of providing it as a constructor lies in the ability
+ // of subclasses to easily inherit a zeroed base state during
+ // initialization.
+ explicit EncodedValueStorage(ZeroInitTag_t) {
+ std::memset(_data, 0, sizeof(_data));
+ }
- public:
+public:
+ View view() {
+ return _data;
+ }
- View view() {
- return _data;
- }
+ ConstView constView() const {
+ return _data;
+ }
- ConstView constView() const {
- return _data;
- }
+ operator View() {
+ return view();
+ }
- operator View() {
- return view();
- }
+ operator ConstView() const {
+ return constView();
+ }
- operator ConstView() const {
- return constView();
- }
+private:
+ char _data[sizeof(Layout)];
+};
- private:
- char _data[sizeof(Layout)];
- };
-
-} // namespace mongo
+} // namespace mongo