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


C++ Document::AddMember方法代码示例

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


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

示例1: sendData

void FileMonitorClient::sendData(int command, const char *buf, ssize_t len)
{
    
    
    Document d;
    d.SetObject();
    
    rapidjson::Value data;
    data.SetString(buf, (SizeType)len);
    d.AddMember("command", command, d.GetAllocator());
    d.AddMember("data", data, d.GetAllocator());
    
    StringBuffer buffer;
    Writer<StringBuffer> writer(buffer);
    d.Accept(writer);
    
    std::string senddata = buffer.GetString();
    len = senddata.size();
    std::cout<<senddata<<std::endl;
    ssize_t send_len=0;
    char bufs[10]={0};
    sprintf(bufs, "%09lu",senddata.size());
    std::string buflen(bufs);
    buflen.append(senddata);
    
    while (send_len<len) {
        send_len = send(sokt, buflen.c_str(), buflen.size(), 0);
        int err = errno;
        if (err>0) {
            std::cout<<("send packet fail")<<strerror(err)<<std::endl;
            close_=false;
            break;
        }
    }
}
开发者ID:leonhe,项目名称:FileMonitor,代码行数:35,代码来源:FileMonitorClient.cpp

示例2: sendApi

//发送json命令的基础函数
Document Device::sendApi(CString &type, Value &method, Value &params, Value &version)
{
	CString actionurl = findActionListUrl(type);
	if (!actionurl || actionurl.IsEmpty())
	{
		return NULL;
	}
	CString url = actionurl + "/" + type;

	Document requestJson;
	requestJson.SetObject();
	Document::AllocatorType& allocator = requestJson.GetAllocator();
	
	requestJson.AddMember("method", method, allocator);
	requestJson.AddMember("params", params, allocator);
	requestJson.AddMember("id", ++reqId, allocator);
	requestJson.AddMember("version", version, allocator);
	
	StringBuffer buffer;
	Writer<StringBuffer> writer(buffer);
	requestJson.Accept(writer);
	const char* output = buffer.GetString();

	CString response = HttpClient::post(url, CString(output));
	if (!response || response.IsEmpty())
	{
		return NULL;
	}

	Document responseJson;
	responseJson.Parse(response);
	return responseJson;
}
开发者ID:zkq,项目名称:SonyRemoteControlCamera,代码行数:34,代码来源:device.cpp

示例3: EnqueuePushData

void AbstractWSServer::EnqueuePushData() {
    // Now give all the possibility to produce new data... which will never be sent if we closed but who cares!
    std::for_each(pushing.cbegin(), pushing.cend(), [this](const PushList &mangle) {
        using namespace rapidjson;
        for(asizei loop = 0; loop < mangle.active.size(); loop++) {
            Document send;
            if(mangle.active[loop]->pusher->Refresh(send)) {
                Document ret;
                ret.SetObject();
                const std::string &ori(mangle.active[loop]->originator->name);
                ret.AddMember("pushing", StringRef(ori.c_str()), ret.GetAllocator());
                if(mangle.active[loop]->originator->GetMaxPushing() > 1) ret.AddMember("stream", StringRef(mangle.active[loop]->name.c_str()), ret.GetAllocator());
                ret.AddMember("payload", send, ret.GetAllocator());
                auto sink = std::find_if(clients.cbegin(), clients.cend(), [&mangle](const ClientState &test) {
                    return &test.conn.get() == mangle.dst && test.ws.get();
                });
                if(sink != clients.cend()) {
                    rapidjson::StringBuffer pretty;
                    #if _DEBUG
                    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(pretty, nullptr);
                    #else
                    rapidjson::Writer<rapidjson::StringBuffer> writer(pretty, nullptr);
                    #endif
                    ret.Accept(writer);
                    sink->ws->EnqueueTextMessage(pretty.GetString(), pretty.GetSize());
                }
            }
        }
    });
}
开发者ID:Golcoin,项目名称:M8M,代码行数:30,代码来源:AbstractWSServer.cpp

