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


C++ Node::begin方法代码示例

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


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

示例1: AreDetailsEqual

    bool AreDetailsEqual(const YAML::Node& lhs, const YAML::Node& rhs) {
        //We want to check for plugin order and messages. 
        if (lhs.IsSequence() && rhs.IsSequence()) {
            std::list<std::string> lhs_names, rhs_names;
            std::list<Message> lhs_messages, rhs_messages;
            
            for (YAML::const_iterator it = lhs.begin(); it != lhs.end(); ++it) {
                if ((*it)["name"])
                    lhs_names.push_back((*it)["name"].as<std::string>());
                if ((*it)["messages"]) {
                    std::list<Message> messages = (*it)["messages"].as< std::list<Message> >();
                    lhs_messages.insert(lhs_messages.end(), messages.begin(), messages.end());
                }
            }
            for (YAML::const_iterator it = rhs.begin(); it != rhs.end(); ++it) {
                if ((*it)["name"])
                    rhs_names.push_back((*it)["name"].as<std::string>());
                if ((*it)["messages"]) {
                    std::list<Message> messages = (*it)["messages"].as< std::list<Message> >();
                    rhs_messages.insert(rhs_messages.end(), messages.begin(), messages.end());
                }
            }

            return lhs_names == rhs_names && lhs_messages == rhs_messages;
        }
        else
            return false;
    }
开发者ID:dbb,项目名称:loot,代码行数:28,代码来源:generators.cpp

示例2: DereferenceIteratorError

 TEST DereferenceIteratorError()
 {
     YAML::Node node = YAML::Load("[{a: b}, 1, 2]");
     YAML_ASSERT_THROWS(node.begin()->first.as<int>(), YAML::InvalidNode);
     YAML_ASSERT((*node.begin()).IsMap() == true);
     YAML_ASSERT(node.begin()->IsMap() == true);
     YAML_ASSERT_THROWS((*node.begin()->begin()).IsDefined(), YAML::InvalidNode);
     YAML_ASSERT_THROWS(node.begin()->begin()->IsDefined(), YAML::InvalidNode);
     return true;
 }
开发者ID:egocarib,项目名称:yaml-cpp,代码行数:10,代码来源:nodetests.cpp

示例3:

map<string, vector<float> > CommandParser::ConvertTaskToExecutiveGoal(pair<string,string> task) {
  string predicate = task.first;
  string subject = task.second;
  map<string, vector<float> > return_goal;
  bool predicate_found = false;
  bool subject_found = false;
  for(YAML::const_iterator root_itr = root_.begin(); root_itr!=root_.end(); root_itr++){
    string command_primitive = root_itr->first.as<string>();
    if(command_primitive==predicate){
      predicate_found = true;
      YAML::Node possible_goals = root_[command_primitive];
      for(YAML::const_iterator goal_itr=possible_goals.begin(); goal_itr!=possible_goals.end(); goal_itr++){
        YAML::Node goal = *goal_itr; // matched associative array in YAML file
        YAML::const_iterator goal_map = goal.begin(); // use this to get key for the array 
        string goal_name = goal_map->first.as<string>();
        if(goal_name==subject){
          subject_found = true;
          return_goal << goal;//overloaded operator see header file
          return return_goal;
        }
      }
    } else {continue;}
  
  }
  
}
开发者ID:bhavyangupta,项目名称:pandubot_wkspc,代码行数:26,代码来源:read_yaml.cpp

示例4: throw

