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


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

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


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

示例1: loadPins

void PiIO::loadPins()
{
  // fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("pins.json");
//http://rapidjson.org/md_doc_stream.html#FileReadStream

  cout << "load pins" << endl;

  FILE* fp = fopen("pins.json", "r"); // non-Windows use "r"
  char readBuffer[65536];
  FileReadStream is(fp, readBuffer, sizeof(readBuffer));
  Document document;
  document.ParseStream(is);
  fclose(fp);

  assert(document.HasMember("pins"));
  assert(document.IsObject());

  const Value& data = document["pins"];
  //const Value& data = document.FindMember("pins");//.value;
  int size = data.Size();
  size = size - 1;
  cout << "Size is " << size << endl;
  for (int i = size; i >= 0; i--){ // Uses SizeType instead of size_t
    int wpi = -1;
    if(data[i].HasMember("wpi")){
      wpi = data[i]["wpi"].GetInt();
    }
    pins[i].startup(data[i]["pin"].GetInt(), data[i]["name"].GetString(), wpi, i);
  }
  cout << getInfoString() << endl;
}
开发者ID:thepoho,项目名称:pi_tester,代码行数:31,代码来源:pi_io.cpp

示例2: ParseGameTitlesFromFile

void ParseGameTitlesFromFile(std::map<GameID, std::string>& GameTitlesListOut)
{
	SetCurrentDirectory(NativeStr(g_sHomeDir).c_str());
	FILE* pf = nullptr;
	fopen_s(&pf, RA_TITLES_FILENAME, "rb");
	if (pf != nullptr)
	{
		Document doc;
		doc.ParseStream(FileStream(pf));

		if (!doc.HasParseError() && doc.HasMember("Success") && doc["Success"].GetBool() && doc.HasMember("Response"))
		{
			const Value& List = doc["Response"];
			for (Value::ConstMemberIterator iter = List.MemberBegin(); iter != List.MemberEnd(); ++iter)
			{
				if (iter->name.IsNull() || iter->value.IsNull())
					continue;

				GameID nID = static_cast<GameID>(std::strtoul(iter->name.GetString(), nullptr, 10));	//	KEYS ARE STRINGS, must convert afterwards!
				const std::string sTitle = iter->value.GetString();
				GameTitlesListOut[nID] = sTitle;
			}
		}

		fclose(pf);
	}
}
开发者ID:RetroAchievements,项目名称:RASuite,代码行数:27,代码来源:RA_Dlg_GameLibrary.cpp

示例3: save

void Scene::save()
{
	std::ifstream ifs(settings_file);
	rapidjson::IStreamWrapper isw(ifs);

	Document doc;
	doc.ParseStream(isw);
	ifs.close();

	ofstream ofs(settings_file);
	OStreamWrapper osw(ofs);
	Writer<OStreamWrapper> writer(osw);

	Value& scene = doc["scene"];

	scene["carcas_enabled"].SetBool(carcas_enabled);
	scene["animation_enabled"].SetBool(animation_enabled);
	scene["texture_enabled"].SetBool(texture_enabled);
	scene["partition"].SetInt(partition);
	scene["current_time"].SetFloat(current_time);
	scene["rotate_x"].SetFloat(rotate_x);
	scene["rotate_y"].SetFloat(rotate_y);
	scene["scale"].SetFloat(scale);

	auto lights = doc["lighting"]["local"].GetArray();
	for(auto light : local_lights)
		lights[light.num]["enabled"].SetBool(light.enabled);

	doc.Accept(writer);
	ofs.close();
}
开发者ID:karkin96,项目名称:IU9,代码行数:31,代码来源:Scene.cpp

示例4: SetFromJSONString

