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


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

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


在下文中一共展示了Node::IsMap方法的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;
}
开发者ID:Humhu,项目名称:argus_utils,代码行数:32,代码来源:YamlUtils.cpp

示例2: 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;
        }
    }
开发者ID:tsimonq2,项目名称:calamares,代码行数:32,代码来源:Module.cpp

示例3: dataTypeFromString

bool
KnobSerialization::checkForValueNode(const YAML::Node& node, const std::string& nodeType)
{

    if (!node[nodeType]) {
        return false;
    }
        // We need to figure out of the knob is multi-view and if multi-dimensional
    YAML::Node valueNode = node[nodeType];

    _dataType = dataTypeFromString(nodeType);

    // If the "Value" is a map, this can be either a multi-view knob or a single-view
    // and single-dimensional knob with animation.
    // Check to find any of the keys of a single dimension map. If we find it, that means
    // this is not the multi-view map and that this is a single-dimensional knob
    if (!valueNode.IsMap()) {
        decodeValueNode("Main", valueNode);
    } else {
        if (valueNode["Curve"] || valueNode["pyMultiExpr"] || valueNode["pyExpr"] || valueNode["exprtk"] || valueNode["N"] || valueNode["T"] ||
            valueNode["K"] || valueNode["D"] || valueNode["V"]) {
            decodeValueNode("Main", valueNode);
        } else {
            // Multi-view
            for (YAML::const_iterator it = valueNode.begin(); it != valueNode.end(); ++it) {
                decodeValueNode(it->first.as<std::string>(), it->second);
            }
        }
    }
    return true;
}
开发者ID:kcotugno,项目名称:Natron,代码行数:31,代码来源:KnobSerialization.cpp

示例4: InvalidNode

void
RotoStrokeItemSerialization::decode(const YAML::Node& node)
{

    if (!node.IsMap()) {
        throw YAML::InvalidNode();
    }
    KnobTableItemSerialization::decode(node);

    if (node["SubStrokes"]) {
        YAML::Node strokesNode = node["SubStrokes"];
        for (std::size_t i = 0; i < strokesNode.size(); ++i) {
            YAML::Node strokeN = strokesNode[i];
            PointCurves p;
            p.x.reset(new CurveSerialization);
            p.y.reset(new CurveSerialization);
            p.pressure.reset(new CurveSerialization);
            p.x->decode(strokeN["x"]);
            p.y->decode(strokeN["y"]);
            p.pressure->decode(strokeN["pressure"]);
            _subStrokes.push_back(p);
        }
    }


}
开发者ID:kcotugno,项目名称:Natron,代码行数:26,代码来源:RotoStrokeItemSerialization.cpp

示例5: 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;
		}
	}
}
开发者ID:Zangetsu38,项目名称:rpcs3,代码行数:30,代码来源:SettingsDialog.cpp

示例6: 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;
}
开发者ID:karimnaaji,项目名称:tangram-es,代码行数:35,代码来源:yamlPath.cpp

示例7: from_yaml

Map from_yaml(type_t<Map>, const YAML::Node& value)
{
    if (!value.IsMap())
        throw deserialize_error{"type must be a map but is " +
                                yaml_type_name(value)};

    Map ret{};

    for (const auto& obj : value)
    {
        try
        {
            ret.emplace(
                yaml::deserialize<typename Map::key_type>(obj.first),
                yaml::deserialize<typename Map::mapped_type>(obj.second));
        }
        catch (deserialize_error& ex)
        {
            std::string msg =
                "error when deserializing field " + obj.first.Scalar();
            ex.add(msg.c_str());
            throw;
        }
    }

    return ret;
}
开发者ID:k0zmo,项目名称:kl,代码行数:27,代码来源:yaml.hpp

示例8: 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

示例9: expandDefaults