示例4: serialize

      Document JsonTransactionFactory::serialize(
          const Transaction &transaction) {
        Document document;
        auto& allocator = document.GetAllocator();
        document.SetObject();

        Value signatures;
        signatures.SetArray();
        for (const auto &signature : transaction.signatures) {
          signatures.PushBack(
              Document(&allocator)
                  .CopyFrom(serializeSignature(signature), allocator),
              allocator);
        }
        document.AddMember("signatures", signatures, allocator);

        document.AddMember("created_ts", transaction.created_ts, allocator);
        document.AddMember("creator_account_id", transaction.creator_account_id, allocator);
        document.AddMember("tx_counter", transaction.tx_counter, allocator);


        Value commands;
        commands.SetArray();
        for (auto &&command : transaction.commands) {
          commands.PushBack(
              Document(&allocator)
                  .CopyFrom(factory_.serializeAbstractCommand(command),
                            allocator),
              allocator);
        }

        document.AddMember("commands", commands, allocator);

        return document;
      }
开发者ID:eduardonunesp,项目名称:iroha,代码行数:35,代码来源:json_transaction_factory.cpp

示例5: writeDevicePixels

void FCDevice::writeDevicePixels(Document &msg)
{
    /*
     * Write pixels without mapping, from a JSON integer
     * array in msg["pixels"]. The pixel array is removed from
     * the reply to save network bandwidth.
     *
     * Pixel values are clamped to [0, 255], for convenience.
     */

    const Value &pixels = msg["pixels"];
    if (!pixels.IsArray()) {
        msg.AddMember("error", "Pixel array is missing", msg.GetAllocator());
    } else {

        // Truncate to the framebuffer size, and only deal in whole pixels.
        int numPixels = pixels.Size() / 3;
        if (numPixels > NUM_PIXELS)
            numPixels = NUM_PIXELS;

        for (int i = 0; i < numPixels; i++) {
            uint8_t *out = fbPixel(i);

            const Value &r = pixels[i*3 + 0];
            const Value &g = pixels[i*3 + 1];
            const Value &b = pixels[i*3 + 2];

            out[0] = std::max(0, std::min(255, r.IsInt() ? r.GetInt() : 0));
            out[1] = std::max(0, std::min(255, g.IsInt() ? g.GetInt() : 0));
            out[2] = std::max(0, std::min(255, b.IsInt() ? b.GetInt() : 0));
        }

        writeFramebuffer();
    }
}
开发者ID:RGB-123,项目名称:fadecandy,代码行数:35,代码来源:fcdevice.cpp

示例6: state

void
Renderer::SaveState(std::string name)
{
  Document doc;
  doc.Parse("{}");

  Value state(kObjectType);

  state.AddMember("Volume", Value().SetString("volname", doc.GetAllocator()), doc.GetAllocator());

	getCamera().saveState(doc, state);
	getRenderProperties().saveState(doc, state);
	getTransferFunction().saveState(doc, state);
	getColorMap().saveState(doc, state["TransferFunction"]);
	getSlices().saveState(doc, state);
	getIsos().saveState(doc, state);

  doc.AddMember("State", state, doc.GetAllocator());

  StringBuffer sbuf;
  PrettyWriter<StringBuffer> writer(sbuf);
  doc.Accept(writer);

  std::ofstream out;
  out.open(name.c_str(), std::ofstream::out);
  out << sbuf.GetString() << "\n";
  out.close();
}
开发者ID:TACC,项目名称:VolViewer,代码行数:28,代码来源:Renderer.cpp

示例7: main

int main(int argc, char **argv)
{
    Document d;
    d.SetObject();
    Value vElem;
    vElem.SetArray();

    Document::AllocatorType & allocator = d.GetAllocator();
    for(int i = 0; i < 10; ++i)
    {
        Value tmp;///(i);
        tmp.SetInt(i);
      //  vElem.PushBack<int>(i, d.GetAllocator);
        vElem.PushBack(tmp, allocator);
    }
    d.AddMember("Data", vElem, allocator);

    StringBuffer buffer;
    Writer<StringBuffer> writer(buffer);
    d.Accept(writer);
    string json(buffer.GetString(), buffer.GetSize());
    cout << json << endl;
 //   Document::AllocatorType& a = d.GetAllocator();
 //  cout <<  d["test"].IsNull() << endl;// = 1;

 //   Value v1("foo");
  //  Value v2(v1, a);

    



}
开发者ID:loveclj,项目名称:c-,代码行数:33,代码来源:test_document.cpp

