00001
00002
00003
00004
00005
00006
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00036 #pragma once
00037
00038 #if defined(MONGO_EXPOSE_MACROS)
00039 #error this header is for client programs, not the mongo database itself. include jsobj.h instead.
00040
00041
00042
00043 #endif
00044
00045 #include <iostream>
00046 #include <sstream>
00047 #include <boost/utility.hpp>
00048 #include "util/builder.h"
00049
00050 namespace bson {
00051
00052 using std::string;
00053 using std::stringstream;
00054
00055 class assertion : public std::exception {
00056 public:
00057 assertion( unsigned u , const string& s )
00058 : id( u ) , msg( s ) {
00059 mongo::StringBuilder ss;
00060 ss << "BsonAssertion id: " << u << " " << s;
00061 full = ss.str();
00062 }
00063
00064 virtual ~assertion() throw() {}
00065
00066 virtual const char* what() const throw() { return full.c_str(); }
00067
00068 unsigned id;
00069 string msg;
00070 string full;
00071 };
00072 }
00073
00074 namespace mongo {
00075 #if !defined(assert)
00076 inline void assert(bool expr) {
00077 if(!expr) {
00078 throw bson::assertion( 0 , "assertion failure in bson library" );
00079 }
00080 }
00081 #endif
00082 #if !defined(uassert)
00083 inline void uasserted(unsigned msgid, std::string s) {
00084 throw bson::assertion( msgid , s );
00085 }
00086
00087 inline void uassert(unsigned msgid, std::string msg, bool expr) {
00088 if( !expr )
00089 uasserted( msgid , msg );
00090 }
00091 inline void msgasserted(int msgid, const char *msg) {
00092 throw bson::assertion( msgid , msg );
00093 }
00094 inline void msgasserted(int msgid, const std::string &msg) { msgasserted(msgid, msg.c_str()); }
00095 inline void massert(unsigned msgid, std::string msg, bool expr) {
00096 if(!expr) {
00097 std::cout << "assertion failure in bson library: " << msgid << ' ' << msg << std::endl;
00098 throw bson::assertion( msgid , msg );
00099 }
00100 }
00101 #endif
00102 }
00103
00104 #include "../bson/bsontypes.h"
00105 #include "../bson/oid.h"
00106 #include "../bson/bsonelement.h"
00107 #include "../bson/bsonobj.h"
00108 #include "../bson/bsonmisc.h"
00109 #include "../bson/bsonobjbuilder.h"
00110 #include "../bson/bsonobjiterator.h"
00111 #include "../bson/bson-inl.h"
00112
00113 namespace mongo {
00114
00115 inline unsigned getRandomNumber() {
00116 #if defined(_WIN32)
00117 return rand();
00118 #else
00119 return random();
00120 #endif
00121 }
00122
00123 }