void kul::yaml::File::validate(const YAML::Node& n, const std::vector<NodeValidator>& nvs) throw(Exception) {
    kul::hash::set::String keys;
    for(const auto& nv : nvs) if(nv.name() == "*") return;

    for(YAML::const_iterator it = n.begin(); it != n.end(); ++it){
        const std::string& key(it->first.as<std::string>());
        if(keys.count(key)) KEXCEPTION("Duplicate key detected: " + key + "\n" + this->f);
        keys.insert(key);
        bool f = 0;
        for(const auto& nv : nvs){
            if(nv.name() != key) continue;
            f = 1;
            if(nv.type() == 1 && it->second.Type() != 2) KEXCEPTION("String expected: " + nv.name() + "\n" + this->f);
            if(nv.type() == 2 && it->second.Type() != 3) KEXCEPTION("List expected: " + nv.name() + "\n" + this->f);
            if(nv.type() == 3 && it->second.Type() != 4) KEXCEPTION("Map expected: " + nv.name() + "\n" + this->f);
            if(nv.type() == 2)
                for(size_t i = 0; i < it->second.size(); i++)
                    validate(it->second[i], nv.children());
            if(nv.type() == 3) validate(it->second, nv.children());
        }
        if(!f) KEXCEPTION("Unexpected key: " + key + "\n" + this->f);
    }
    for(const auto& nv : nvs){
        if(nv.mandatory() && !keys.count(nv.name()))
            KEXCEPTION("Key mandatory: : " + nv.name() + "\n" + this->f);
    }
}
开发者ID:yangming85,项目名称:maiken,代码行数:27,代码来源:yaml.cpp

示例5: MergeYaml

YAML::Node MergeYaml( const YAML::Node& a, const YAML::Node& b )
{
	// Short circuit cases
	if( a.IsNull() ) { return b; }
	else if( b.IsNull() ) { return a; }
	
	if( !a.IsMap() || !b.IsMap() )
	{
		throw std::runtime_error( "Cannot merge non-map nodes." );
	}
	
	YAML::Node node;
	CopyYaml( a, node );
	YAML::Node::const_iterator iter;
	// Cycle through b and add all fields to node
	for( iter = b.begin(); iter != b.end(); iter++ )
	{
		std::string key = iter->first.as<std::string>();
		
		// If both a and b have a key we have to merge them
		if( node[key] )
		{
			node[key] = MergeYaml( node[key], iter->second );
		}
		// Otherwise we just add it
		else
		{
			node[key] = iter->second;
		}
	}
	return node;
}
开发者ID:Humhu,项目名称:argus_utils,代码行数:32,代码来源:YamlUtils.cpp

示例6: if

/*
 * This function checks to see if the current YAML::Node contains only keys
 * that we care about. Unknown keys should cause PLFS to spit out an error
 * rather than being silently ignored.
 * This is a bit nasty as it drills through the entire tree recursively
 * but it will catch any unknowns in one pass
 *
 * Returns true if all keys are valid
 *
 * Returns false if unknown keys are found and sets bad_key to an error
 * message that points out what key is invalid
 */
bool
is_valid_node(const YAML::Node node, string** bad_key) {
    set<string> key_list(Valid_Keys, 
                         Valid_Keys + 
                         (sizeof(Valid_Keys) / sizeof(Valid_Keys[0]))
                        );
    string key;
    string err = "\nBad key or value in plfsrc: ";
    if(node.IsMap()) {
        for(YAML::const_iterator it=node.begin();it!=node.end();it++) {
            if(!it->first.IsNull()) {
                key = it->first.as<string>();
                if(!is_valid_node(node[key],bad_key)) // recurse
                    return false;
                if(key_list.find(key) == key_list.end()) {
                    err.append(key);
                    *bad_key = new string (err);
                    return false; // this is an unknown key
                }
            }
        }
    }
    else if (node.IsSequence()) {
        for(unsigned int i = 0; i < node.size(); i++)
            if(!is_valid_node(node[i],bad_key)) // recurse
                return false;
    }
    else if (node.IsScalar() && node.as<string>().find(" ") != string::npos) {
        err.append(node.as<string>());
        *bad_key = new string (err);
        return false; // no spaces in values allowed
    }
    return true; // all keys are valid
}
开发者ID:zhang-jingwang,项目名称:plfs-core,代码行数:46,代码来源:parse_conf.cpp

示例7: Import

