summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight Merriman <dwight@10gen.com>2010-04-24 17:14:44 -0400
committerDwight Merriman <dwight@10gen.com>2010-04-24 17:14:44 -0400
commit96b58977fcc6cad83a79589162843659221ea1ab (patch)
treeddc288190e07bb58465737b867e3891b0fb1109e
parent8d3ab6a171ea3463f6bc2053351779fe37539d69 (diff)
downloadmongo-96b58977fcc6cad83a79589162843659221ea1ab.tar.gz
towards 2
-rw-r--r--bson/bson.h24
-rw-r--r--bson/bson_db.h50
-rw-r--r--bson/bsondemo/bsondemo.vcproj4
-rw-r--r--bson/bsonelement.h26
-rw-r--r--db/clientcursor.cpp2
-rw-r--r--db/dbcommands.cpp6
-rw-r--r--db/jsobj.cpp2
-rw-r--r--db/jsobj.h2
-rw-r--r--db/mr.cpp6
9 files changed, 92 insertions, 30 deletions
diff --git a/bson/bson.h b/bson/bson.h
index bb44799dc60..fefe40fcefa 100644
--- a/bson/bson.h
+++ b/bson/bson.h
@@ -33,20 +33,36 @@
#pragma once
-//#include <iostream>
+#include <iostream>
#include <sstream>
+namespace mongo {
+
+#if !defined(assert)
+ void assert(bool expr) {
+ if(!expr) std::cout << "assertion failure in bson library" << std::endl;
+ }
+#endif
+#if !defined(uassert)
+ void uassert(unsigned msgid, const char *msg, bool expr) {
+ if(!expr) std::cout << "assertion failure in bson library: " << msgid << ' ' << msg << std::endl;
+ }
+ void massert(unsigned msgid, const char *msg, bool expr) {
+ if(!expr) std::cout << "assertion failure in bson library: " << msgid << ' ' << msg << std::endl;
+ }
+#endif
+
+}
+
/*
#include "../util/builder.h"
-#include "../util/optime.h"
#include "boost/utility.hpp"
#include <set>
*/
#include "../bson/bsontypes.h"
#include "../bson/oid.h"
-/*
-#include "../bson/oid.h"
#include "../bson/bsonelement.h"
+/*
#include "../bson/bsonobj.h"
#include "../bson/bsonmisc.h"
#include "../bson/bsonobjbuilder.h"
diff --git a/bson/bson_db.h b/bson/bson_db.h
new file mode 100644
index 00000000000..2b86295571f
--- /dev/null
+++ b/bson/bson_db.h
@@ -0,0 +1,50 @@
+/** @file bson_db.h
+
+ This file contains the implementation of BSON-related methods that are required
+ by the MongoDB database server.
+
+ Normally, for standalone BSON usage, you do not want this file - it will tend to
+ pull in some other files from the MongoDB project. Thus, bson.h (the main file
+ one would use) does not include this file.
+*/
+
+/* 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.
+ */
+
+#pragma once
+
+#include "../util/optime.h"
+
+namespace mongo {
+
+ inline OpTime BSONElement::_opTime() const {
+ return OpTime( *reinterpret_cast< const unsigned long long* >( value() ) );
+ }
+
+ inline string BSONElement::_asCode() const {
+ switch( type() ){
+ case mongo::String:
+ case Code:
+ return valuestr();
+ case CodeWScope:
+ return codeWScopeCode();
+ default:
+ log() << "can't convert type: " << (int)(type()) << " to code" << endl;
+ }
+ uassert( 10062 , "not code" , 0 );
+ return "";
+ }
+
+}
diff --git a/bson/bsondemo/bsondemo.vcproj b/bson/bsondemo/bsondemo.vcproj
index 9d89bda3d6d..4d73def6096 100644
--- a/bson/bsondemo/bsondemo.vcproj
+++ b/bson/bsondemo/bsondemo.vcproj
@@ -183,6 +183,10 @@
>
</File>
<File
+ RelativePath="..\bson_db.h"
+ >
+ </File>
+ <File
RelativePath="..\bsonelement.h"
>
</File>
diff --git a/bson/bsonelement.h b/bson/bsonelement.h
index fc86ce6c372..e04241714f8 100644
--- a/bson/bsonelement.h
+++ b/bson/bsonelement.h
@@ -17,8 +17,12 @@
#pragma once
+#include <vector>
+
namespace mongo {
+ class OpTime;
+
/** BSONElement represents an "element" in a BSONObj. So for the object { a : 3, b : "abc" },
'a : 3' is the first element (key+value).
@@ -203,20 +207,6 @@ public:
BSONObj codeWScopeObject() const;
- string ascode() const {
- switch( type() ){
- case mongo::String:
- case Code:
- return valuestr();
- case CodeWScope:
- return codeWScopeCode();
- default:
- log() << "can't convert type: " << (int)(type()) << " to code" << endl;
- }
- uassert( 10062 , "not code" , 0 );
- return "";
- }
-
/** Get binary data. Element must be of type BinData */
const char *binData(int& len) const {
// BinData: <int len> <byte subtype> <byte[len] data>
@@ -300,10 +290,6 @@ public:
}
}
- OpTime optime() const {
- return OpTime( *reinterpret_cast< const unsigned long long* >( value() ) );
- }
-
Date_t timestampTime() const{
unsigned long long t = ((unsigned int*)(value() + 4 ))[0];
return t * 1000;
@@ -345,6 +331,10 @@ public:
}
totalSize = -1;
}
+
+ string BSONElement::_asCode() const;
+ OpTime _opTime() const;
+
private:
const char *data;
mutable int fieldNameSize_; // cached value
diff --git a/db/clientcursor.cpp b/db/clientcursor.cpp
index b5fe82f981c..5f64c144f1f 100644
--- a/db/clientcursor.cpp
+++ b/db/clientcursor.cpp
@@ -269,7 +269,7 @@ namespace mongo {
BSONElement e = last.obj()["ts"];
if ( e.type() == Date || e.type() == Timestamp )
- _slaveReadTill = e.optime();
+ _slaveReadTill = e._opTime();
}
void ClientCursor::updateSlaveLocation( CurOp& curop ){
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp
index 734996cabe6..8d978f9edeb 100644
--- a/db/dbcommands.cpp
+++ b/db/dbcommands.cpp
@@ -1478,7 +1478,7 @@ namespace mongo {
}
}
else if ( p["$keyf"].type() ){
- keyf = p["$keyf"].ascode();
+ keyf = p["$keyf"]._asCode();
}
else {
// no key specified, will use entire object as key
@@ -1499,10 +1499,10 @@ namespace mongo {
string finalize;
if (p["finalize"].type())
- finalize = p["finalize"].ascode();
+ finalize = p["finalize"]._asCode();
return group( realdbname , ns , q ,
- key , keyf , reduce.ascode() , reduce.type() != CodeWScope ? 0 : reduce.codeWScopeScopeData() ,
+ key , keyf , reduce._asCode() , reduce.type() != CodeWScope ? 0 : reduce.codeWScopeScopeData() ,
initial.embeddedObject() , finalize ,
errmsg , result );
}
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index d95e1c7e61a..17233beff4c 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -334,7 +334,7 @@ namespace mongo {
break;
case Code:
- s << ascode();
+ s << _asCode();
break;
case Timestamp:
diff --git a/db/jsobj.h b/db/jsobj.h
index 8a04a5d6dc1..65a3ee5d2b9 100644
--- a/db/jsobj.h
+++ b/db/jsobj.h
@@ -42,3 +42,5 @@
#include "../bson/bsonobjiterator.h"
#include "../bson/bsoninlines.h"
#include "../bson/ordering.h"
+
+#include "../bson/bson_db.h"
diff --git a/db/mr.cpp b/db/mr.cpp
index 4561c3a2ff5..e4350baab8e 100644
--- a/db/mr.cpp
+++ b/db/mr.cpp
@@ -155,10 +155,10 @@ namespace mongo {
}
{ // code
- mapCode = cmdObj["map"].ascode();
- reduceCode = cmdObj["reduce"].ascode();
+ mapCode = cmdObj["map"]._asCode();
+ reduceCode = cmdObj["reduce"]._asCode();
if ( cmdObj["finalize"].type() ){
- finalizeCode = cmdObj["finalize"].ascode();
+ finalizeCode = cmdObj["finalize"]._asCode();
}
checkCodeWScope( "map" , cmdObj );
checkCodeWScope( "reduce" , cmdObj );