当前位置: 首页>>代码示例>>C++>>正文


C++ Date_t::toString方法代码示例

本文整理汇总了C++中Date_t::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ Date_t::toString方法的具体用法?C++ Date_t::toString怎么用?C++ Date_t::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Date_t的用法示例。


在下文中一共展示了Date_t::toString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _log

Status CatalogManagerCommon::_log(OperationContext* txn,
                                  const StringData& logCollName,
                                  const std::string& what,
                                  const std::string& operationNS,
                                  const BSONObj& detail) {
    Date_t now = grid.shardRegistry()->getExecutor()->now();
    const std::string hostName = grid.shardRegistry()->getNetwork()->getHostName();
    const string changeId = str::stream() << hostName << "-" << now.toString() << "-" << OID::gen();

    ChangeLogType changeLog;
    changeLog.setChangeId(changeId);
    changeLog.setServer(hostName);
    changeLog.setClientAddr(txn->getClient()->clientAddress(true));
    changeLog.setTime(now);
    changeLog.setNS(operationNS);
    changeLog.setWhat(what);
    changeLog.setDetails(detail);

    BSONObj changeLogBSON = changeLog.toBSON();
    log() << "about to log metadata event into " << logCollName << ": " << changeLogBSON;

    const NamespaceString nss("config", logCollName);
    Status result = insertConfigDocument(txn, nss.ns(), changeLogBSON);
    if (!result.isOK()) {
        warning() << "Error encountered while logging config change with ID [" << changeId
                  << "] into collection " << logCollName << ": " << result;
    }

    return result;
}
开发者ID:hunnymunch,项目名称:mongo,代码行数:30,代码来源:catalog_manager_common.cpp

示例2: Status

StatusWith<executor::TaskExecutor::CallbackHandle> TaskExecutorMock::scheduleWorkAt(
    Date_t when, const CallbackFn& work) {
    if (shouldFailScheduleWorkAtRequest()) {
        return Status(ErrorCodes::OperationFailed,
                      str::stream() << "failed to schedule work at " << when.toString());
    }
    return getExecutor()->scheduleWorkAt(when, work);
}
开发者ID:RyanBard,项目名称:mongo,代码行数:8,代码来源:task_executor_mock.cpp

示例3: expectConfigCollectionInsert

void ShardingTestFixture::expectConfigCollectionInsert(const HostAndPort& configHost,
                                                       StringData collName,
                                                       Date_t timestamp,
                                                       const std::string& what,
                                                       const std::string& ns,
                                                       const BSONObj& detail) {
    onCommand([&](const RemoteCommandRequest& request) {
        ASSERT_EQUALS(configHost, request.target);
        ASSERT_EQUALS("config", request.dbname);

        BatchedInsertRequest actualBatchedInsert;
        std::string errmsg;
        ASSERT_TRUE(actualBatchedInsert.parseBSON(request.dbname, request.cmdObj, &errmsg));

        ASSERT_EQ("config", actualBatchedInsert.getNS().db());
        ASSERT_EQ(collName, actualBatchedInsert.getNS().coll());

        auto inserts = actualBatchedInsert.getDocuments();
        ASSERT_EQUALS(1U, inserts.size());

        const ChangeLogType& actualChangeLog = assertGet(ChangeLogType::fromBSON(inserts.front()));

        ASSERT_EQUALS(operationContext()->getClient()->clientAddress(true),
                      actualChangeLog.getClientAddr());
        ASSERT_EQUALS(detail, actualChangeLog.getDetails());
        ASSERT_EQUALS(ns, actualChangeLog.getNS());
        ASSERT_EQUALS(network()->getHostName(), actualChangeLog.getServer());
        ASSERT_EQUALS(timestamp, actualChangeLog.getTime());
        ASSERT_EQUALS(what, actualChangeLog.getWhat());

        // Handle changeId specially because there's no way to know what OID was generated
        std::string changeId = actualChangeLog.getChangeId();
        size_t firstDash = changeId.find("-");
        size_t lastDash = changeId.rfind("-");

        const std::string serverPiece = changeId.substr(0, firstDash);
        const std::string timePiece = changeId.substr(firstDash + 1, lastDash - firstDash - 1);
        const std::string oidPiece = changeId.substr(lastDash + 1);

        ASSERT_EQUALS(grid.getNetwork()->getHostName(), serverPiece);
        ASSERT_EQUALS(timestamp.toString(), timePiece);

        OID generatedOID;
        // Just make sure this doesn't throws and assume the OID is valid
        generatedOID.init(oidPiece);

        BatchedCommandResponse response;
        response.setOk(true);

        return response.toBSON();
    });
}
开发者ID:GodotGo,项目名称:mongo,代码行数:52,代码来源:sharding_test_fixture.cpp

示例4: logChange