void FileBundle::Import(const YAML::Node& config)
{
    switch (config.Type())
    {
    case YAML::NodeType::Scalar:
        ImportScalarNode(config);
        break;
    case YAML::NodeType::Sequence:
        for (auto i = config.begin(); i != config.end(); ++i)
        {
            const YAML::Node& node = *i;
            switch(node.Type())
            {
            case YAML::NodeType::Scalar:
                ImportScalarNode(node);
                break;
            case YAML::NodeType::Map:
                for (auto k = node.begin(); k != node.end(); ++k)
                {
                    auto file = ImportScalarNode(k->second);
                    file->name = k->first.as<string>();
                }
                break;
            }
        }
        break;
    case YAML::NodeType::Map:
        ImportCompositeBundle(config);
        break;
    }
}
开发者ID:jjiezheng,项目名称:ship,代码行数:31,代码来源:file_bundle.cpp

示例8: set_field

		void set_field(doid_t do_id, const Field* field, const val_t &value)
		{
			m_log->trace() << "Setting field on obj-" << do_id << endl;

			YAML::Node document;
			if(!load(do_id, document))
			{
				return;
			}

			// Get the fields from the file that are not being updated
			const Class* dcc = g_dcf->get_class_by_name(document["class"].as<string>());
			ObjectData dbo(dcc->get_id());
			YAML::Node existing = document["fields"];
			for(auto it = existing.begin(); it != existing.end(); ++it)
			{
				const Field* field = dcc->get_field_by_name(it->first.as<string>());
				if(!field)
				{
					m_log->warning() << "Field '" << it->first.as<string>()
					                 << "', loaded from '" << filename(do_id)
					                 << "', does not exist." << endl;
					continue;
				}
				vector<uint8_t> value = read_yaml_field(field, it->second, do_id);
				if(value.size() > 0)
				{
					dbo.fields[field] = value;
				}
			}

			dbo.fields[field] = value;
			write_yaml_object(do_id, dcc, dbo);
		}
开发者ID:Echocage,项目名称:Astron,代码行数:34,代码来源:YAMLDatabase.cpp

示例9: get_fields

		bool get_fields(doid_t do_id, const vector<const Field*> &fields, map_t &values)
		{
			m_log->trace() << "Getting fields on obj-" << do_id << endl;

			YAML::Node document;
			if(!load(do_id, document))
			{
				return false;
			}

			// Get the fields from the file that are not being updated
			for(auto it = fields.begin(); it != fields.end(); ++it)
			{
				const Field* field = *it;
				m_log->trace() << "Searching for field: " << field->get_name() << endl;

				YAML::Node existing = document["fields"];
				for(auto it2 = existing.begin(); it2 != existing.end(); ++it2)
				{
					if(it2->first.as<string>() == field->get_name())
					{
						vector<uint8_t> value = read_yaml_field(field, it2->second, do_id);
						if(value.size() > 0)
						{
							values[*it] = value;
							m_log->trace() << "Found requested field: " + field->get_name() << endl;
						}
					}
				}
			}
			return true;
		}
开发者ID:Echocage,项目名称:Astron,代码行数:32,代码来源:YAMLDatabase.cpp

示例10: load

/**
 * Loads the map data set from a YAML file.
 * @param node YAML node.
 */
void MapDataSet::load(const YAML::Node &node)
{
	for (YAML::const_iterator i = node.begin(); i != node.end(); ++i)
	{
		_name = i->as<std::string>(_name);
	}
}
开发者ID:Scarberian,项目名称:OpenXcom,代码行数:11,代码来源:MapDataSet.cpp

示例11: main

int main(int argc, char* argv[])
{
   
   try
   {
      YAML::Node config = YAML::LoadFile(argv[1]);
      YAML::const_iterator iter =config.begin();
      yaml::ConfigNodePtr np;

      while( iter != config.end())
      {
         const YAML::Node& node = *iter;

         std::string module_name = node["module_name"].as<std::string>();
         
         np = yaml::NodeFactory::Instance().Create( module_name );
         np->Decode(node);
         np->Print(std::cout);
         ++iter;
      }

   }
   catch ( YAML::ParserException& e )
   {
      std::cout << e.what();
   }

   return 0;
}
开发者ID:FlavioFalcao,项目名称:Software-Defined-Radar-Simulator,代码行数:29,代码来源:yaml-test.cpp

示例12: addDevice