// Parse specified string as JSON and set any settings contained in the string 
// to their specified values
bool Settings::SetFromJSONString(const std::string& str)
{
    bool retVal = false;
    StringStream ss(str.c_str());
    
    try
    { 
        Document defaultsDoc;
        defaultsDoc.Parse(_defaultJSON.c_str());
 
        Document doc;
        doc.ParseStream(ss);
        const Value& root = doc[SETTINGS_ROOT_KEY];
        
        // first validate the name & type of each setting from the given string
        for (Value::ConstMemberIterator itr = root.MemberBegin(); 
                                        itr != root.MemberEnd(); ++itr)
        {
            const char* name = itr->name.GetString(); 
            if (!IsValidSettingName(name))
            {
                HandleError(UnknownSetting, true, name);
                return false;
            }
            
            if (!AreSameType(defaultsDoc[SETTINGS_ROOT_KEY][name],
                                     doc[SETTINGS_ROOT_KEY][name]))
            {

                HandleError(WrongTypeForSetting, true, name);
                return false;                
            }
        }
        
        // then set each value into the settings document
        for (Value::ConstMemberIterator itr = root.MemberBegin(); 
                                        itr != root.MemberEnd(); ++itr)
        {
            const char* name = itr->name.GetString();              
            if (_settingsDoc[SETTINGS_ROOT_KEY][name].IsString())
            {
                // need to make a copy of the string to be stored
                const char* str = doc[SETTINGS_ROOT_KEY][name].GetString();
                Value s;
                s.SetString(str, strlen(str), _settingsDoc.GetAllocator());
                _settingsDoc[SETTINGS_ROOT_KEY][name] = s;
            }
            else
                _settingsDoc[SETTINGS_ROOT_KEY][name] = 
                                                doc[SETTINGS_ROOT_KEY][name];
        }
        Save();
        retVal = true;
    }
    catch(std::exception)
    {
        HandleError(CantReadSettingsString, true, str.c_str());
    }
    return retVal;
}
开发者ID:AllenMcAfee,项目名称:ember-firmware,代码行数:62,代码来源:Settings.cpp

示例5: GetField

string ConfigParser::GetField(const char* field)
{
    stringstream err;
    FILE* fp = fopen(configPath.c_str(), "rb");

    if(!fp){
        err << "Could not open file " << configPath << "!";
        errors.push_back(err.str());
        return ""; 
    }

    char readBuffer[CONFIGPARSER_BUF_SIZE] = {};
    FileReadStream configStream(fp, readBuffer, sizeof(readBuffer));

    Document d;
    d.ParseStream(configStream);

    if(d.HasMember(field)){
        Value& s = d[field];
        string value;
        if ( s.IsString() )
        {
            value = s.GetString();
        }
        fclose(fp);
        return value;
    }

    err << "Could not find field " << field << "!";
    errors.push_back(err.str());
    fclose(fp);

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

示例6: GetPort

int ConfigParser::GetPort()
{
    stringstream err;
    FILE* fp = fopen(configPath.c_str(), "rb");

    if(!fp){
        err << "Could not open file " << configPath << "!";
        errors.push_back(err.str());
        return -1;
    }

    char readBuffer[CONFIGPARSER_BUF_SIZE] = {};
    FileReadStream configStream(fp, readBuffer, sizeof(readBuffer));

    Document d;
    d.ParseStream(configStream);

    if(d.HasMember("Port")){
        Value& s = d["Port"];
        fclose(fp);
        return s.GetInt();
    }

    err << "Could not find field [Port]!";
    errors.push_back(err.str());
    fclose(fp);

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

示例7: ifs

static void* pfwl_field_tags_load_L7(pfwl_field_id_t field, const char* fileName){
  void* db = NULL;
  if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_STRING){
    db = new pfwl_field_matching_db_t;
  }else if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_MMAP){
    db = new std::map<std::string, pfwl_field_matching_db_t>;
  }

  if(fileName){
    std::ifstream ifs(fileName);
    IStreamWrapper isw(ifs);
    Document d;
    d.ParseStream(isw);

    if (d.HasParseError()){
      return NULL;
    }

    const Value& rules = d["rules"];
    assert(rules.IsArray());
    for (Value::ConstValueIterator itr = rules.Begin(); itr != rules.End(); ++itr) {
        const Value& stringToMatch = (*itr)["value"];
        const Value& matchingType = (*itr)["matchingType"];
        const Value& tag = (*itr)["tag"];
        if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_STRING){
          pfwl_field_string_tags_add_internal(static_cast<pfwl_field_matching_db_t*>(db), stringToMatch.GetString(), getFieldMatchingType(matchingType.GetString()), tag.GetString());
        }else if(pfwl_get_L7_field_type(field) == PFWL_FIELD_TYPE_MMAP){
          const Value& key = (*itr)["key"];
          pfwl_field_mmap_tags_add_internal(static_cast<std::map<std::string, pfwl_field_matching_db_t>*>(db), key.GetString(), stringToMatch.GetString(), getFieldMatchingType(matchingType.GetString()), tag.GetString());
        }
    }
  }
  return db;
}
开发者ID:DanieleDeSensi,项目名称:Peafowl,代码行数:34,代码来源:tags.cpp

