Permalink
Browse files

updated cxx driver

  • Loading branch information...
1 parent 271a04c commit 6dd623608a648347d6dbf520d46551b10e00ec4b Ubuntu committed Mar 11, 2013
Showing with 4,174 additions and 1,480 deletions.
  1. +13 −5 mongo-cxx-driver/src/SConscript.client
  2. +14 −3 mongo-cxx-driver/src/mongo/base/counter.h
  3. +16 −17 mongo-cxx-driver/src/mongo/base/parse_number.cpp
  4. +22 −4 mongo-cxx-driver/src/mongo/base/string_data-inl.h
  5. +15 −4 mongo-cxx-driver/src/mongo/base/string_data.h
  6. +15 −3 mongo-cxx-driver/src/mongo/bson/bson_field.h
  7. +177 −99 mongo-cxx-driver/src/mongo/bson/bson_validate.cpp
  8. +1 −2 mongo-cxx-driver/src/mongo/bson/bson_validate.h
  9. +2 −2 mongo-cxx-driver/src/mongo/bson/oid.cpp
  10. +1 −1 mongo-cxx-driver/src/mongo/bson/oid.h
  11. +4 −0 mongo-cxx-driver/src/mongo/bson/util/misc.h
  12. +1 −1 mongo-cxx-driver/src/mongo/buildinfo.cpp
  13. +0 −4 mongo-cxx-driver/src/mongo/client/clientAndShell.cpp
  14. +144 −39 mongo-cxx-driver/src/mongo/client/dbclient.cpp
  15. +1 −0 mongo-cxx-driver/src/mongo/client/dbclient.h
  16. +89 −81 mongo-cxx-driver/src/mongo/client/dbclient_rs.cpp
  17. +54 −25 mongo-cxx-driver/src/mongo/client/dbclient_rs.h
  18. +10 −1 mongo-cxx-driver/src/mongo/client/dbclientcursor.h
  19. +60 −11 mongo-cxx-driver/src/mongo/client/dbclientinterface.h
  20. +3 −4 mongo-cxx-driver/src/mongo/client/distlock.cpp
  21. +6 −164 mongo-cxx-driver/src/mongo/client/sasl_client_authenticate.cpp
  22. +15 −10 mongo-cxx-driver/src/mongo/client/sasl_client_authenticate.h
  23. +230 −0 mongo-cxx-driver/src/mongo/client/sasl_client_authenticate_impl.cpp
  24. +11 −19 mongo-cxx-driver/src/mongo/client/syncclusterconnection.cpp
  25. +4 −1 mongo-cxx-driver/src/mongo/client/syncclusterconnection.h
  26. +6 −2 mongo-cxx-driver/src/mongo/db/auth/action_type.h
  27. +3 −1 mongo-cxx-driver/src/mongo/db/auth/action_types.txt
  28. +1 −0 mongo-cxx-driver/src/mongo/db/auth/authorization_manager.h
  29. +4 −4 mongo-cxx-driver/src/mongo/db/btree.h
  30. +1 −1 mongo-cxx-driver/src/mongo/db/client.h
  31. +3 −1 mongo-cxx-driver/src/mongo/db/clientcursor.h
  32. +2 −1 mongo-cxx-driver/src/mongo/db/cmdline.h
  33. +1 −2 mongo-cxx-driver/src/mongo/db/database.h
  34. +1 −1 mongo-cxx-driver/src/mongo/db/dbmessage.h
  35. +5 −4 mongo-cxx-driver/src/mongo/db/dur_commitjob.h
  36. 0 mongo-cxx-driver/src/mongo/db/{ops → }/field_ref.h
  37. +5 −0 mongo-cxx-driver/src/mongo/db/hashindex.h
  38. +2 −3 mongo-cxx-driver/src/mongo/db/index_rebuilder.h
  39. +48 −0 mongo-cxx-driver/src/mongo/db/index_set.h
  40. +63 −9 mongo-cxx-driver/src/mongo/db/indexkey.h
  41. +10 −11 mongo-cxx-driver/src/mongo/db/jsobj.cpp
  42. +23 −11 mongo-cxx-driver/src/mongo/db/json.cpp
  43. +4 −4 mongo-cxx-driver/src/mongo/db/json.h
  44. +31 −5 mongo-cxx-driver/src/mongo/db/keypattern.h
  45. +11 −70 mongo-cxx-driver/src/mongo/db/matcher.h
  46. +3 −2 mongo-cxx-driver/src/mongo/db/namespace_details-inl.h
  47. +9 −6 mongo-cxx-driver/src/mongo/db/namespace_details.h
  48. +10 −3 mongo-cxx-driver/src/mongo/db/namespacestring.h
  49. +6 −0 mongo-cxx-driver/src/mongo/db/oplogreader.h
  50. +12 −1 mongo-cxx-driver/src/mongo/db/ops/query.h
  51. +45 −132 mongo-cxx-driver/src/mongo/db/ops/update_internal.h
  52. +7 −6 mongo-cxx-driver/src/mongo/db/pdfile.h
  53. +31 −0 mongo-cxx-driver/src/mongo/db/pdfile_version.h
  54. +2 −1 mongo-cxx-driver/src/mongo/db/queryutil.h
  55. +0 −7 mongo-cxx-driver/src/mongo/db/repl/bgsync.h
  56. +14 −5 mongo-cxx-driver/src/mongo/db/repl/rs.h
  57. +1 −1 mongo-cxx-driver/src/mongo/db/repl_block.h
  58. +2 −1 mongo-cxx-driver/src/mongo/db/scanandorder.h
  59. +46 −7 mongo-cxx-driver/src/mongo/db/server_parameters.h
  60. +77 −0 mongo-cxx-driver/src/mongo/db/stats/timer_stats.h
  61. +77 −8 mongo-cxx-driver/src/mongo/platform/atomic_intrinsics_win32.h
  62. +1 −0 mongo-cxx-driver/src/mongo/platform/windows_basic.h
  63. +5 −1 mongo-cxx-driver/src/mongo/s/balancer_policy.h
  64. +13 −1 mongo-cxx-driver/src/mongo/s/chunk.h
  65. +0 −4 mongo-cxx-driver/src/mongo/s/chunk_version.h
  66. +9 −7 mongo-cxx-driver/src/mongo/s/collection_manager.h
  67. +5 −0 mongo-cxx-driver/src/mongo/s/d_logic.h
  68. +26 −19 mongo-cxx-driver/src/mongo/s/field_parser-inl.h
  69. +27 −24 mongo-cxx-driver/src/mongo/s/field_parser.h
  70. +9 −1 mongo-cxx-driver/src/mongo/s/shard.h
  71. +133 −39 mongo-cxx-driver/src/mongo/s/type_changelog.h
  72. +99 −40 mongo-cxx-driver/src/mongo/s/type_chunk.h
  73. +182 −53 mongo-cxx-driver/src/mongo/s/type_collection.h
  74. +150 −54 mongo-cxx-driver/src/mongo/s/type_config_version.h
  75. +74 −30 mongo-cxx-driver/src/mongo/s/type_database.h
  76. +48 −23 mongo-cxx-driver/src/mongo/s/type_lockpings.h
  77. +139 −48 mongo-cxx-driver/src/mongo/s/type_locks.h
  78. +132 −43 mongo-cxx-driver/src/mongo/s/type_mongos.h
  79. +146 −54 mongo-cxx-driver/src/mongo/s/type_settings.h
  80. +123 −36 mongo-cxx-driver/src/mongo/s/type_shard.h
  81. +82 −30 mongo-cxx-driver/src/mongo/s/type_tags.h
  82. +4 −2 mongo-cxx-driver/src/mongo/s/writeback_listener.h
  83. +14 −9 mongo-cxx-driver/src/mongo/scripting/bench.h
  84. +9 −11 mongo-cxx-driver/src/mongo/scripting/bson_template_evaluator.h
  85. +14 −7 mongo-cxx-driver/src/mongo/scripting/engine.h
  86. +1 −1 mongo-cxx-driver/src/mongo/scripting/engine_spidermonkey_internal.h
  87. +185 −53 mongo-cxx-driver/src/mongo/scripting/engine_v8.h
  88. +7 −2 mongo-cxx-driver/src/mongo/scripting/v8_db.h
  89. +171 −0 mongo-cxx-driver/src/mongo/scripting/v8_deadline_monitor.h
  90. +46 −0 mongo-cxx-driver/src/mongo/scripting/v8_profiler.h
  91. +24 −3 mongo-cxx-driver/src/mongo/scripting/v8_utils.h
  92. +11 −2 mongo-cxx-driver/src/mongo/targetver.h
  93. +13 −9 mongo-cxx-driver/src/mongo/util/background.cpp
  94. +2 −2 mongo-cxx-driver/src/mongo/util/gsasl_session.h
  95. +5 −3 mongo-cxx-driver/src/mongo/util/log.cpp
  96. +25 −7 mongo-cxx-driver/src/mongo/util/log.h
  97. +19 −10 mongo-cxx-driver/src/mongo/util/net/hostandport.h
  98. +208 −4 mongo-cxx-driver/src/mongo/util/net/listen.cpp
  99. +2 −1 mongo-cxx-driver/src/mongo/util/net/message_port.cpp
  100. +43 −12 mongo-cxx-driver/src/mongo/util/net/sock.cpp
  101. +71 −14 mongo-cxx-driver/src/mongo/util/net/ssl_manager.cpp
  102. +32 −4 mongo-cxx-driver/src/mongo/util/net/ssl_manager.h
  103. +7 −1 mongo-cxx-driver/src/mongo/util/optime.h
  104. +21 −3 mongo-cxx-driver/src/mongo/util/queue.h
  105. +2 −1 mongo-cxx-driver/src/mongo/util/ramlog.cpp
  106. +4 −2 mongo-cxx-driver/src/mongo/util/ramlog.h
  107. +351 −0 mongo-cxx-driver/src/mongo/util/version.cpp
  108. +6 −0 mongo-cxx-driver/src/mongo/util/version.h