示例8: Convert

rapidjson::Document SceneConvertor::Convert( const Scene* scene )
{
	Document json;
	json.SetObject();
	Document::AllocatorType& al = json.GetAllocator();

	
	json.AddMember( "FILE_TYPE",		"SCENE",							al );

	Value stringNode;
	Value nullNode;
	nullNode.SetNull();

	Material* skyboxMat = scene->GetSkyboxMaterial();
	if (skyboxMat != NULL)
	{
		stringNode.SetString( skyboxMat->GetName().ToChar(),				al );
		json.AddMember( "skyboxMaterial",	stringNode,						al );
	}
	else
	{
		json.AddMember( "skyboxMaterial",	nullNode,						al );
	}

	json.AddMember( "skyboxSize",	scene->GetSkyboxSize(),					al );

	Value vec3Node = _Vec3_to_JSON( scene->GetAmbientLight(), al );
	json.AddMember( "ambientLight",	vec3Node,								al );

		
	if ( scene->GetMainCamera() != NULL )
	{
		stringNode.SetString( scene->GetMainCamera()->GetName().ToChar(),	al );
		json.AddMember( "mainCamera",	stringNode,							al );
	}
	else
	{
		json.AddMember( "mainCamera",	nullNode,							al );
	}

	Value arrayNode;
	arrayNode.SetArray();
	for (uint i = 0; i < scene->GetGameObjectCount(); ++i)
	{
		GameObject* gameObject = scene->GetGameObjectAt(i);
		if ( gameObject->GetParentNode() == NULL && (_useAll || gameObject->IsSavable()) )
		{
			arrayNode.PushBack( _GameObject_to_JSON(gameObject, al),		al );
		}
	}

	json.AddMember( "gameObjects",		arrayNode,							al );


	return json;
}
开发者ID:MorcoFreeCode,项目名称:2015__MorcoEngine3D,代码行数:56,代码来源:SceneConvertor.cpp

示例9: main

int main(int argc, const char* argv[]) {
    
    luaL_openlibs(L);
    
    luabridge::getGlobalNamespace(L)
        .beginClass<Entity>("Entity")
            .addConstructor<void(*)(void)>()
            .addFunction("say", &Entity::say)
            .addFunction("getComponent", &Entity::getComponent)
            .addFunction("addComponent", &Entity::addComponent)
        .endClass()
        .beginClass<Component>("Component")
            .addCFunction("getVariable", &Component::getVariable)
            .addCFunction("setVariable", &Component::setVariable)
            .addFunction("getParent", &Component::getParent)
            .addFunction("addMember", &Component::addMember)
        .endClass();
    
    // --
    
    LuaScript enemyLuaScript(L, "Enemy.lua");
    LuaScript entityLuaScript(L, "Player.lua");
    
    ComponentScript entityScript(&entityLuaScript);
    ComponentScript enemyScript(&enemyLuaScript);
    
    // --
    
    Entity myEntity;
    myEntity.addComponent(&entityScript);
    myEntity.addComponent(&enemyScript);
    
    Entity myEntity2;
    myEntity2.addComponent(&enemyScript);
    
//    myEntity.onLoop();
//    myEntity2.onLoop();
    
    myEntity.getComponent("Player.lua")->getScript()->getReference("doPlayerStuff")->call(myEntity.getComponent("Player.lua"), myEntity2);
    
    // --
    
    Document d;
    d.Parse("{}");
    
    rapidjson::Value entityValue(rapidjson::kObjectType);
    myEntity.onSerialize(&entityValue, &d.GetAllocator());
    myEntity2.onSerialize(&entityValue, &d.GetAllocator());
    
    d.AddMember("entities", entityValue, d.GetAllocator());
    
    rapidjson::StringBuffer sb;
    rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
    d.Accept(writer);
    
    std::cout << sb.GetString() << "\n";
    
}
开发者ID:Malaxiz,项目名称:LuaBridgeWrapper,代码行数:58,代码来源:main.cpp

