本文整理汇总了C++中yaml::Node::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::end方法的具体用法?C++ Node::end怎么用?C++ Node::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml::Node
的用法示例。
在下文中一共展示了Node::end方法的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;
}
示例2: 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;
}
示例3: 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
}
示例4: TSDebug
/**
reads all the regular expressions from the database.
and compile them
*/
void
RegexManager::load_config(YAML::Node cfg)
{
try
{
TSDebug(BANJAX_PLUGIN_NAME, "Setting regex re2 options");
RE2::Options opt;
opt.set_log_errors(false);
opt.set_perl_classes(true);
opt.set_posix_syntax(true);
TSDebug(BANJAX_PLUGIN_NAME, "Loading regex manager conf");
//now we compile all of them and store them for later use
for(YAML::const_iterator it = cfg.begin(); it != cfg.end(); ++it) {
string cur_rule = (const char*) (*it)["rule"].as<std::string>().c_str();
TSDebug(BANJAX_PLUGIN_NAME, "initiating rule %s", cur_rule.c_str());
unsigned int observation_interval = (*it)["interval"].as<unsigned int>();
unsigned int threshold = (*it)["hits_per_interval"].as<unsigned int>();
rated_banning_regexes.push_back(new RatedRegex(cur_rule, new RE2((const char*)((*it)["regex"].as<std::string>().c_str()), opt), observation_interval * 1000, threshold /(double)(observation_interval* 1000)));
}
}
catch(YAML::RepresentationException& e)
{
TSDebug(BANJAX_PLUGIN_NAME, "Error loading regex manager conf [%s].", e.what());
return;
}
TSDebug(BANJAX_PLUGIN_NAME, "Done loading regex manager conf");
}
示例5: ParseConvertedUnits
//==============================================================================
/// Parse the converted units list from a document.
///
/// \param [in] unit_list The list of converted units.
///
void DefinitionParser::ParseConvertedUnits( const YAML::Node& unit_list )
{
for ( YAML::Iterator it = unit_list.begin(); it != unit_list.end(); ++it )
{
ParseConvertedUnit( *it );
}
}
示例6: ForceInsertIntoMap
TEST ForceInsertIntoMap()
{
YAML::Node node;
node["a"] = "b";
node.force_insert("x", "y");
node.force_insert("a", 5);
YAML_ASSERT(node.size() == 3);
YAML_ASSERT(node.Type() == YAML::NodeType::Map);
bool ab = false;
bool a5 = false;
bool xy = false;
for(YAML::const_iterator it=node.begin();it!=node.end();++it) {
if(it->first.as<std::string>() == "a") {
if(it->second.as<std::string>() == "b")
ab = true;
else if(it->second.as<std::string>() == "5")
a5 = true;
} else if(it->first.as<std::string>() == "x" && it->second.as<std::string>() == "y")
xy = true;
}
YAML_ASSERT(ab);
YAML_ASSERT(a5);
YAML_ASSERT(xy);
return true;
}
示例7: 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;
}
示例8: 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);
}
}
示例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;
}
示例10: 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;
}
}
示例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;
}
示例12: 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);
}
示例13: 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));
}
}
示例14: 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);
}
}
示例15: 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);
}
}
}