本文整理汇总了C++中yaml::Node类的典型用法代码示例。如果您正苦于以下问题:C++ Node类的具体用法?C++ Node怎么用?C++ Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defaultString
bool
KnobSerialization::checkForDefaultValueNode(const YAML::Node& node, const std::string& nodeType, bool dataTypeSet)
{
std::string defaultString("Default");
std::string defaultTypeName = defaultString + nodeType;
if (!node[defaultTypeName]) {
return false;
}
// If the _dataType member was set in checkForValueNode, ensure that the data type of the value is the same as
// the default value.
if (dataTypeSet) {
SerializationValueVariantTypeEnum type = dataTypeFromString(nodeType);
if (type != _dataType) {
throw std::invalid_argument(_scriptName + ": Default value and value type differ!");
}
} else {
_dataType = dataTypeFromString(nodeType);
}
YAML::Node defNode = node[defaultTypeName];
int nDims = defNode.IsSequence() ? defNode.size() : 1;
_defaultValues.resize(nDims);
for (int i = 0; i < nDims; ++i) {
_defaultValues[i].serializeDefaultValue = true;
YAML::Node dimNode = defNode.IsSequence() ? defNode[i] : defNode;
decodeValueFromNode(dimNode, _defaultValues[i].value, _dataType);
}
return true;
}
示例2: 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);
}
}
示例3: handleRuningStateChangedMsg
void ScServer::handleRuningStateChangedMsg( const QString & data )
{
std::stringstream stream;
stream << data.toStdString();
YAML::Parser parser(stream);
bool serverRunningState;
std::string hostName;
int port;
YAML::Node doc;
while(parser.GetNextDocument(doc)) {
assert(doc.Type() == YAML::NodeType::Sequence);
bool success = doc[0].Read(serverRunningState);
if (!success) return; // LATER: report error?
success = doc[1].Read(hostName);
if (!success) return; // LATER: report error?
success = doc[2].Read(port);
if (!success) return; // LATER: report error?
}
QString qstrHostName( hostName.c_str() );
onRunningStateChanged( serverRunningState, qstrHostName, port );
emit runningStateChange( serverRunningState, qstrHostName, port );
}
示例4: ParseDerivedDimensions
//==============================================================================
/// Parse the derived dimension list from a document.
///
/// \param [in] dim_list The YAML list node for the dimensions.
///
void DefinitionParser::ParseDerivedDimensions( const YAML::Node& dim_list )
{
for ( YAML::Iterator it = dim_list.begin(); it != dim_list.end(); ++it )
{
ParseDerivedDimension( *it );
}
}
示例5: 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;
}
}
示例6: 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");
}
示例7: if
// Incrementally load YAML
static NEVER_INLINE void operator +=(YAML::Node& left, const YAML::Node& node)
{
if (node && !node.IsNull())
{
if (node.IsMap())
{
for (const auto& pair : node)
{
if (pair.first.IsScalar())
{
auto&& lhs = left[pair.first.Scalar()];
lhs += pair.second;
}
else
{
// Exotic case (TODO: probably doesn't work)
auto&& lhs = left[YAML::Clone(pair.first)];
lhs += pair.second;
}
}
}
else if (node.IsScalar() || node.IsSequence())
{
// Scalars and sequences are replaced completely, but this may change in future.
// This logic may be overwritten by custom demands of every specific cfg:: node.
left = node;
}
}
}
示例8: 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;
}
示例9: upgradeYaml
void LootSettings::upgradeYaml(YAML::Node& yaml) {
// Upgrade YAML settings' keys and values from those used in earlier
// versions of LOOT.
if (yaml["Debug Verbosity"] && !yaml["enableDebugLogging"])
yaml["enableDebugLogging"] = yaml["Debug Verbosity"].as<unsigned int>() > 0;
if (yaml["Update Masterlist"] && !yaml["updateMasterlist"])
yaml["updateMasterlist"] = yaml["Update Masterlist"];
if (yaml["Game"] && !yaml["game"])
yaml["game"] = yaml["Game"];
if (yaml["Language"] && !yaml["language"])
yaml["language"] = yaml["Language"];
if (yaml["Last Game"] && !yaml["lastGame"])
yaml["lastGame"] = yaml["Last Game"];
if (yaml["Games"] && !yaml["games"]) {
yaml["games"] = yaml["Games"];
for (auto node : yaml["games"]) {
if (node["url"]) {
node["repo"] = node["url"];
node["branch"] = "master"; // It'll get updated to the correct default
}
}
}
if (yaml["games"]) {
// Handle exception if YAML is invalid, eg. if an unrecognised
// game type is used (which can happen if downgrading from a
// later version of LOOT that supports more game types).
// However, can't remove elements from a sequence Node, so have to
// copy the valid elements into a new node then overwrite the
// original.
YAML::Node validGames;
for (auto node : yaml["games"]) {
try {
GameSettings settings(node.as<GameSettings>());
if (!yaml["Games"]) {
// Update existing default branch, if the default
// repositories are used.
if (settings.RepoURL() == GameSettings(settings.Type()).RepoURL()
&& settings.IsRepoBranchOldDefault()) {
settings.SetRepoBranch(GameSettings(settings.Type()).RepoBranch());
}
}
validGames.push_back(settings);
} catch (...) {}
}
yaml["games"] = validGames;
}
if (yaml["filters"])
yaml["filters"].remove("contentFilter");
}
示例10: groupFromYaml
bool BandwidthGui::groupFromYaml(const std::string& yaml, GroupMap* groupMap)
{
YAML::Node grpInfo = YAML::Load(yaml);
if (grpInfo.IsNull())
{
return true;
}
if (grpInfo.Type() != YAML::NodeType::Map)
{
return false;
}
for (const auto& pair : grpInfo)
{
if(pair.first.Type() != YAML::NodeType::Scalar)
{
return false;
}
std::string key = pair.first.as<std::string>();
for (const auto& element : pair.second)
{
if(element.Type() != YAML::NodeType::Scalar)
{
return false;
}
(*groupMap)[key].push_back(element.as<std::string>());
}
}
return true;
}
示例11: GetYamlDoc
string M3JointArrayClient::GetCompDir(string component)
{
YAML::Node doc;
GetYamlDoc("m3_config.yml",doc);
if(!doc.FindValue("rt_components"))
{
ROS_ERROR("No rt_components key in m3_config.yml.");
return "";
}
for(YAML::Iterator it=doc["rt_components"].begin();it!=doc["rt_components"].end();++it)
{
string dir;
it.first() >> dir;
for(YAML::Iterator it_dir=doc["rt_components"][dir.c_str()].begin();
it_dir!=doc["rt_components"][dir.c_str()].end();++it_dir)
{
string name, type;
it_dir.first() >> name;
it_dir.second() >> type;
if (name == component)
return dir;
}
}
ROS_ERROR("No Robot Found.");
return "";
}
示例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));
}
}
示例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);
}
}
}
示例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));
}
}
}
示例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;
}