本文整理汇总了C++中yaml::Node::IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::IsDefined方法的具体用法?C++ Node::IsDefined怎么用?C++ Node::IsDefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml::Node
的用法示例。
在下文中一共展示了Node::IsDefined方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: get
bool YamlPath::get(YAML::Node root, YAML::Node& out) {
size_t beginToken = 0, endToken = 0, pathSize = codedPath.size();
auto delimiter = MAP_DELIM; // First token must be a map key.
while (endToken < pathSize) {
if (!root.IsDefined()) {
return false; // A node before the end of the path was mising, quit!
}
beginToken = endToken;
endToken = pathSize;
endToken = std::min(endToken, codedPath.find(SEQ_DELIM, beginToken));
endToken = std::min(endToken, codedPath.find(MAP_DELIM, beginToken));
if (delimiter == SEQ_DELIM) {
int index = std::stoi(&codedPath[beginToken]);
if (root.IsSequence()) {
root.reset(root[index]);
} else {
return false;
}
} else if (delimiter == MAP_DELIM) {
auto key = codedPath.substr(beginToken, endToken - beginToken);
if (root.IsMap()) {
root.reset(root[key]);
} else {
return false;
}
} else {
return false; // Path is malformed, return null node.
}
delimiter = codedPath[endToken]; // Get next character as the delimiter.
++endToken; // Move past the delimiter.
}
// Success! Assign the result.
out.reset(root);
return true;
}
示例4: 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;
}
示例5: 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());
}
}
示例6: yaml_get_node
int yaml_get_node(const config_t &config,
const std::string &key,
const bool optional,
YAML::Node &node) {
ASSERT(config.ok == true, "Config file is not loaded!");
// Recurse down config key
std::vector<YAML::Node> traversal;
traversal.push_back(config.root);
std::istringstream iss(key);
std::string element;
while (std::getline(iss, element, '.')) {
traversal.push_back(traversal.back()[element]);
}
node = traversal.back();
// Note:
//
// yaml_node = yaml_node["some_level_deeper"];
//
// YAML::Node is mutable, by doing the above it destroys the parsed yaml
// tree/graph, to avoid this problem we store the visited YAML::Node into
// a std::vector and return the last visited YAML::Node
// Check key
if (node.IsDefined() == false && optional == false) {
mexErrMsgIdAndTxt("prototype:error",
"Opps [%s] missing in yaml file [%s]!",
key.c_str(),
config.file_path.c_str());
return -1;
} else if (node.IsDefined() == false && optional == true) {
return -1;
}
return 0;
}
示例7: loadNodes
void GraphIO::loadNodes(const YAML::Node& doc, SemanticVersion version)
{
TimerPtr timer = getProfiler()->getTimer("load graph");
YAML::Node nodes = doc["nodes"];
if (nodes.IsDefined()) {
for (std::size_t i = 0, total = nodes.size(); i < total; ++i) {
const YAML::Node& n = nodes[i];
auto interlude = timer->step(n["uuid"].as<std::string>());
loadNode(n, version);
}
}
}
示例8: TableRow
TableRow::TableRow( YAML::Node config )
{
this->readRequiredEntry<std::string>( table, config["table"], "rows::table" );
this->readEntry<bool>( recycleRows, config["recycleRows"], false );
this->readEntry<callback>( callbackPreUpdate, config["callbackPreUpdate"], "~" );
this->readEntry<callback>( callbackPostUpdate, config["callbackPostUpdate"], "~" );
this->readEntry<callback>( callbackPreInsert, config["callbackPreInsert"], "~" );
this->readEntry<callback>( callbackPostInsert, config["callbackPostInsert"], "~" );
this->readEntry<callback>( callbackPreDelete, config["callbackPreDelete"], "~" );
this->readEntry<callback>( callbackPostDelete, config["callbackPostDelete"], "~" );
Logger::debug( std::string( "* Table : " ) + table + "\n" +
"- Recyclage de rows : " + ( recycleRows ? "Oui" : "Non" ) + "\n" +
"- Callback update : " + callbackPreUpdate + " / " + callbackPostUpdate + "\n" +
"- Callback insert : " + callbackPreInsert + " / " + callbackPostInsert + "\n" +
"- Callback delete : " + callbackPreDelete + " / " + callbackPostDelete + "\n" +
"- Champs : \n"
);
YAML::Node fields = config["fields"];
for( uint i = 0; i < fields.size(); i++ )
{
this->fields.push_back( TableRow_Col( fields[i] ) );
}
Logger::debug( "\n" );
YAML::Node subrows = config["subRows"];
if( subrows.IsDefined() && !subrows.IsNull() )
{
for( uint i = 0; i < subrows.size(); i++ )
{
this->subRows.push_back( TableRow( subrows[i] ) );
}
}
}
示例9: infostream
YAMLDatabase(ConfigNode dbeconfig, doid_t min_id, doid_t max_id) :
DatabaseBackend(dbeconfig, min_id, max_id),
m_next_id(min_id),
m_free_ids(),
m_foldername(foldername.get_rval(m_config))
{
stringstream log_name;
log_name << "Database-YAML" << "(Range: [" << min_id << ", " << max_id << "])";
m_log = new LogCategory("yamldb", log_name.str());
// Open database info file
ifstream infostream(m_foldername + "/info.yaml");
YAML::Node document = YAML::Load(infostream);
if(document.IsDefined() && !document.IsNull())
{
// Read next available id
YAML::Node key_next = document["next"];
if(key_next.IsDefined() && !key_next.IsNull())
{
m_next_id = document["next"].as<doid_t>();
}
// Read available freed ids
YAML::Node key_free = document["free"];
if(key_free.IsDefined() && !key_free.IsNull())
{
for(doid_t i = 0; i < key_free.size(); i++)
{
m_free_ids.push_back(key_free[i].as<doid_t>());
}
}
}
// Close database info file
infostream.close();
}
示例10: 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;
}
示例11:
parameters (YAML::Node& node, std::string i_path = "") {
YAML::Node::operator= (node);
path = i_path;
defined = node.IsDefined ();
}
示例12:
static bool
hasValue( const YAML::Node& v )
{
return v.IsDefined() && !v.IsNull();
}