MongoDB C++ Driver  legacy-1.1.2
bsontypes.h
1 // bsontypes.h
2 
3 /* Copyright 2009 10gen Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include "mongo/util/assert_util.h"
21 
22 namespace mongo {
23 
24 class BSONArrayBuilder;
25 class BSONElement;
26 class BSONObj;
27 class BSONObjBuilder;
28 class BSONObjBuilderValueStream;
29 class BSONObjIterator;
30 class Ordering;
31 struct BSONArray; // empty subclass of BSONObj useful for overloading
32 struct BSONElementCmpWithoutField;
33 
38 enum BSONType {
40  MinKey = -1,
42  EOO = 0,
46  String = 2,
48  Object = 3,
50  Array = 4,
52  BinData = 5,
54  Undefined = 6,
56  jstOID = 7,
58  Bool = 8,
60  Date = 9,
62  jstNULL = 10,
64  RegEx = 11,
66  DBRef = 12,
68  Code = 13,
70  Symbol = 14,
72  CodeWScope = 15,
74  NumberInt = 16,
76  Timestamp = 17,
78  NumberLong = 18,
80  JSTypeMax = 18,
82  MaxKey = 127
83 };
84 
88 const char* typeName(BSONType type);
89 
90 /* subtypes of BinData.
91  bdtCustom and above are ones that the JS compiler understands, but are
92  opaque to the database.
93 */
94 enum BinDataType {
95  BinDataGeneral = 0,
96  Function = 1,
97  ByteArrayDeprecated = 2, /* use BinGeneral instead */
98  bdtUUID = 3, /* deprecated */
99  newUUID = 4, /* language-independent UUID format across all drivers */
100  MD5Type = 5,
101  bdtCustom = 128
102 };
103 
109 inline int canonicalizeBSONType(BSONType type) {
110  switch (type) {
111  case MinKey:
112  case MaxKey:
113  return type;
114  case EOO:
115  case Undefined:
116  return 0;
117  case jstNULL:
118  return 5;
119  case NumberDouble:
120  case NumberInt:
121  case NumberLong:
122  return 10;
123  case mongo::String:
124  case Symbol:
125  return 15;
126  case Object:
127  return 20;
128  case mongo::Array:
129  return 25;
130  case BinData:
131  return 30;
132  case jstOID:
133  return 35;
134  case mongo::Bool:
135  return 40;
136  case mongo::Date:
137  return 45;
138  case Timestamp:
139  return 47;
140  case RegEx:
141  return 50;
142  case DBRef:
143  return 55;
144  case Code:
145  return 60;
146  case CodeWScope:
147  return 65;
148  default:
149  verify(0);
150  return -1;
151  }
152 }
153 }
end of object
Definition: bsontypes.h:42
larger than all other types
Definition: bsontypes.h:82
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Updated to a Date with value next OpTime on insert.
Definition: bsontypes.h:76
date type
Definition: bsontypes.h:60
boolean type
Definition: bsontypes.h:58
smaller than all other types
Definition: bsontypes.h:40
BSONType
the complete list of valid BSON types see also bsonspec.org
Definition: bsontypes.h:38
ObjectId.
Definition: bsontypes.h:56
an embedded object
Definition: bsontypes.h:48
32 bit signed integer
Definition: bsontypes.h:74
double precision floating point value
Definition: bsontypes.h:44
null type
Definition: bsontypes.h:62
a programming language (e.g., Python) symbol
Definition: bsontypes.h:70
javascript code that can execute on the database server, with SavedContext
Definition: bsontypes.h:72
Undefined type.
Definition: bsontypes.h:54
regular expression, a pattern with options
Definition: bsontypes.h:64
64 bit integer
Definition: bsontypes.h:78
an embedded array
Definition: bsontypes.h:50
deprecated / use CodeWScope
Definition: bsontypes.h:68
deprecated / will be redesigned
Definition: bsontypes.h:66
max type that is not MaxKey
Definition: bsontypes.h:80
const char * typeName(BSONType type)
returns the name of the argument's type
int canonicalizeBSONType(BSONType type)
Returns a number for where a given type falls in the sort order.
Definition: bsontypes.h:109
binary data
Definition: bsontypes.h:52
character string, stored in utf8
Definition: bsontypes.h:46