MongoDB C++ Driver
legacy-1.1.2
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
mongo
base
encoded_value_storage.h
1
/* Copyright 2014 MongoDB Inc.
2
*
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
6
*
7
* http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
16
#pragma once
17
18
#include <cstring>
19
20
#include "mongo/base/data_view.h"
21
22
namespace
mongo
{
23
24
struct
ZeroInitTag_t
{
25
ZeroInitTag_t
(){};
26
};
27
28
const
ZeroInitTag_t
kZeroInitTag;
29
30
template
<
typename
Layout,
typename
ConstView,
typename
View>
31
class
EncodedValueStorage
{
32
protected
:
33
EncodedValueStorage
() {}
34
35
// This explicit constructor is provided to allow for easy zeroing
36
// during creation of a value. You might prefer this over an
37
// uninitialised value if the zeroed version provides a useful base
38
// state. Such cases might include a set of counters that begin at
39
// zero, flags that start off false or a larger structure where some
40
// significant portion of storage falls into those kind of use cases.
41
// Use this where you might have used calloc(1, sizeof(type)) in C.
42
//
43
// The added value of providing it as a constructor lies in the ability
44
// of subclasses to easily inherit a zeroed base state during
45
// initialization.
46
explicit
EncodedValueStorage
(
ZeroInitTag_t
) {
47
std::memset(_data, 0,
sizeof
(_data));
48
}
49
50
public
:
51
View view() {
52
return
_data;
53
}
54
55
ConstView constView()
const
{
56
return
_data;
57
}
58
59
operator
View() {
60
return
view();
61
}
62
63
operator
ConstView()
const
{
64
return
constView();
65
}
66
67
private
:
68
char
_data[
sizeof
(Layout)];
69
};
70
71
}
// namespace mongo
mongo
Utility functions for parsing numbers from strings.
Definition:
compare_numbers.h:20
mongo::ZeroInitTag_t
Definition:
encoded_value_storage.h:24
mongo::EncodedValueStorage
Definition:
encoded_value_storage.h:31
Generated by
1.8.10