示例8: v_initialize

    /**
     * class ResourceManager
     */
    bool ResourceManager::v_initialize(void) {
        FILE* fp = fopen(m_configFile.c_str(), "rb");
        char readBuffer[65536];
        FileReadStream is(fp, readBuffer, sizeof(readBuffer));

        Document jsonConfig;
        jsonConfig.ParseStream(is);

        const Value& a = jsonConfig;
        assert(a.IsArray());
        for (SizeType i = 0; i < a.Size(); i++) {// Uses SizeType instead of size_t
            assert(a[i].IsObject());

            assert(a[i].HasMember("id"));
            assert(a[i]["id"].IsInt());

            assert(a[i].HasMember("name"));
            assert(a[i]["name"].IsString());

            assert(a[i].HasMember("path"));
            assert(a[i]["path"].IsString());

            assert(a[i].HasMember("pipeline"));
            assert(a[i]["pipeline"].IsString());

            int id = a[i]["id"].GetInt();

            // pipeline
            string pipeline = a[i]["pipeline"].GetString();
            if (pipeline.length() >= SIZE_RESOURCE_NAME-1) assert(false);
            long pipelineHash = hashString(pipeline);

            string name = a[i]["name"].GetString();
            if (name.length() >= SIZE_RESOURCE_NAME-1) assert(false);

            string path = a[i]["path"].GetString();
            if (path.length() >= SIZE_RESOURCE_PATH-1) assert(false);

            InternalResHandler *rHandler = new InternalResHandler(id, pipelineHash, name, path);

            if (a[i].HasMember("links")) {
                const Value& links = a[i]["links"];
                assert(links.IsArray());
                for (SizeType i = 0; i < links.Size(); i++) {
                    rHandler->m_linkedResouces[rHandler->m_amountLinkedResouces] = links[i].GetInt();
                    rHandler->m_amountLinkedResouces++;
                }
            }

            ResourcesMap::iterator it = m_resources.find(id);
            //TODO better handling of already existant pipeline for a given resource type
            assert(it == m_resources.end());
            m_resources.insert(std::pair<int, InternalResHandler*>(id, rHandler));

            _INFO("found resource with id  [" << id << "] (" << rHandler->m_name.c_str() << ")");
        }

        fclose(fp);
        return true;
    }
开发者ID:mcamier,项目名称:CCompotePlusPlus,代码行数:63,代码来源:resourceManager.cpp

示例9: run

void run(char* configFilename)
{
    Document config;
    FILE* fp = fopen(configFilename, "r");
    char buffer[4096];
    FileReadStream configFile(fp, buffer, sizeof(buffer));
    config.ParseStream(configFile);
    
    FMFeature trainData, testData;
    FMTarget prediction;

    load_data(config["train_data"].GetString(), trainData, true);
    load_data(config["test_data"].GetString(), testData, false);
    
    fm_train_test(config, trainData, testData, prediction);

    ofstream fout(config["pred"].GetString());
    for (int i = 0; i < prediction.size(); i++)
    {
        fout << prediction[i] << ' ';
        int place = testData.feature[i][0].first;
        if (place == place_count)
            fout << endl;
    }
}
开发者ID:farseev,项目名称:mobility,代码行数:25,代码来源:baseline.cpp

示例10: ParseGameHashLibraryFromFile

void ParseGameHashLibraryFromFile(std::map<std::string, GameID>& GameHashLibraryOut)
{
	SetCurrentDirectory(NativeStr(g_sHomeDir).c_str());
	FILE* pf = NULL;
	fopen_s(&pf, RA_GAME_HASH_FILENAME, "rb");
	if (pf != NULL)
	{
		Document doc;
		doc.ParseStream(FileStream(pf));

		if (!doc.HasParseError() && doc.HasMember("Success") && doc["Success"].GetBool() && doc.HasMember("MD5List"))
		{
			const Value& List = doc["MD5List"];
			for (Value::ConstMemberIterator iter = List.MemberBegin(); iter != List.MemberEnd(); ++iter)
			{
				if (iter->name.IsNull() || iter->value.IsNull())
					continue;

				const std::string sMD5 = iter->name.GetString();
				//GameID nID = static_cast<GameID>( std::strtoul( iter->value.GetString(), NULL, 10 ) );	//	MUST BE STRING, then converted to uint. Keys are strings ONLY
				GameID nID = static_cast<GameID>(iter->value.GetUint());
				GameHashLibraryOut[sMD5] = nID;
			}
		}

		fclose(pf);
	}
}
开发者ID:RetroAchievements,项目名称:RASuite,代码行数:28,代码来源:RA_Dlg_GameLibrary.cpp