Status CatalogManagerReplicaSet::logChange(OperationContext* txn,
                                           const string& clientAddress,
                                           const string& what,
                                           const string& ns,
                                           const BSONObj& detail) {
    if (_changeLogCollectionCreated.load() == 0) {
        BSONObj createCmd = BSON("create" << ChangeLogType::ConfigNS << "capped" << true << "size"
                                          << kChangeLogCollectionSize);
        auto result =
            grid.shardRegistry()->runCommandOnConfigWithNotMasterRetries("config", createCmd);
        if (!result.isOK()) {
            LOG(1) << "couldn't create changelog collection: " << causedBy(result.getStatus());
            return result.getStatus();
        }

        Status commandStatus = Command::getStatusFromCommandResult(result.getValue());
        if (commandStatus.isOK() || commandStatus == ErrorCodes::NamespaceExists) {
            _changeLogCollectionCreated.store(1);
        } else {
            LOG(1) << "couldn't create changelog collection: " << causedBy(commandStatus);
            return commandStatus;
        }
    }

    Date_t now = grid.shardRegistry()->getExecutor()->now();
    const std::string hostName = grid.shardRegistry()->getNetwork()->getHostName();
    const string changeId = str::stream() << hostName << "-" << now.toString() << "-" << OID::gen();

    ChangeLogType changeLog;
    changeLog.setChangeId(changeId);
    changeLog.setServer(hostName);
    changeLog.setClientAddr(clientAddress);
    changeLog.setTime(now);
    changeLog.setNS(ns);
    changeLog.setWhat(what);
    changeLog.setDetails(detail);

    BSONObj changeLogBSON = changeLog.toBSON();
    log() << "about to log metadata event: " << changeLogBSON;

    Status result = insert(txn, ChangeLogType::ConfigNS, changeLogBSON, NULL);
    if (!result.isOK()) {
        warning() << "Error encountered while logging config change with ID " << changeId << ": "
                  << result;
    }

    return result;
}
开发者ID:himanshugpt,项目名称:mongo,代码行数:48,代码来源:catalog_manager_replica_set.cpp

