本文整理汇总了C++中yaml::Node::IsNull方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::IsNull方法的具体用法?C++ Node::IsNull怎么用?C++ Node::IsNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml::Node
的用法示例。
在下文中一共展示了Node::IsNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: getNode
virtual Node* getNode(const char* key) {
std::string path = key;
YAML::Node result;
for(size_t i = 0; i < entries.size(); i++) {
YAML::Node node = entries[i];
size_t pos = 0;
while(pos < path.size()) {
std::string subpath;
size_t end = path.find('.', pos);
if(end == std::string::npos) {
subpath = path.substr(pos);
pos = path.size();
} else {
subpath = path.substr(pos, end - pos);
pos = end + 1;
}
if(!node.IsNull()) {
node.reset(node[subpath]);
}
}
if(!node.IsNull() && node.IsDefined()) {
return new NodeImpl(node);
}
}
return NULL;
}
示例3: ResetNode
TEST ResetNode()
{
YAML::Node node = YAML::Load("[1, 2, 3]");
YAML_ASSERT(!node.IsNull());
YAML::Node other = node;
node.reset();
YAML_ASSERT(node.IsNull());
YAML_ASSERT(!other.IsNull());
node.reset(other);
YAML_ASSERT(!node.IsNull());
YAML_ASSERT(other == node);
return true;
}
示例4: configFile
void
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
{
foreach ( const QString& path, moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName ) )
{
QFile configFile( path );
if ( configFile.exists() && configFile.open( QFile::ReadOnly | QFile::Text ) )
{
QByteArray ba = configFile.readAll();
YAML::Node doc = YAML::Load( ba.constData() );
if ( doc.IsNull() )
{
cDebug() << "Found empty module configuration" << path;
// Special case: empty config files are valid,
// but aren't a map.
return;
}
if ( !doc.IsMap() )
{
cWarning() << "Bad module configuration format" << path;
return;
}
cDebug() << "Loaded module configuration" << path;
m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ).toMap();
m_emergency = m_maybe_emergency
&& m_configurationMap.contains( EMERGENCY )
&& m_configurationMap[ EMERGENCY ].toBool();
return;
}
}
示例5: get_field
bool get_field(doid_t do_id, const Field* field, val_t &value)
{
m_log->trace() << "Getting field 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
YAML::Node node = document["fields"][field->get_name()];
if(!node.IsDefined() || node.IsNull())
{
return false;
}
m_log->trace() << "Found requested field: " + field->get_name() << endl;
value = read_yaml_field(field, node, do_id);
if(value.size() > 0)
{
return true;
}
return false;
}
示例6: load
inline bool load(doid_t do_id, YAML::Node &document)
{
ifstream stream(filename(do_id));
document = YAML::Load(stream);
if(!document.IsDefined() || document.IsNull())
{
m_log->error() << "obj-" << do_id << " does not exist in database." << endl;
return false;
}
if(!document["class"].IsDefined() || document["class"].IsNull())
{
m_log->error() << filename(do_id) << " does not contain the 'class' key." << endl;
return false;
}
if(!document["fields"].IsDefined() || document["fields"].IsNull())
{
m_log->error() << filename(do_id) << " does not contain the 'fields' key." << endl;
return false;
}
// Read object's DistributedClass
string dc_name = document["class"].as<string>();
if(!g_dcf->get_class_by_name(dc_name))
{
m_log->error() << "Class '" << dc_name << "', loaded from '" << filename(do_id)
<< "', does not exist." << endl;
return false;
}
return true;
}
示例7: 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;
}
示例8:
boost::optional<T> from_yaml(type_t<boost::optional<T>>,
const YAML::Node& value)
{
if (!value || value.IsNull())
return {};
return yaml::deserialize<T>(value);
}
示例9: loadPluginsConfig
bool loadPluginsConfig (YAML::Node & y_root, PluginsConfig & config)
{
try
{
if (y_root.IsNull())
return false;
YAML::Node y_cfg = y_root["Plugins"]; // @TODO: unicode? utf8?
if (y_cfg)
{
int const n = y_cfg.size();
//YAML::NodeType::value cst = y_tasks.Type();
for (int i = 0; i < n; ++i)
{
YAML::Node y_cfg_i = y_cfg[i];
bb::PluginConfig cfg = y_cfg[i].as<bb::PluginConfig>();
config.m_plugins.push_back(cfg);
}
return true;
}
}
catch (std::exception & e)
{
return false;
}
return false;
}
示例10: 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;
}
}
}
示例11: parseFile
virtual void parseFile(const char* path, const char* key) {
try {
YAML::Node part = YAML::LoadFile(path)[key];
if(!part.IsNull() && part.IsDefined())
entries.push_back(part);
} catch(std::exception& e) {
throw exception(e.what());
}
}
示例12: generate_from_yaml
param_tree param_tree::generate_from_yaml(YAML::Node const& yaml)
{
if(yaml.IsNull())
{
return param_tree{};
}
param_tree pt;
auto root = pt.m_tree.create_root().first;
pt.generate_from_yaml(yaml, root);
return pt;
}
示例13: get
T get(const std::string& path, const T& fallback = T()) {
for(size_t i = 0; i < entries.size(); i++) {
YAML::Node node = entries[i];
size_t pos = 0;
while(pos < path.size()) {
std::string subpath;
size_t end = path.find('.', pos);
if(end == std::string::npos) {
subpath = path.substr(pos);
pos = path.size();
} else {
subpath = path.substr(pos, end - pos);
pos = end + 1;
}
if(!node.IsNull()) {
node.reset(node[subpath]);
}
}
if(!node.IsNull() && node.IsDefined()) {
return node.as<T>();
}
}
return fallback;
}
示例14: CopyYaml
void CopyYaml( const YAML::Node& src, YAML::Node& dst )
{
if( src.IsNull() ) { return; }
if( src.IsScalar() )
{
dst = src;
return;
};
YAML::Node::const_iterator iter;
for( iter = src.begin(); iter != src.end(); iter++ )
{
dst[ iter->first.as<std::string>() ] = iter->second;
}
}
示例15: resolver
ClientAgent::ClientAgent(RoleConfig roleconfig) : Role(roleconfig), m_acceptor(NULL),
m_client_type(client_type.get_rval(roleconfig)),
m_server_version(server_version.get_rval(roleconfig)),
m_ct(min_channel.get_rval(roleconfig), max_channel.get_rval(roleconfig))
{
std::stringstream ss;
ss << "Client Agent (" << bind_addr.get_rval(roleconfig) << ")";
m_log = new LogCategory("clientagent", ss.str());
//Initialize the network
std::string str_ip = bind_addr.get_rval(m_roleconfig);
std::string str_port = str_ip.substr(str_ip.find(':', 0) + 1, std::string::npos);
str_ip = str_ip.substr(0, str_ip.find(':', 0));
tcp::resolver resolver(io_service);
tcp::resolver::query query(str_ip, str_port);
tcp::resolver::iterator it = resolver.resolve(query);
m_acceptor = new tcp::acceptor(io_service, *it, true);
if(g_uberdogs.empty())
{
YAML::Node udnodes = g_config->copy_node()["uberdogs"];
if(!udnodes.IsNull())
{
for(auto it = udnodes.begin(); it != udnodes.end(); ++it)
{
YAML::Node udnode = *it;
Uberdog ud;
ud.dcc = g_dcf->get_class_by_name(udnode["class"].as<std::string>());
if(!ud.dcc)
{
m_log->fatal() << "DCClass " << udnode["class"].as<std::string>()
<< "Does not exist!" << std::endl;
exit(1);
}
ud.anonymous = udnode["anonymous"].as<bool>();
g_uberdogs[udnode["id"].as<uint32_t>()] = ud;
}
}
}
start_accept();
}