本文整理汇总了C++中StringData类的典型用法代码示例。如果您正苦于以下问题:C++ StringData类的具体用法?C++ StringData怎么用?C++ StringData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
bool run(OperationContext* txn,
const string& dbname,
BSONObj& cmdObj,
int,
string& errmsg,
BSONObjBuilder& result) {
BSONElement first = cmdObj.firstElement();
uassert(28528,
str::stream() << "Argument to listIndexes must be of type String, not "
<< typeName(first.type()),
first.type() == String);
StringData collectionName = first.valueStringData();
uassert(28529,
str::stream() << "Argument to listIndexes must be a collection name, "
<< "not the empty string",
!collectionName.empty());
const NamespaceString ns(dbname, collectionName);
const long long defaultBatchSize = std::numeric_limits<long long>::max();
long long batchSize;
Status parseCursorStatus = parseCommandCursorOptions(cmdObj, defaultBatchSize, &batchSize);
if (!parseCursorStatus.isOK()) {
return appendCommandStatus(result, parseCursorStatus);
}
AutoGetCollectionForRead autoColl(txn, ns);
if (!autoColl.getDb()) {
return appendCommandStatus(result,
Status(ErrorCodes::NamespaceNotFound, "no database"));
}
const Collection* collection = autoColl.getCollection();
if (!collection) {
return appendCommandStatus(result,
Status(ErrorCodes::NamespaceNotFound, "no collection"));
}
const CollectionCatalogEntry* cce = collection->getCatalogEntry();
invariant(cce);
vector<string> indexNames;
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
indexNames.clear();
cce->getAllIndexes(txn, &indexNames);
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "listIndexes", ns.ns());
auto ws = make_unique<WorkingSet>();
auto root = make_unique<QueuedDataStage>(txn, ws.get());
for (size_t i = 0; i < indexNames.size(); i++) {
BSONObj indexSpec;
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
indexSpec = cce->getIndexSpec(txn, indexNames[i]);
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "listIndexes", ns.ns());
WorkingSetID id = ws->allocate();
WorkingSetMember* member = ws->get(id);
member->keyData.clear();
member->loc = RecordId();
member->obj = Snapshotted<BSONObj>(SnapshotId(), indexSpec.getOwned());
member->transitionToOwnedObj();
root->pushBack(id);
}
std::string cursorNamespace = str::stream() << dbname << ".$cmd." << name << "."
<< ns.coll();
dassert(NamespaceString(cursorNamespace).isValid());
dassert(NamespaceString(cursorNamespace).isListIndexesCursorNS());
dassert(ns == NamespaceString(cursorNamespace).getTargetNSForListIndexes());
auto statusWithPlanExecutor = PlanExecutor::make(
txn, std::move(ws), std::move(root), cursorNamespace, PlanExecutor::YIELD_MANUAL);
if (!statusWithPlanExecutor.isOK()) {
return appendCommandStatus(result, statusWithPlanExecutor.getStatus());
}
unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
BSONArrayBuilder firstBatch;
const int byteLimit = FindCommon::kMaxBytesToReturnToClientAtOnce;
for (long long objCount = 0; objCount < batchSize && firstBatch.len() < byteLimit;
objCount++) {
BSONObj next;
PlanExecutor::ExecState state = exec->getNext(&next, NULL);
if (state == PlanExecutor::IS_EOF) {
break;
}
invariant(state == PlanExecutor::ADVANCED);
firstBatch.append(next);
}
CursorId cursorId = 0LL;
if (!exec->isEOF()) {
exec->saveState();
exec->detachFromOperationContext();
ClientCursor* cursor =
new ClientCursor(CursorManager::getGlobalCursorManager(),
exec.release(),
//.........这里部分代码省略.........
示例2: versionCmp
int versionCmp(StringData rhs, StringData lhs) {
if (strcmp(rhs.data(),lhs.data()) == 0)
return 0;
// handle "1.2.3-" and "1.2.3-pre"
if (rhs.size() < lhs.size()) {
if (strncmp(rhs.data(), lhs.data(), rhs.size()) == 0 && lhs.data()[rhs.size()] == '-')
return +1;
}
else if (rhs.size() > lhs.size()) {
if (strncmp(rhs.data(), lhs.data(), lhs.size()) == 0 && rhs.data()[lhs.size()] == '-')
return -1;
}
return lexNumCmp(rhs.data(), lhs.data());
}
示例3: addPathComponent
void UpdateIndexData::addPathComponent(StringData pathComponent) {
_pathComponents.insert(pathComponent.toString());
}
示例4: Status
Status HostAndPort::initialize(const StringData& s) {
size_t colonPos = s.rfind(':');
StringData hostPart = s.substr(0, colonPos);
// handle ipv6 hostPart (which we require to be wrapped in []s)
const size_t openBracketPos = s.find('[');
const size_t closeBracketPos = s.find(']');
if (openBracketPos != std::string::npos) {
if (openBracketPos != 0) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "'[' present, but not first character in "
<< s.toString());
}
if (closeBracketPos == std::string::npos) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "ipv6 address is missing closing ']' in hostname in "
<< s.toString());
}
hostPart = s.substr(openBracketPos+1, closeBracketPos-openBracketPos-1);
// prevent accidental assignment of port to the value of the final portion of hostPart
if (colonPos < closeBracketPos) {
colonPos = std::string::npos;
}
else if (colonPos != closeBracketPos+1) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "Extraneous characters between ']' and pre-port ':'"
<< " in " << s.toString());
}
}
else if (closeBracketPos != std::string::npos) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "']' present without '[' in " << s.toString());
}
else if (s.find(':') != colonPos) {
return Status(ErrorCodes::FailedToParse,
str::stream() << "More than one ':' detected. If this is an ipv6 address,"
<< " it needs to be surrounded by '[' and ']'; "
<< s.toString());
}
if (hostPart.empty()) {
return Status(ErrorCodes::FailedToParse, str::stream() <<
"Empty host component parsing HostAndPort from \"" <<
escape(s.toString()) << "\"");
}
int port;
if (colonPos != std::string::npos) {
const StringData portPart = s.substr(colonPos + 1);
Status status = parseNumberFromStringWithBase(portPart, 10, &port);
if (!status.isOK()) {
return status;
}
if (port <= 0) {
return Status(ErrorCodes::FailedToParse, str::stream() << "Port number " << port <<
" out of range parsing HostAndPort from \"" << escape(s.toString()) <<
"\"");
}
}
else {
port = -1;
}
_host = hostPart.toString();
_port = port;
return Status::OK();
}
示例5: versionCmp
int versionCmp(const StringData rhs, const StringData lhs) {
if (rhs == lhs) return 0;
// handle "1.2.3-" and "1.2.3-pre"
if (rhs.size() < lhs.size()) {
if (strncmp(rhs.rawData(), lhs.rawData(), rhs.size()) == 0 && lhs[rhs.size()] == '-') return +1;
}
else if (rhs.size() > lhs.size()) {
if (strncmp(rhs.rawData(), lhs.rawData(), lhs.size()) == 0 && rhs[lhs.size()] == '-') return -1;
}
return LexNumCmp::cmp(rhs, lhs, false);
}
示例6: setErrMessage
void WriteConcernErrorDetail::setErrMessage(StringData errMessage) {
_errMessage = errMessage.toString();
_isErrMessageSet = true;
}
示例7: setCollName
void BatchedUpdateRequest::setCollName(const StringData& collName) {
_collName = collName.toString();
_isCollNameSet = true;
}
示例8: addCursorId
void RangeDeleterMockEnv::addCursorId(const StringData& ns, CursorId id) {
scoped_lock sl(_cursorMapMutex);
_cursorMap[ns.toString()].insert(id);
}
示例9: removeCursorId
void RangeDeleterMockEnv::removeCursorId(const StringData& ns, CursorId id) {
scoped_lock sl(_cursorMapMutex);
_cursorMap[ns.toString()].erase(id);
}
示例10:
NamespaceIndex::NamespaceIndex(const string &dir, const StringData& database) :
_dir(dir),
_nsdbFilename(database.toString() + ".ns"),
_database(database.toString()),
_openRWLock("nsOpenRWLock")
{}
示例11: setNS
void CurOp::setNS( const StringData& ns ) {
ns.substr( 0, Namespace::MaxNsLen ).copyTo( _ns, true );
}
示例12: prepare
Status ModifierRename::prepare(mutablebson::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
// Rename doesn't work with positional fields ($)
dassert(matchedField.empty());
_preparedState.reset(new PreparedState(root));
// Locate the to field name in 'root', which must exist.
size_t fromIdxFound;
Status status = pathsupport::findLongestPrefix(_fromFieldRef,
root,
&fromIdxFound,
&_preparedState->fromElemFound);
const bool sourceExists = (_preparedState->fromElemFound.ok() &&
fromIdxFound == (_fromFieldRef.numParts() - 1));
// If we can't find the full element in the from field then we can't do anything.
if (!status.isOK() || !sourceExists) {
execInfo->noOp = true;
_preparedState->fromElemFound = root.getDocument().end();
// TODO: remove this special case from existing behavior
if (status.code() == ErrorCodes::PathNotViable) {
return status;
}
return Status::OK();
}
// Ensure no array in ancestry if what we found is not at the root
mutablebson::Element curr = _preparedState->fromElemFound.parent();
if (curr != curr.getDocument().root())
while (curr.ok() && (curr != curr.getDocument().root())) {
if (curr.getType() == Array)
return Status(ErrorCodes::BadValue,
str::stream() << "The source field cannot be an array element, '"
<< _fromFieldRef.dottedField() << "' in doc with "
<< findElementNamed(root.leftChild(), "_id").toString()
<< " has an array field called '" << curr.getFieldName() << "'");
curr = curr.parent();
}
// "To" side validation below
status = pathsupport::findLongestPrefix(_toFieldRef,
root,
&_preparedState->toIdxFound,
&_preparedState->toElemFound);
// FindLongestPrefix may return not viable or any other error and then we cannot proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
// Not an error condition as we will create the "to" path as needed.
} else if (!status.isOK()) {
return status;
}
const bool destExists = _preparedState->toElemFound.ok() &&
(_preparedState->toIdxFound == (_toFieldRef.numParts()-1));
// Ensure no array in ancestry of "to" Element
// Set to either parent, or node depending on if the full path element was found
curr = (destExists ? _preparedState->toElemFound.parent() : _preparedState->toElemFound);
if (curr != curr.getDocument().root()) {
while (curr.ok()) {
if (curr.getType() == Array)
return Status(ErrorCodes::BadValue,
str::stream()
<< "The destination field cannot be an array element, '"
<< _fromFieldRef.dottedField() << "' in doc with "
<< findElementNamed(root.leftChild(), "_id").toString()
<< " has an array field called '" << curr.getFieldName() << "'");
curr = curr.parent();
}
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fromFieldRef;
execInfo->fieldRef[1] = &_toFieldRef;
execInfo->noOp = false;
return Status::OK();
}
示例13: prepare
Status ModifierPull::prepare(mb::Element root,
const StringData& matchedField,
ExecInfo* execInfo) {
_preparedState.reset(new PreparedState(root.getDocument()));
// If we have a $-positional field, it is time to bind it to an actual field part.
if (_posDollar) {
if (matchedField.empty()) {
return Status(ErrorCodes::BadValue,
str::stream() << "The positional operator did not find the match "
"needed from the query. Unexpanded update: "
<< _fieldRef.dottedField());
}
_fieldRef.setPart(_posDollar, matchedField);
}
// Locate the field name in 'root'.
Status status = pathsupport::findLongestPrefix(_fieldRef,
root,
&_preparedState->idxFound,
&_preparedState->elemFound);
// FindLongestPrefix may say the path does not exist at all, which is fine here, or
// that the path was not viable or otherwise wrong, in which case, the mod cannot
// proceed.
if (status.code() == ErrorCodes::NonExistentPath) {
_preparedState->elemFound = root.getDocument().end();
} else if (!status.isOK()) {
return status;
}
// We register interest in the field name. The driver needs this info to sort out if
// there is any conflict among mods.
execInfo->fieldRef[0] = &_fieldRef;
if (!_preparedState->elemFound.ok() ||
_preparedState->idxFound < (_fieldRef.numParts() - 1)) {
// If no target element exists, then there is nothing to do here.
_preparedState->noOp = execInfo->noOp = true;
return Status::OK();
}
// This operation only applies to arrays
if (_preparedState->elemFound.getType() != mongo::Array)
return Status(
ErrorCodes::BadValue,
"Cannot apply $pull to a non-array value");
// If the array is empty, there is nothing to pull, so this is a noop.
if (!_preparedState->elemFound.hasChildren()) {
_preparedState->noOp = execInfo->noOp = true;
return Status::OK();
}
// Walk the values in the array
mb::Element cursor = _preparedState->elemFound.leftChild();
while (cursor.ok()) {
if (isMatch(cursor))
_preparedState->elementsToRemove.push_back(cursor);
cursor = cursor.rightSibling();
}
// If we didn't find any elements to add, then this is a no-op, and therefore in place.
if (_preparedState->elementsToRemove.empty()) {
_preparedState->noOp = execInfo->noOp = true;
}
return Status::OK();
}
示例14: verify
void ClientCursor::invalidate(const StringData& ns) {
Lock::assertWriteLocked(ns);
size_t dot = ns.find( '.' );
verify( dot != string::npos );
// first (and only) dot is the last char
bool isDB = dot == ns.size() - 1;
Database *db = cc().database();
verify(db);
verify(ns.startsWith(db->name()));
recursive_scoped_lock cclock(ccmutex);
// Look at all active non-cached Runners. These are the runners that are in auto-yield mode
// that are not attached to the the client cursor. For example, all internal runners don't
// need to be cached -- there will be no getMore.
for (set<Runner*>::iterator it = nonCachedRunners.begin(); it != nonCachedRunners.end();
++it) {
Runner* runner = *it;
const string& runnerNS = runner->ns();
if ( ( isDB && StringData(runnerNS).startsWith(ns) ) || ns == runnerNS ) {
runner->kill();
}
}
// Look at all cached ClientCursor(s). The CC may have a Runner, a Cursor, or nothing (see
// sharding_block.h).
CCById::const_iterator it = clientCursorsById.begin();
while (it != clientCursorsById.end()) {
ClientCursor* cc = it->second;
// Aggregation cursors don't have their lifetime bound to the underlying collection.
if (cc->isAggCursor) {
++it;
continue;
}
// We're only interested in cursors over one db.
if (cc->_db != db) {
++it;
continue;
}
// Note that a valid ClientCursor state is "no cursor no runner." This is because
// the set of active cursor IDs in ClientCursor is used as representation of query
// state. See sharding_block.h. TODO(greg,hk): Move this out.
if (NULL == cc->_runner.get()) {
++it;
continue;
}
bool shouldDelete = false;
// We will only delete CCs with runners that are not actively in use. The runners that
// are actively in use are instead kill()-ed.
if (NULL != cc->_runner.get()) {
if (isDB || cc->_runner->ns() == ns) {
// If there is a pinValue >= 100, somebody is actively using the CC and we do
// not delete it. Instead we notify the holder that we killed it. The holder
// will then delete the CC.
if (cc->_pinValue >= 100) {
cc->_runner->kill();
}
else {
// pinvalue is <100, so there is nobody actively holding the CC. We can
// safely delete it as nobody is holding the CC.
shouldDelete = true;
}
}
}
if (shouldDelete) {
ClientCursor* toDelete = it->second;
CursorId id = toDelete->cursorid();
delete toDelete;
// We're not following the usual paradigm of saving it, ++it, and deleting the saved
// 'it' because deleting 'it' might invalidate the next thing in clientCursorsById.
// TODO: Why?
it = clientCursorsById.upper_bound(id);
}
else {
++it;
}
}
}
示例15: ScopedLock
Lock::DBRead::DBRead( const StringData& ns )
: ScopedLock( 'r' ), _what(ns.data()), _nested(false) {
lockDB( _what );
}