示例5: buildJsonString

    /*
    ** Build Json string that represent this element.
    */
    void MongoElement::buildJsonString(Concatenator &con)
    {
        switch (_bsonElement.type())
        {
        /** double precision floating point value */
        case NumberDouble:
            con.append(QString::number(_bsonElement.Double()));
            break;

        /** character string, stored in utf8 */
        case String:
            {
            /*
            ** If you'll write:
            ** 
            **   int valsize    = element.valuesize();
            **   int strsize    = element.valuestrsize();
            **   int bytescount = qstrlen(element.valuestr());
            **  
            ** You'll get:
            **
            **   bytescount + 1 == strsize
            **   strsize + 4    == valsize
            **
            ** So:
            **   bytescount + 5 == valsize
            **
            */

                QString res = QString::fromUtf8(_bsonElement.valuestr(), _bsonElement.valuestrsize() - 1);
                con.append(res);
            }
            break;

        /** an embedded object */
        case Object:
            {
                MongoDocumentPtr doc = asDocument();
                doc->buildJsonString(con);
            }
            break;

        /** an embedded array */
        case Array:
            {
                MongoDocumentPtr doc = asDocument();
                doc->buildJsonString(con);
            }
            break;

        /** binary data */
        case BinData:
            {
                mongo::BinDataType binType = _bsonElement.binDataType();
                if (binType == mongo::newUUID || binType == mongo::bdtUUID) {
                    std::string uuid = HexUtils::formatUuid(_bsonElement, AppRegistry::instance().settingsManager()->uuidEncoding());
                    con.append(QString::fromStdString(uuid));
                    break;
                }

                con.append("<binary>");
            }
            break;

        /** Undefined type */
        case Undefined:
            con.append("<undefined>");
            break;

        /** ObjectId */
        case jstOID:
            {
                QString idValue = QString::fromStdString(_bsonElement.OID().toString());
                QString objectId = QString("ObjectId(\"%1\")").arg(idValue);
                con.append(objectId);
            }
            break;

        /** boolean type */
        case Bool:
            con.append(_bsonElement.Bool() ? "true" : "false");
            break;

        /** date type */
        case Date:
        {
            long long ms = (long long) _bsonElement.Date().millis;

            boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
            boost::posix_time::time_duration diff = boost::posix_time::millisec(ms);
            boost::posix_time::ptime time = epoch + diff;



            std::stringstream strm;

            //boost::date_time::time_facet *timeFacet = new boost::date_time::time_facet("%a, %d %b %Y %H:%M:%S.%f GMT"); // "%Y---%m-%d %H:%M:%S"
//.........这里部分代码省略.........
开发者ID:strogo,项目名称:robomongo,代码行数:101,代码来源:MongoElement.cpp

示例6: buildJsonString

    /*
    ** Build Json string that represent this element.
    */
    void MongoElement::buildJsonString(std::string &con)
    {
        switch (_bsonElement.type())
        {
        /** double precision floating point value */
        case NumberDouble:
            con.append(QtUtils::toStdString<std::string>(QString::number(_bsonElement.Double(),'g',14)));
            break;

        /** character string, stored in utf8 */
        case String:
            {
            /*
            ** If you'll write:
            ** 
            **   int valsize    = element.valuesize();
            **   int strsize    = element.valuestrsize();
            **   int bytescount = qstrlen(element.valuestr());
            **  
            ** You'll get:
            **
            **   bytescount + 1 == strsize
            **   strsize + 4    == valsize
            **
            ** So:
            **   bytescount + 5 == valsize
            **
            */

                con.append(_bsonElement.valuestr(), _bsonElement.valuestrsize() - 1);
            }
            break;

        /** an embedded object */
        case Object:
            {
                MongoDocumentPtr doc = asDocument();
                doc->buildJsonString(con);
            }
            break;

        /** an embedded array */
        case Array:
            {
                MongoDocumentPtr doc = asDocument();
                doc->buildJsonString(con);
            }
            break;

        /** binary data */
        case BinData:
            {
                mongo::BinDataType binType = _bsonElement.binDataType();
                if (binType == mongo::newUUID || binType == mongo::bdtUUID) {
                    std::string uuid = HexUtils::formatUuid(_bsonElement, AppRegistry::instance().settingsManager()->uuidEncoding());
                    con.append(uuid);
                    break;
                }

                con.append("<binary>");
            }
            break;

        /** Undefined type */
        case Undefined:
            con.append("<undefined>");
            break;

        /** ObjectId */
        case jstOID:
            {
                std::string idValue = _bsonElement.OID().toString();
                char buff[256]={0};
                sprintf(buff,"ObjectId(\"%s\")",idValue.c_str());
                con.append(buff);
            }
            break;

        /** boolean type */
        case Bool:
            con.append(_bsonElement.Bool() ? "true" : "false");
            break;

        /** date type */
        case Date:
        {
            long long ms = (long long) _bsonElement.Date().millis;

            boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
            boost::posix_time::time_duration diff = boost::posix_time::millisec(ms);
            boost::posix_time::ptime time = epoch + diff;

            std::string date = miutil::isotimeString(time,false,AppRegistry::instance().settingsManager()->timeZone()==LocalTime);

            con.append(date);
            break;
        }
//.........这里部分代码省略.........
开发者ID:eugenkr,项目名称:robomongo,代码行数:101,代码来源:MongoElement.cpp

示例7: buildJsonString

        void buildJsonString(const mongo::BSONElement &elem,std::string &con, UUIDEncoding uuid, SupportedTimes tz)
        {
            switch (elem.type())
            {
            case NumberDouble:
                {
                    char dob[32] = {0};
                    sprintf(dob, "%f", elem.Double());
                    con.append(dob);
                }
                break;
            case String:
                {
                    con.append(elem.valuestr(), elem.valuestrsize() - 1);
                }
                break;
            case Object:
                {
                    buildJsonString(elem.Obj(), con, uuid, tz);
                }
                break;
            case Array:
                {
                    buildJsonString(elem.Obj(), con, uuid, tz);
                }
                break;
            case BinData:
                {
                    mongo::BinDataType binType = elem.binDataType();
                    if (binType == mongo::newUUID || binType == mongo::bdtUUID) {
                        std::string uu = HexUtils::formatUuid(elem, uuid);
                        con.append(uu);
                        break;
                    }
                    con.append("<binary>");
                }
                break;
            case Undefined:
                con.append("<undefined>");
                break;
            case jstOID:
                {
                    std::string idValue = elem.OID().toString();
                    char buff[256] = {0};
                    sprintf(buff, "ObjectId(\"%s\")", idValue.c_str());
                    con.append(buff);
                }
                break;
            case Bool:
                con.append(elem.Bool() ? "true" : "false");
                break;
            case Date:
                {
                    long long ms = (long long) elem.Date().millis;

                    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
                    boost::posix_time::time_duration diff = boost::posix_time::millisec(ms);
                    boost::posix_time::ptime time = epoch + diff;

                    std::string date = miutil::isotimeString(time,false,tz==LocalTime);

                    con.append(date);
                    break;
                }
            case jstNULL:
                con.append("<null>");
                break;

            case RegEx:
                {
                    con.append("/" + std::string(elem.regex()) + "/");

                    for ( const char *f = elem.regexFlags(); *f; ++f ) {
                        switch ( *f ) {
                        case 'g':
                        case 'i':
                        case 'm':
                            con+=*f;
                        default:
                            break;
                        }
                    }
                }
                break;
            case DBRef:
                break;
            case Code:
                con.append(elem._asCode());
                break;
            case Symbol:
                con.append(elem.valuestr(), elem.valuestrsize() - 1);
                break;
            case CodeWScope:
                {
                    mongo::BSONObj scope = elem.codeWScopeObject();
                    if (!scope.isEmpty() ) {
                        con.append(elem._asCode());
                        break;
                    }
                }
//.........这里部分代码省略.........
开发者ID:melinite,项目名称:robomongo,代码行数:101,代码来源:BsonUtils.cpp


注:本文中的Date_t::toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。