/**
 * LoadDevices
 * 
 * Loads devices from configuration object(YAML::Node)
 */
void
InsteonNetwork::loadDevices() {
    YAML::Node device = config_["DEVICES"];
    for (auto it = device.begin(); it != device.end(); ++it) {
        addDevice(it->first.as<int>(0));
    }
}
开发者ID:gitaaronc,项目名称:autohubpp,代码行数:12,代码来源:InsteonNetwork.cpp

示例13: loadPropertySystems

void WorldYamlSource::loadPropertySystems() {

	// iterate through each section (each section is a system)
	std::vector<YAML::Node> nodes = YAML::LoadAllFromFile(dir + "PropertySystems.yaml");
	for (size_t i = 0; i < nodes.size(); i++) {
		YamlWrapper yaml(nodes[i]);

		// parse which system this section is for
		String typeName = yaml.read<String>("Which", "NONE", "Invalid property system.");
		ThingType type = ThingType::fromString(typeName);

		// create the system
		propertySystems[type].reset(new PropertySystem());
		PropertySystem& system = *propertySystems[type];

		// parse the properties of the system
		YAML::Node propertiesNode = yaml["Properties"].getNode();
		for (auto iter = propertiesNode.begin(); iter != propertiesNode.end(); ++iter) {
			YamlWrapper propertyYaml(*iter);
			String name  = propertyYaml.read<String>("Name", "", "Property name not given.");
			Type type    = Type::fromString(propertyYaml.read<String>("Type"));
			Variant def  = readVariant(propertyYaml["Default"].getNode(), type);
			bool mainKey = propertyYaml.read<bool>("MainKey", false);
			system.add(name, type, def, mainKey);
		}
	}
}
开发者ID:lupuchard,项目名称:fek-base,代码行数:27,代码来源:WorldYamlSource.cpp

示例14: loadItems

void WorldYamlSource::loadItems() {
	if (!propertySystems[ThingType::ITEM]) return;
	PropertySystem& itemSys = *propertySystems[ThingType::ITEM];

	std::vector<YAML::Node> nodes = YAML::LoadAllFromFile(dir + "Items.yaml");
	for (size_t i = 0; i < nodes.size(); i++) {
		YamlWrapper yaml(nodes[i]);

		// read base
		String baseName = yaml.read<String>("Base", "", "Item lacks a base.");
		if (baseName == "") continue;
		auto iter = itemBaseNameMap.find(baseName);
		if (iter == itemBaseNameMap.end()) {
			LOG(ERROR) << "'" << baseName << "' is not an existing item base.";
			continue;
		}
		BaseThing& base = *iter->second;

		items.emplace_back(new Item(base, items.size() + 1));
		Item& item = *items.back();

		// read location
		if (yaml["Location"]->IsSequence()) {
			item.moveTo(yaml.read<Coord>("Location", Coord()));
		}

		// read properties
		YAML::Node propertiesNode = yaml["Properties"].getNode();
		for (auto iter = propertiesNode.begin(); iter != propertiesNode.end(); ++iter) {
			const Property& property = itemSys[iter->first.as<String>()];
			item.setValue(property, readVariant(iter->second, property.type));
		}
	}
}
开发者ID:lupuchard,项目名称:fek-base,代码行数:34,代码来源:WorldYamlSource.cpp

示例15: parseConfig

bool Sampler::parseConfig(const string &config_string) {
  YAML::Node node = YAML::Load(config_string);
  for (YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
    string sample_name = it->first.as<string>();
    ui << sample_name << "\n";

    YAML::Node sample_data = it->second;

    if (!sample_data["file"]) {
      ui << "file is required for each sample\n";
      continue;
    }

    string file(sample_data["file"].as<string>());

    float pan = 0.;
    if (sample_data["pan"]) {
      pan = sample_data["pan"].as<float>();
    }

    midi_data_t midi_data = sample_data["midi"].as<int>();

    addSample(midi_data, file, pan);
  }
  return true;
}
开发者ID:ohinds,项目名称:perfen,代码行数:26,代码来源:sampler.cpp


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