示例11: load

  void load(const std::string &filename, vector<unique_ptr<Trellis>> &trellis_buffer) {
    ifstream file_stream(filename);
    IStreamWrapper stream_wrapper(file_stream);
    Document document;
    document.ParseStream(stream_wrapper);

    load_trellises(document["trellises"], trellis_buffer);
  }
开发者ID:silentorb,项目名称:ground_cpp,代码行数:8,代码来源:serialize.cpp

示例12: ReadTestConfig

void ReadTestConfig(char* fname){
	/* Read from JSON file. */
	FILE* fp = fopen(fname, "rb"); // non-Windows use "r"
	assert(fp);
	char readBuffer[65536*2];
	FileReadStream is(fp, readBuffer, sizeof(readBuffer));
	/* Parse from stream*/
	d.ParseStream(is);
	fclose(fp);
}
开发者ID:AnsenYu,项目名称:DMT,代码行数:10,代码来源:simulator.cpp

示例13: isw

TEST(IStreamWrapper, fstream)
{ fstream fs;
  ASSERT_TRUE(Open(fs, "utf8bom.json"));
  IStreamWrapper isw(fs);
  EncodedInputStream<UTF8<>, IStreamWrapper> eis(isw);
  Document d;
  EXPECT_TRUE(!d.ParseStream(eis).HasParseError());
  EXPECT_TRUE(d.IsObject());
  EXPECT_EQ(5, d.MemberCount());
}
开发者ID:ArunkumarRamanan,项目名称:vowpal_wabbit,代码行数:10,代码来源:istreamwrappertest.cpp

示例14: main

int main(int argc, char** argv)
{
    if(argc < 2){
        printf("Usage: %s json_file\n\n", argv[0]);
        return -1;
    }

    FILE* fp = fopen(argv[1], "r");

    char readBuffer[65535];
    FileReadStream is(fp, readBuffer, sizeof(readBuffer));

    Document d;
    d.ParseStream(is);

    fclose(fp);

    //将读取的json重新格式化输出
    printf("\nModified JSON with reformatting:\n");
    StringBuffer sb;
    PrettyWriter<StringBuffer> writer(sb);
    d.Accept(writer);    // Accept() traverses the DOM and generates Handler events.
    puts(sb.GetString());

    printf("\n\n");

    //解析json,生成配置相关的map
    
    assert(d.HasMember("keyname"));

    //get keyname
    const Value& key = d["keyname"];
    assert(key.IsString());

    const char* key_name = key.GetString();

    printf("key:%s\n", key_name);

    //read values
    const Value& values = d["values"];
    assert(values.IsArray());

    printf("values size is:%d\n", values.Size());
    for(Value::ConstValueIterator it=values.Begin(); it != values.End(); ++it) {
        assert(it->IsObject());
        //查找实际的key
        //
        Value::ConstMemberIterator itr = it->FindMember(key_name);
        if(itr != it->MemberEnd()){
            printf("%s : %d\n", itr->name.GetString(), itr->value.GetInt());
        }
    }

    return 0;
}
开发者ID:kevin1sMe,项目名称:excel2json,代码行数:55,代码来源:read_from_file.cpp

示例15: loadDocument

	Document loadDocument(const std::string& documentPath)
	{
		FILE *fp = fopen(documentPath.c_str(), "r"); // non-Windows use "r"
		char readBuffer[65536]; //TODO: check this magic constant
		FileReadStream is(fp, readBuffer, sizeof(readBuffer));
		Document doc;
		doc.ParseStream(is);
		fclose(fp);

		return doc;
	}
开发者ID:RazvanPascalau,项目名称:SVGRasterizer,代码行数:11,代码来源:ConfigLoader.cpp


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