示例10: serialize

      Document JsonBlockFactory::serialize(const Block &block) {
        Document document;
        auto &allocator = document.GetAllocator();
        document.SetObject();

        Value signatures;
        signatures.SetArray();
        for (const auto &signature : block.sigs) {
          signatures.PushBack(serializeSignature(signature, allocator),
                              allocator);
        }
        document.AddMember("signatures", signatures, allocator);

        document.AddMember("created_ts", block.created_ts, allocator);
        document.AddMember("hash", block.hash.to_hexstring(), allocator);
        document.AddMember(
            "prev_hash", block.prev_hash.to_hexstring(), allocator);
        document.AddMember("height", block.height, allocator);
        document.AddMember("txs_number", block.txs_number, allocator);

        Value commands;
        commands.SetArray();
        for (auto &&transaction : block.transactions) {
          commands.PushBack(
              Document(&allocator)
                  .CopyFrom(factory_.serialize(transaction), allocator),
              allocator);
        }
        document.AddMember("transactions", commands, allocator);

        return document;
      }
开发者ID:kevinmcmahon,项目名称:iroha,代码行数:32,代码来源:json_block_factory.cpp

示例11: writer

// Issue 226: Value of string type should not point to NULL
TEST(Document, AssertAcceptInvalidNameType) {
    Document doc;
    doc.SetObject();
    doc.AddMember("a", 0, doc.GetAllocator());
    doc.FindMember("a")->name.SetNull(); // Change name to non-string type.

    OutputStringStream os;
    Writer<OutputStringStream> writer(os);
    ASSERT_THROW(doc.Accept(writer), AssertException);
}
开发者ID:Longhui,项目名称:mysql-5.7.9-readcode,代码行数:11,代码来源:documenttest.cpp

示例12: do_read

	void do_read()
	{
		auto self(shared_from_this());
		socket_.async_read_some(boost::asio::buffer(data_, max_length),
			[this, self](boost::system::error_code ec, std::size_t length)
		{
			if (!ec)
			{
				TMP_PACKET* packet = (TMP_PACKET*)(data_);
				Document d;
				d.Parse(packet->strdata);
				Value& ss = d["stars"];
				ss.SetInt(ss.GetInt() + 1);
				OutputDebugString("recv packet");

				Document sendJson;
				sendJson.SetObject();
				Document::AllocatorType& allocator = sendJson.GetAllocator();
				sendJson.AddMember("cmd", 1, allocator);
				sendJson.AddMember("ret", 1, allocator);

				// Convert JSON document to string
				rapidjson::StringBuffer strbuf;
				rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
				sendJson.Accept(writer);
				
				static int totalcnt = 0;
				totalcnt++;

				TCP_PACKET_H hdr;
				hdr.PacketSize = strbuf.GetSize()+ 1 + sizeof(TCP_PACKET_H);
				memcpy_s(_sendData, sizeof(TCP_PACKET_H), (void*)&hdr, sizeof(TCP_PACKET_H));
				std::cout << strbuf.GetString() << strbuf.GetSize() << " total:"<< totalcnt << std::endl;
				//std::cout << strbuf.GetSize() << std::endl;
				sprintf_s(_sendData + sizeof(TCP_PACKET_H), strbuf.GetSize()+1, "%s",strbuf.GetString());


				
				
				// 오류코드 없으면, 패킷데이터 처리..
				// 헤더검사 등의 예외처리 필요..
				//TMP_PACKET sendPkt;
				//sendPkt.Header.PacketSize = strbuf.GetSize()+;
				do_write(hdr.PacketSize);

				do_read();

			}
		});
	}
开发者ID:ak47-nexon,项目名称:asioserver,代码行数:50,代码来源:main.cpp

示例13: SetField

