MongoDB  2.7.0
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 bson { }
23 
24 namespace mongo {
25 
26  class BSONArrayBuilder;
27  class BSONElement;
28  class BSONObj;
29  class BSONObjBuilder;
30  class BSONObjBuilderValueStream;
31  class BSONObjIterator;
32  class Ordering;
33  struct BSONArray; // empty subclass of BSONObj useful for overloading
34  struct BSONElementCmpWithoutField;
35 
36  extern BSONObj maxKey;
37  extern BSONObj minKey;
38 
43  enum BSONType {
45  MinKey=-1,
47  EOO=0,
51  String=2,
53  Object=3,
55  Array=4,
61  jstOID=7,
63  Bool=8,
65  Date=9,
67  jstNULL=10,
69  RegEx=11,
71  DBRef=12,
73  Code=13,
75  Symbol=14,
79  NumberInt = 16,
81  Timestamp = 17,
83  NumberLong = 18,
87  MaxKey=127
88  };
89 
94  const char* typeName (BSONType type);
95 
96  /* subtypes of BinData.
97  bdtCustom and above are ones that the JS compiler understands, but are
98  opaque to the database.
99  */
100  enum BinDataType {
101  BinDataGeneral=0,
102  Function=1,
103  ByteArrayDeprecated=2, /* use BinGeneral instead */
104  bdtUUID = 3, /* deprecated */
105  newUUID=4, /* language-independent UUID format across all drivers */
106  MD5Type=5,
107  bdtCustom=128
108  };
109 
115  inline int canonicalizeBSONType(BSONType type) {
116  switch (type) {
117  case MinKey:
118  case MaxKey:
119  return type;
120  case EOO:
121  case Undefined:
122  return 0;
123  case jstNULL:
124  return 5;
125  case NumberDouble:
126  case NumberInt:
127  case NumberLong:
128  return 10;
129  case mongo::String:
130  case Symbol:
131  return 15;
132  case Object:
133  return 20;
134  case mongo::Array:
135  return 25;
136  case BinData:
137  return 30;
138  case jstOID:
139  return 35;
140  case mongo::Bool:
141  return 40;
142  case mongo::Date:
143  case Timestamp:
144  return 45;
145  case RegEx:
146  return 50;
147  case DBRef:
148  return 55;
149  case Code:
150  return 60;
151  case CodeWScope:
152  return 65;
153  default:
154  verify(0);
155  return -1;
156  }
157  }
158 }
end of object
Definition: bsontypes.h:47
larger than all other types
Definition: bsontypes.h:87
Updated to a Date with value next OpTime on insert.
Definition: bsontypes.h:81
date type
Definition: bsontypes.h:65
boolean type
Definition: bsontypes.h:63
smaller than all other types
Definition: bsontypes.h:45
BSONType
the complete list of valid BSON types see also bsonspec.org
Definition: bsontypes.h:43
ObjectId.
Definition: bsontypes.h:61
an embedded object
Definition: bsontypes.h:53
32 bit signed integer
Definition: bsontypes.h:79
double precision floating point value
Definition: bsontypes.h:49
null type
Definition: bsontypes.h:67
a programming language (e.g., Python) symbol
Definition: bsontypes.h:75
javascript code that can execute on the database server, with SavedContext
Definition: bsontypes.h:77
Undefined type.
Definition: bsontypes.h:59
regular expression, a pattern with options
Definition: bsontypes.h:69
64 bit integer
Definition: bsontypes.h:83
an embedded array
Definition: bsontypes.h:55
deprecated / use CodeWScope
Definition: bsontypes.h:73
deprecated / will be redesigned
Definition: bsontypes.h:71
max type that is not MaxKey
Definition: bsontypes.h:85
const char * typeName(BSONType type)
returns the name of the argument's type defined in jsobj.cpp
int canonicalizeBSONType(BSONType type)
Returns a number for where a given type falls in the sort order.
Definition: bsontypes.h:115
binary data
Definition: bsontypes.h:57
character string, stored in utf8
Definition: bsontypes.h:51