/** @file jsobj.h
BSON classes
*/
/* Copyright 2009 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
BSONObj and its helpers
"BSON" stands for "binary JSON" -- ie a binary way to represent objects that would be
represented in JSON (plus a few extensions useful for databases & other languages).
http://www.mongodb.org/display/DOCS/BSON
*/
#pragma once
#include "../stdafx.h"
#include "../util/builder.h"
#include "../util/optime.h"
#include "boost/utility.hpp"
#include <set>
namespace mongo {
class BSONObj;
struct BSONArray; // empty subclass of BSONObj useful for overloading
class BSONElement;
class Record;
class BSONObjBuilder;
class BSONArrayBuilder;
class BSONObjBuilderValueStream;
#pragma pack(1)
/**
the complete list of valid BSON types
*/
enum BSONType {
/** smaller than all other types */
MinKey=-1,
/** end of object */
EOO=0,
/** double precision floating point value */
NumberDouble=1,
/** character string, stored in utf8 */
String=2,
/** an embedded object */
Object=3,
/** an embedded array */
Array=4,
/** binary data */
BinData=5,
/** Undefined type */
Undefined=6,
/** ObjectId */
jstOID=7,
/** boolean type */
Bool=8,
/** date type */
Date=9,
/** null type */
jstNULL=10,
/** regular expression, a pattern with options */
RegEx=11,
/** deprecated / will be redesigned */
DBRef=12,
/** deprecated / use CodeWScope */
Code=13,
/** a programming language (e.g., Python) symbol */
Symbol=14,
/** javascript code that can execute on the database server, with SavedContext */
CodeWScope=15,
/** 32 bit signed integer */
NumberInt = 16,
/** Updated to a Date with value next OpTime on insert */
Timestamp = 17,
/** 64 bit integer */
NumberLong = 18,
/** max type that is not MaxKey */
JSTypeMax=18,
/** larger than all other types */
MaxKey=127
};
/* subtypes of BinData.
bdtCustom and above are ones that the JS compiler understands, but are
opaque to the database.
*/
enum BinDataType { Function=1, ByteArray=2, bdtUUID = 3, MD5Type=5, bdtCustom=128 };
/** Object ID type.
BSON objects typically have an _id field for the object id. This field should be the first
member of the object when present. class OID is a special type that is a 12 byte id which
is likely to be unique to the system. You may also use other types for _id's.
When _id field is missing from a BSON object, on an insert the database may insert one
automatically in certain circumstances.
Warning: You must call OID::newState() after a fork().
*/
class OID {
union {
struct{
long long a;
unsigned b;
};
unsigned char data[12];
};
static unsigned _machine;
public:
/** call this after a fork */
static void newState();
/** initialize to 'null' */
void clear() { a = 0; b = 0; }
const unsigned char *getData() const { return data; }
bool operator==(const OID& r) {
return a==r.a&&b==r.b;
}
bool operator!=(const OID& r) {
return a!=r.a||b!=r.b;
}
/** The object ID output as 24 hex digits. */
string str() const {
stringstream s;
s << hex;
// s.fill( '0' );
// s.width( 2 );
// fill wasn't working so doing manually...
for( int i = 0; i < 8; i++ ) {
unsigned u = data[i];
if( u < 16 ) s << '0';
s << u;
}
const unsigned char * raw = (const unsigned char*)&b;
for( int i = 0; i < 4; i++ ) {
unsigned u = raw[i];
if( u < 16 ) s << '0';
s << u;
}
/*
s.width( 16 );
s << a;
s.width( 8 );
s << b;
s << dec;
*/
return s.str();
}
/**
sets the contents to a new oid / randomized value
*/
void init();
/** Set to the hex string value specified. */
void init( string s );
};
ostream& operator<<( ostream &s, const OID &o );
/** Formatting mode for generating JSON from BSON.
See <http://mongodb.onconfluence.com/display/DOCS/Mongo+Extended+JSON>
for details.
*/
enum JsonStringFormat {
/** strict RFC format */
Strict,
/** 10gen format, which is close to JS format. This form is understandable by
javascript running inside the Mongo server via eval() */
TenGen,
/** Javascript JSON compatible */
JS
};
/* l and r MUST have same type when called: check that first. */
int compareElementValues(const BSONElement& l, const BSONElement& r);
#pragma pack()
/* internals
<type><fieldName ><value>
-------- size() ------------
-fieldNameSize-
value()
type()
*/
/** BSONElement represents an "element" in a BSONObj. So for the object { a : 3, b : "abc" },
'a : 3' is the first element (key+value).
The BSONElement object points into the BSONObj's data. Thus the BSONObj must stay in scope
for the life of the BSONElement.
*/
class BSONElement {
friend class BSONObjIterator;
friend class BSONObj;
public:
string toString( bool includeFieldName = true ) const;
operator string() const { return toString(); }
string jsonString( JsonStringFormat format, bool includeFieldNames = true ) const;
/** Returns the type of the element */
BSONType type() const {
return (BSONType) *data;
}
/** returns the tyoe of the element fixed for the main type
the main purpose is numbers. any numeric type will return NumberDouble
Note: if the order changes, indexes have to be re-built or than can be corruption
*/
int canonicalType() const {
BSONType t = type();
switch ( t ){
case MinKey:
case MaxKey:
return t;
case EOO:
case Undefined:
return 0;
case jstNULL:
return 5;
case NumberDouble:
case NumberInt:
case NumberLong:
return 10;
case String:
case Symbol:
return 15;
case Object:
return 20;
case Array:
return 25;
case BinData:
return 30;
case jstOID:
return 35;
case Bool:
return 40;
case Date:
case Timestamp:
return 45;
case RegEx:
return 50;
case DBRef:
return 55;
case Code:
return 60;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。 它的特点是高性能、易部署、易使用,存储数据非常方便。 主要功能特性有: 面向集合存储,易存储对象类型的数据。 模式自由。 支持动态查询。 支持完全索引,包含内部对象。 支持查询。 支持复制和故障恢复。 使用高效的二进制数据存储,包括大型对象(如视频等)。 自动处理碎片,以支持云计算层次的扩展性。 支持RUBY,PYTHON,JAVA,C++,PHP,C#等多种语言。 文件存储格式为BSON(一种JSON的扩展)。 可通过网络访问。
资源推荐
资源详情
资源评论
收起资源包目录
mongodb-win32-i386-1.2.1.zip (86个子文件)
mongodb-win32-i386-1.2.1
bin
mongofiles.exe 2.04MB
mongoexport.exe 2.03MB
mongos.exe 1.49MB
mongoimport.exe 2.03MB
mongodump.exe 2.02MB
mongorestore.exe 2.02MB
mongo.exe 1.35MB
mongod.exe 2.27MB
THIRD-PARTY-NOTICES 7KB
include
mongo
client
gridfs.h 6KB
quorum.h 732B
connpool.h 4KB
dbclient.h 34KB
parallel.h 5KB
model.h 2KB
stdafx.h 4KB
db
module.h 2KB
jsobj.h 60KB
json.h 1KB
lasterror.h 3KB
cmdline.h 2KB
filever.h 840B
rec.h 3KB
clientcursor.h 5KB
dbinfo.h 1KB
reci.h 1KB
database.h 5KB
concurrency.h 5KB
jsobjmanipulator.h 3KB
extsort.h 3KB
query.h 4KB
recstore.h 3KB
queryoptimizer.h 6KB
matcher.h 5KB
client.h 3KB
dbhelpers.h 4KB
security.h 2KB
nonce.h 1KB
namespace.h 22KB
db.h 5KB
minilex.h 5KB
scanandorder.h 5KB
repl.h 10KB
resource.h 1KB
btree.h 14KB
cursor.h 7KB
introspect.h 1007B
replset.h 6KB
queryutil.h 8KB
dbmessage.h 7KB
curop.h 2KB
commands.h 3KB
reccache.h 6KB
pdfile.h 15KB
storage.h 4KB
instance.h 5KB
targetver.h 888B
util
md5.h 3KB
message.h 6KB
hashtab.h 4KB
debug_util.h 2KB
base64.h 1005B
lruishmap.h 2KB
top.h 6KB
builder.h 3KB
embedded_builder.h 3KB
file.h 4KB
unittest.h 2KB
goodies.h 11KB
optime.h 3KB
allocator.h 1KB
processinfo.h 1KB
sock.h 7KB
mmap.h 2KB
httpclient.h 822B
log.h 7KB
file_allocator.h 8KB
background.h 2KB
message_server.h 1KB
assert_util.h 5KB
queue.h 2KB
miniwebserver.h 2KB
ntservice.h 2KB
README 731B
GNU-AGPL-3.0 34KB
lib
mongoclient.lib 41.49MB
共 86 条
- 1
资源评论
- bob007lqb2012-07-09感觉没什么用。。。
知识铺
- 粉丝: 1204
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功