YAML::Node expandDefaults(const YAML::Node& node) {
  YAML::Node result = YAML::Clone(node);
  if (node.IsMap() && node["DEFAULT"]) {
    const YAML::Node& default_node = result["DEFAULT"];
    for (auto field = result.begin(); field != result.end(); ++field) {
      std::string fieldname = field->first.as<std::string>();
      if (fieldname != "DEFAULT") {
        result[fieldname] = applyDefaults(result[fieldname], default_node);
      }
    }
  }
  if (result.IsMap() || result.IsSequence()) {
    for (auto child = result.begin(); child != result.end(); ++child) {
      std::string child_name = child->first.as<std::string>();
      result[child_name] = expandDefaults(child->second);
    }
  }
  return result;
}
开发者ID:hsu,项目名称:drake,代码行数:19,代码来源:yamlUtil.cpp

示例10: parseCommand

void Config::parseCommand(const YAML::Node& node, iCommandConfig& config)
{
	//std::cerr << "Under active development!" << '\n';
	//return;
	if(node.size() >= 1 && node.IsMap())
		for (YAML::const_iterator iter=node.begin();iter!=node.end();++iter) {
			std::string key = iter->first.as<std::string>();
			YAML::Node value = iter->second;
			Util::lowercase(key);
			//std::cout << key << std::endl;
			if(key == "command")
			{
				if(value.IsScalar())
				{
					LOG(logger, DEBUG, "Proc: %s", value.as<std::string>().c_str());
					config.command = Util::parseCommand(value.as<std::string>());
#if 0
					// TODO: We need to take quotes from the user and send them all as
					// a single argument instead of multiple arguments.
					std::string cnfval = value.as<std::string>();
					char* cmd = new char[cnfval.size() + 1];
					cmd[cnfval.size()] = 0;
					memcpy(cmd, cnfval.c_str(), cnfval.size());
					size_t size = 1;
					for(size_t i=0; i<cnfval.size(); i++)
						if(cmd[i] == ' ')
							size++;
					config.command = new char*[size+1];
					config.command[size] = 0;
					config.command[0] = cmd;
					size_t csize = 0;
					for(size_t i=0; i<cnfval.size(); i++)
					{
						if(cmd[i] == ' ')
						{
							cmd[i] = 0;
							if(csize < size && (i + 1) < cnfval.size())
							{
								config.command[++csize] = cmd+(unsigned int)i+1;
							}
						}
					}
#endif
				}
			}
			else if( key == "enabled" ) {
				config.enabled = value.as<bool>();
			}
		}
	//for(size_t i=0;config.command[i]; i++)
	//{
	//	std::cout << "==" << config.command[i] << '\n';
	//}
}
开发者ID:frostyfrog,项目名称:Renzoku,代码行数:54,代码来源:config.cpp

示例11: configFile

void
Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
{
    QStringList configFilesByPriority;

    if ( CalamaresUtils::isAppDataDirOverridden() )
    {
        configFilesByPriority.append(
            CalamaresUtils::appDataDir().absoluteFilePath(
                QString( "modules/%1" ).arg( configFileName ) ) );
    }
    else
    {
        if ( Settings::instance()->debugMode() )
        {
            configFilesByPriority.append(
                QDir( QDir::currentPath() ).absoluteFilePath(
                    QString( "src/modules/%1/%2" ).arg( m_name )
                                                  .arg( configFileName ) ) );
        }

        configFilesByPriority.append(
            QString( "/etc/calamares/modules/%1" ).arg( configFileName ) );
        configFilesByPriority.append(
            CalamaresUtils::appDataDir().absoluteFilePath(
                QString( "modules/%2" ).arg( configFileName ) ) );
    }

    foreach ( const QString& path, configFilesByPriority )
    {
        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.IsMap() )
            {
                cLog() << Q_FUNC_INFO << "bad module configuration format"
                         << path;
                return;
            }

            m_configurationMap = CalamaresUtils::yamlMapToVariant( doc ).toMap();
            return;
        }
        else
            continue;
    }
开发者ID:AOSC-Dev,项目名称:calamares,代码行数:49,代码来源:Module.cpp

示例12: tryDecodeInputsMap