int ConfigParser::SetField(const char* field, const char* value)
{
    stringstream err;
    FILE* fpRead = fopen(configPath.c_str(), "rb");

    if(!fpRead){
        err << "Could not open file " << configPath << "!";
        errors.push_back(err.str());
        return -1; 
    }
    char readBuffer[CONFIGPARSER_BUF_SIZE] = {};
    FileReadStream configStream(fpRead, readBuffer, sizeof(readBuffer));

    Document d;
    d.ParseStream(configStream);

    if(d.HasMember(field)){
        Value& tmp(d[field]);
        tmp.SetString(StringRef(value));
    }
    else
    {
        Value::AllocatorType& a(d.GetAllocator());
        d.AddMember(StringRef(field), StringRef(value), a);
        if(!d.HasMember(field)){
            fclose(fpRead);
            err << "Failed to set field '" << field << "'' in config file " << configPath << "!";
            errors.push_back(err.str());
            return -1; 
        }
    }
    fclose(fpRead);

    FILE* fpWrite = fopen(configPath.c_str(), "wb");
    if(!fpWrite){
        err << "Could not open file " << configPath << "!";
        errors.push_back(err.str());
        return -1; 
    }

    char writeBuffer[CONFIGPARSER_BUF_SIZE] = {};
    FileWriteStream configWriteStream(fpWrite, writeBuffer, sizeof(writeBuffer));
    PrettyWriter<FileWriteStream> writer(configWriteStream);
    d.Accept(writer);

    fclose(fpWrite);

    return 0;
}
开发者ID:muzzley,项目名称:alljoyn-muzzley-gateway-connector,代码行数:49,代码来源:ConfigParser.cpp

示例14: WriteDataJson

bool ZatData::WriteDataJson()
{
  void* file;
  if (!(file = XBMC->OpenFileForWrite(data_file.c_str(), true)))
  {
    XBMC->Log(LOG_ERROR, "Save data.json failed.");
    return false;
  }

  Document d;
  d.SetObject();

  Value a(kArrayType);
  Document::AllocatorType& allocator = d.GetAllocator();
  for (auto const& item : recordingsData)
  {
    if (!item.second->stillValid)
    {
      continue;
    }

    Value r;
    r.SetObject();
    Value recordingId;
    recordingId.SetString(item.second->recordingId.c_str(),
        item.second->recordingId.length(), allocator);
    r.AddMember("recordingId", recordingId, allocator);
    r.AddMember("playCount", item.second->playCount, allocator);
    r.AddMember("lastPlayedPosition", item.second->lastPlayedPosition,
        allocator);
    a.PushBack(r, allocator);
  }
  d.AddMember("recordings", a, allocator);

  StringBuffer buffer;
  Writer<StringBuffer> writer(buffer);
  d.Accept(writer);
  const char* output = buffer.GetString();
  XBMC->WriteFile(file, output, strlen(output));
  XBMC->CloseFile(file);
  return true;
}
开发者ID:vdrtuxnet,项目名称:pvr.zattoo,代码行数:42,代码来源:ZatData.cpp

示例15: Set

/**
 * Specialisation of Options::SetImpl to store strings.
 * This specialisation is necessary because the value must be copied.
 * rapidjson requires that (a.) it explicitly be copied, or that (b.) it will
 * retain a reference that is guaranteed to be valid for longer than itself.
 * @param key The key to the value.
 * @param val The value to be stored.
 */
void Options::Set(const char *key, const char *val) {
    Document *d = static_cast<Document*>(m_doc);
    Value *fi = static_cast<Value*>(m_family_inst);

    if (!fi) { //Family doesn't exist, so create it
        Value family_key(m_family.c_str(), d->GetAllocator());
        Value family_val(Type::kObjectType);
        Value entry_key(key, d->GetAllocator());
        Value entry_val(val, d->GetAllocator());

        family_val.AddMember(entry_key, entry_val, d->GetAllocator());
        d->AddMember(family_key, family_val, d->GetAllocator());
        m_family_inst = &(*d)[m_family.c_str()];
    } else { //We have the family
        Value *existing = LGetValue(fi, key);
        if (existing) { //The entry was already there, so just update value
            existing->SetString(val, d->GetAllocator());
        } else { //Create the new entry
            Value entry_key(key, d->GetAllocator());
            Value entry_val(val, d->GetAllocator());
            fi->AddMember(entry_key, entry_val, d->GetAllocator());
        }
    }
}
开发者ID:picopter,项目名称:picopterx,代码行数:32,代码来源:opts.cpp


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