@@ -13,7 +13,7 @@ env.Command(['mongo/db/auth/action_type.h', 'mongo/db/auth/action_type.cpp'],
['mongo/db/auth/generate_action_types.py', 'mongo/db/auth/action_types.txt'],
'$PYTHON $SOURCES $TARGETS')
-clientSource = [
+clientSourceBasic = [
'mongo/base/configuration_variable_manager.cpp',
'mongo/base/error_codes.cpp',
'mongo/base/global_initializer.cpp',
@@ -26,9 +26,9 @@ clientSource = [
'mongo/base/parse_number.cpp',
'mongo/base/status.cpp',
'mongo/base/string_data.cpp',
- 'mongo/bson/util/bson_extract.cpp',
'mongo/bson/bson_validate.cpp',
'mongo/bson/oid.cpp',
+ 'mongo/bson/util/bson_extract.cpp',
'mongo/buildinfo.cpp',
'mongo/client/clientAndShell.cpp',
'mongo/client/clientOnly.cpp',
@@ -40,6 +40,7 @@ clientSource = [
'mongo/client/distlock.cpp',
'mongo/client/gridfs.cpp',
'mongo/client/model.cpp',
+ 'mongo/client/sasl_client_authenticate.cpp',
'mongo/client/syncclusterconnection.cpp',
'mongo/db/jsobj.cpp',
'mongo/db/json.cpp',
@@ -83,11 +84,18 @@ clientSource = [
'mongo/util/timer.cpp',
'mongo/util/trace.cpp',
'mongo/util/util.cpp',
+ 'mongo/util/version.cpp',
]
+clientSourceSasl = ['mongo/client/sasl_client_authenticate_impl.cpp',
+ 'mongo/util/gsasl_session.cpp']
+
+clientSourceAll = clientSourceBasic + clientSourceSasl
+
if env['MONGO_BUILD_SASL_CLIENT']:
- clientSource.extend(['mongo/client/sasl_client_authenticate.cpp',
- 'mongo/util/gsasl_session.cpp'])
+ clientSource = clientSourceAll
+else:
+ clientSource = clientSourceBasic
exampleSourceMap = [
('authTest', 'mongo/client/examples/authTest.cpp'),
@@ -154,7 +162,7 @@ env.Install(
'mongo/db/auth/generate_action_types.py',
'mongo/db/auth/action_types.txt',
'#buildscripts/make_archive.py',
- clientSource,
+ clientSourceAll,
clientHeaders,
[source for (target, source) in exampleSourceMap],
'mongo/bson/bsondemo/bsondemo.cpp',
@@ -22,12 +22,23 @@
#include "mongo/platform/cstdint.h"
namespace mongo {
-
+ /**
+ * A 64bit (atomic) counter.
+ *
+ * The constructor allows setting the start value, and increment([int]) is used to change it.
+ *
+ * The value can be returned using get() or the (long long) function operator.
+ */
class Counter64 {
public:
-
+
+ /** Atomically increment. */
void increment( uint64_t n = 1 ) { _counter.addAndFetch(n); }
-
+
+ /** Atomically decrement. */
+ void decrement( uint64_t n = 1 ) { _counter.subtractAndFetch(n); }
+
+ /** Return the current value */
long long get() const { return _counter.load(); }
operator long long() const { return get(); }
@@ -74,33 +74,32 @@ namespace mongo {
* "inputBase" is not 0, *outputBase is set to "inputBase". Otherwise, if "stringValue" starts
* with "0x" or "0X", sets outputBase to 16, or if it starts with 0, sets outputBase to 8.
*
- * Returns the substring of "stringValue" with the base-indicating prefix stripped off.
+ * Returns stringValue, unless it sets *outputBase to 16, in which case it will strip off the
+ * "0x" or "0X" prefix, if present.
*/
static inline StringData _extractBase(
const StringData& stringValue, int inputBase, int* outputBase) {
+ const StringData hexPrefixLower("0x", StringData::LiteralTag());
+ const StringData hexPrefixUpper("0X", StringData::LiteralTag());
if (inputBase == 0) {
- if (stringValue.size() == 0) {
- *outputBase = inputBase;
- return stringValue;
+ if (stringValue.size() > 2 && (stringValue.startsWith(hexPrefixLower) ||
+ stringValue.startsWith(hexPrefixUpper))) {
+ *outputBase = 16;
+ return stringValue.substr(2);
}
- if (stringValue[0] == '0') {
- if (stringValue.size() > 1 && (stringValue[1] == 'x' || stringValue[1] == 'X')) {
- *outputBase = 16;
- return stringValue.substr(2);
- }
+ if (stringValue.size() > 1 && stringValue[0] == '0') {
*outputBase = 8;
- return stringValue.substr(1);
+ return stringValue;
}
*outputBase = 10;
return stringValue;
}
else {
*outputBase = inputBase;
- if (inputBase == 16) {
- StringData prefix = stringValue.substr(0, 2);
- if (prefix == "0x" || prefix == "0X")
- return stringValue.substr(2);
+ if (inputBase == 16 && (stringValue.startsWith(hexPrefixLower) ||
+ stringValue.startsWith(hexPrefixUpper))) {
+ return stringValue.substr(2);
}
return stringValue;
}
@@ -115,12 +114,12 @@ namespace mongo {
if (base == 1 || base < 0 || base > 36)
return Status(ErrorCodes::BadValue, "Invalid base", 0);
- if (stringValue.size() == 0)
- return Status(ErrorCodes::FailedToParse, "Empty string");
-
bool isNegative = false;
StringData str = _extractBase(_extractSign(stringValue, &isNegative), base, &base);
+ if (str.empty())
+ return Status(ErrorCodes::FailedToParse, "No digits");
+
NumberType n(0);
if (isNegative) {
if (limits::is_signed) {
@@ -61,8 +61,11 @@ namespace mongo {
dest[size()] = 0;
}
- inline size_t StringData::find( char c ) const {
- const void* x = memchr( _data, c, size() );
+ inline size_t StringData::find( char c, size_t fromPos ) const {
+ if ( fromPos >= size() )
+ return string::npos;
+
+ const void* x = memchr( _data + fromPos, c, _size - fromPos );
if ( x == 0 )
return string::npos;
return static_cast<size_t>( static_cast<const char*>(x) - _data );
@@ -91,10 +94,25 @@ namespace mongo {
if ( pos > size() )
throw std::out_of_range( "out of range" );
- if ( pos + n > size() )
+ // truncate to end of string
+ if ( n > size() - pos )
n = size() - pos;
return StringData( _data + pos, n );
}
-}
+ inline bool StringData::startsWith( const StringData& prefix ) const {
+ // TODO: Investigate an optimized implementation.
+ return substr(0, prefix.size()) == prefix;
+ }
+
+ inline bool StringData::endsWith( const StringData& suffix ) const {
+ // TODO: Investigate an optimized implementation.
+ const size_t thisSize = size();
+ const size_t suffixSize = suffix.size();
+ if (suffixSize > thisSize)
+ return false;
+ return substr(thisSize - suffixSize) == suffix;
+ }
+
+} // namespace mongo
@@ -56,7 +56,7 @@ namespace mongo {
/**
* Constructs a StringData explicitly, for the case where the length of the string is
- * already known. 'c' must be a pointer to a null-terminated string, and strlenOfc must
+ * already known. 'c' must be a pointer to a null-terminated string, and len must
* be the length that strlen(c) would return, a.k.a the index of the terminator in c.
*/
StringData( const char* c, size_t len )
@@ -96,16 +96,27 @@ namespace mongo {
// finders
//
- size_t find( char c ) const;
+ size_t find( char c , size_t fromPos = 0 ) const;
size_t find( const StringData& needle ) const;
+ /**
+ * Returns true if 'prefix' is a substring of this instance, anchored at position 0.
+ */
+ bool startsWith( const StringData& prefix ) const;
+
+ /**
+ * Returns true if 'suffix' is a substring of this instance, anchored at the end.
+ */
+ bool endsWith( const StringData& suffix ) const;
+
//
// accessors
//
/**
- * this is not guaranteed to be null-terminated,
- * if you use this without all using size(), you are likely doing something wrong
+ * Get the pointer to the first byte of StringData. This is not guaranteed to be
+ * null-terminated, so if using this without checking size(), you are likely doing
+ * something wrong.
*/
const char* rawData() const { return _data; }
@@ -74,8 +74,11 @@ namespace mongo {
template<typename T>
class BSONField {
public:
- BSONField(const std::string& name, const std::string& longName="")
- : _name(name), _longName(longName) {}
+ BSONField(const std::string& name)
+ : _name(name), _defaultSet(false) {}
+
+ BSONField(const std::string& name, const T& defaultVal)
+ : _name(name), _default(defaultVal), _defaultSet(true) {}
BSONFieldValue<T> make(const T& t) const {
return BSONFieldValue<T>(_name, t);
@@ -89,6 +92,14 @@ namespace mongo {
return _name;
}
+ const T& getDefault() const {
+ return _default;
+ }
+
+ const bool hasDefault() const {
+ return _defaultSet;
+ }
+
std::string operator()() const {
return _name;
}
@@ -109,7 +120,8 @@ namespace mongo {
private:
std::string _name;
- std::string _longName;
+ T _default;
+ bool _defaultSet;
};
} // namespace mongo
Oops, something went wrong.

0 comments on commit 6dd6236

Please sign in to comment.