static void tryDecodeInputsMap(const YAML::Node& node, const std::string& token, std::map<std::string, std::string>* container)
{
    if (node[token]) {
        YAML::Node inputsNode = node[token];
        if (inputsNode.IsMap()) {
            for (YAML::const_iterator it = inputsNode.begin(); it!=inputsNode.end(); ++it) {
                container->insert(std::make_pair(it->first.as<std::string>(), it->second.as<std::string>()));
            }
        } else {
            // When single input, just use the index as key
            container->insert(std::make_pair("0", inputsNode.as<std::string>()));
        }
    }

}
开发者ID:kcotugno,项目名称:Natron,代码行数:15,代码来源:NodeSerialization.cpp

示例13: fileName

TEST_F(OsgSceneryRepresentationTest, SerializationTests)
{
	std::shared_ptr<SceneryRepresentation> scenery = std::make_shared<OsgSceneryRepresentation>("OsgScenery");

	std::string fileName("OsgSceneryRepresentationTests/Torus.obj");
	scenery->loadModel(fileName);

	YAML::Node node;
	ASSERT_NO_THROW(node = scenery->encode());
	EXPECT_TRUE(node.IsMap());

	std::shared_ptr<SceneryRepresentation> result = std::make_shared<OsgSceneryRepresentation>("OsgScenery");
	ASSERT_NO_THROW(result->decode(node));
	EXPECT_EQ("SurgSim::Graphics::OsgSceneryRepresentation", result->getClassName());
	EXPECT_EQ(fileName, result->getModel()->getFileName());
}
开发者ID:ricortiz,项目名称:opensurgsim,代码行数:16,代码来源:OsgSceneryRepresentationTests.cpp

示例14: applyDefaults

YAML::Node applyDefaults(const YAML::Node& node,
                         const YAML::Node& default_node) {
  YAML::Node result = YAML::Clone(node);
  if (!default_node.IsMap()) {
    std::cerr << default_node << std::endl;
    throw std::runtime_error("map node expected");
  }
  for (auto field = default_node.begin(); field != default_node.end();
       ++field) {
    std::string fieldname = field->first.as<std::string>();
    if (!result[fieldname]) {
      result[fieldname] = YAML::Clone(field->second);
    } else if (field->second.IsMap()) {
      result[fieldname] = applyDefaults(result[fieldname], field->second);
    }
  }
  return result;
}
开发者ID:hsu,项目名称:drake,代码行数:18,代码来源:yamlUtil.cpp

示例15: file

Settings::Settings( const QString& settingsFilePath,
                    bool debugMode,
                    QObject* parent )
    : QObject( parent )
    , m_debug( debugMode )
    , m_doChroot( true )
    , m_promptInstall( false )
    , m_disableCancel( false )
    , m_disableCancelDuringExec( false )
{
    cDebug() << "Using Calamares settings file at" << settingsFilePath;
    QFile file( settingsFilePath );
    if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) )
    {
        QByteArray ba = file.readAll();

        try
        {
            YAML::Node config = YAML::Load( ba.constData() );
            Q_ASSERT( config.IsMap() );

            interpretModulesSearch( debugMode, CalamaresUtils::yamlToStringList( config[ "modules-search" ] ), m_modulesSearchPaths );
            interpretInstances( config[ "instances" ], m_customModuleInstances );
            interpretSequence( config[ "sequence" ], m_modulesSequence );

            m_brandingComponentName = requireString( config, "branding" );
            m_promptInstall = requireBool( config, "prompt-install", false );
            m_doChroot = !requireBool( config, "dont-chroot", false );
            m_isSetupMode = requireBool( config, "oem-setup", !m_doChroot );
            m_disableCancel = requireBool( config, "disable-cancel", false );
            m_disableCancelDuringExec = requireBool( config, "disable-cancel-during-exec", false );
        }
        catch ( YAML::Exception& e )
        {
            CalamaresUtils::explainYamlException( e, ba, file.fileName() );
        }
    }
    else
    {
        cWarning() << "Cannot read settings file" << file.fileName();
    }

    s_instance = this;
}
开发者ID:calamares,项目名称:calamares,代码行数:44,代码来源:Settings.cpp


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