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


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

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


在下文中一共展示了Node::Type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: toValue

static Value toValue(const YAML::Node& node, NTA_BasicType dataType)
{
    if (node.Type() == YAML::NodeType::Map || node.Type() == YAML::NodeType::Null)
    {
        NTA_THROW << "YAML string does not not represent a value.";
    }
    if (node.Type() == YAML::NodeType::Scalar)
    {
        if (dataType == NTA_BasicType_Byte)
        {
            // node >> *str;
            std::string val;
            node.Read(val);
            boost::shared_ptr<std::string> str(new std::string(val));
            Value v(str);
            return v;
        } else {
            boost::shared_ptr<Scalar> s(new Scalar(dataType));
            _toScalar(node, s);
            Value v(s);
            return v;
        }
    } else {
        // array
        boost::shared_ptr<Array> a(new Array(dataType));
        _toArray(node, a);
        Value v(a);
        return v;
    }
}
开发者ID:h2suzuki,项目名称:nupic.core,代码行数:30,代码来源:YAMLUtils.cpp

示例2: parse_drawable

Drawable parse_drawable(const YAML::Node& node) {
	const char* err =
			"Expected drawable object, of form \n"
					"     type: image -or- animation -or- directional -or- lua \n"
					"     file: <filename>\n"
					"-or- frames: <drawable list or file pattern>\n"
					"         Note: file patterns are of the form filename(min-max).extension\n"
					"-or- function: <lua function>";
	if (node.Type() == YAML::NodeType::Scalar) {
		return Drawable(new Image(parse_str(node)));
	}

	if (node.Type() != YAML::NodeType::Map) {
		throw YAML::RepresentationException(node.GetMark(), err);
	}

	std::string type = parse_optional(node, "type", std::string());

	if ((type.empty() && yaml_has_node(node, "file")) || type == "image") {
		return Drawable(new Image(parse_image(node)));
	} else if (type == "animation") {
		return Drawable(new Animation(parse_animation(node)));
	} else if (type == "directional") {
		return Drawable(new DirectionalDrawable(parse_directional(node)));
	} else if (type == "lua") {
		return Drawable(new LuaDrawable(parse_luadrawable(node)));
	} else {
		throw YAML::RepresentationException(node.GetMark(), err);
	}

}
开发者ID:ludamad,项目名称:lanarts,代码行数:31,代码来源:parse_drawable.cpp

示例3: parseSceneGlobals

JSValue parseSceneGlobals(JSScope& jsScope, const YAML::Node& node) {
    switch(node.Type()) {
    case YAML::NodeType::Scalar: {
        auto& scalar = node.Scalar();
        if (scalar.compare(0, 8, "function") == 0) {
            return pushYamlScalarAsJsFunctionOrString(jsScope, node);
        }
        return pushYamlScalarAsJsPrimitive(jsScope, node);
    }
    case YAML::NodeType::Sequence: {
        auto jsArray = jsScope.newArray();
        for (size_t i = 0; i < node.size(); i++) {
            jsArray.setValueAtIndex(i, parseSceneGlobals(jsScope, node[i]));
        }
        return jsArray;
    }
    case YAML::NodeType::Map: {
        auto jsObject = jsScope.newObject();
        for (const auto& entry : node) {
            if (!entry.first.IsScalar()) {
                continue; // Can't put non-scalar keys in JS objects.
            }
            jsObject.setValueForProperty(entry.first.Scalar(), parseSceneGlobals(jsScope, entry.second));
        }
        return jsObject;
    }
    default:
        return jsScope.newNull();
    }
}
开发者ID:karimnaaji,项目名称:tangram-es,代码行数:30,代码来源:styleContext.cpp

示例4: load

void Property::load( const YAML::Node& yaml_node )
{
  if( yaml_node.Type() == YAML::NodeType::Scalar )
  {
    loadValue( yaml_node );
  }
  else if( yaml_node.Type() == YAML::NodeType::Map )
  {
    loadChildren( yaml_node );
  }
  else
  {
    printf( "Property::load() TODO: error handling - unexpected YAML type (Sequence) at line %d, column %d.\n",
            yaml_node.GetMark().line, yaml_node.GetMark().column );
  }
}
开发者ID:F34140r,项目名称:visualization-userfriendly,代码行数:16,代码来源:property.cpp

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

示例6: 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;
    }
}
开发者ID:jjiezheng,项目名称:ship,代码行数:31,代码来源:file_bundle.cpp

示例7: 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;
 }
开发者ID:egocarib,项目名称:yaml-cpp,代码行数:25,代码来源:nodetests.cpp

示例8: 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;
}
开发者ID:MorS25,项目名称:nimbro_network,代码行数:29,代码来源:bandwidth_gui.cpp

示例9: is

TrackExtractor *loadTEFromDisk (const char *tename) {
    try {
        ifstream is(tename);
        if (is.bad()) {
            is.close();
            cout << "is bad" << endl;
            return defaultTE();
        }

        YAML::Parser parser(is);
        YAML::Node node;
        parser.GetNextDocument(node);
     //   std::cout << "parsed\n";
        if (node.Type() != YAML::NodeType::Map) {
            cout << "failed to parse " << tename << "node is not a map " <<endl;
            return defaultTE();
        }
        if (node.FindValue("max maggot contour angle")) { //it's a maggot
            MaggotTrackExtractor *mte = new MaggotTrackExtractor;
      //      cout << "it's a maggot" << endl;
            mte->fromYAML(node);
            return mte;
        } else {
    //        cout << "basic track extractor" << endl;
            TrackExtractor *te = new TrackExtractor;
            te->fromYAML(node);
            return te;
        }

    } catch (YAML::ParserException &e) {
        std::cout << "Parser Error " << e.what() << "\n";
        return defaultTE();
    }
   
}
开发者ID:samuellab,项目名称:MAGATAnalyzer-Track-Extraction,代码行数:35,代码来源:main.cpp

示例10: parseConfigItemFromYamlNode

 static ConfigItem parseConfigItemFromYamlNode(const YAML::Node &n) {
   ConfigItem item;
   if(n.Type() == YAML::NodeType::Scalar) {
     std::string s;
     n.GetScalar(s);
     item.setUnparsedString(s);
   }
   return item;
 }
开发者ID:bergatt,项目名称:mars,代码行数:9,代码来源:ConfigData.cpp

示例11: parseSceneGlobals

void StyleContext::parseSceneGlobals(const YAML::Node& node, const std::string& key, int seqIndex,
                                     duk_idx_t dukObject) {

    switch(node.Type()) {
        case YAML::NodeType::Scalar:
            if (key.size() == 0) {
                duk_push_string(m_ctx, node.Scalar().c_str());
                duk_put_prop_index(m_ctx, dukObject, seqIndex);
            } else {
                auto nodeValue = node.Scalar();
                if (nodeValue.compare(0, 8, "function") == 0) {
                    duk_push_string(m_ctx, key.c_str()); // push property key
                    duk_push_string(m_ctx, nodeValue.c_str()); // push function string
                    duk_push_string(m_ctx, "");
                    if (duk_pcompile(m_ctx, DUK_COMPILE_FUNCTION) == 0) { // compile function
                        duk_put_prop(m_ctx, -3); // put {key: function()}
                    } else {
                        LOGW("Compile failed in global function: %s\n%s\n---",
                             duk_safe_to_string(m_ctx, -1),
                             nodeValue.c_str());
                        duk_pop(m_ctx); //pop error
                        duk_pop(m_ctx); //pop key
                        // push property as a string
                        duk_push_string(m_ctx, nodeValue.c_str());
                        duk_put_prop_string(m_ctx, dukObject, key.c_str());
                    }
                } else {
                    duk_push_string(m_ctx, nodeValue.c_str());
                    duk_put_prop_string(m_ctx, dukObject, key.c_str());
                }
            }
            break;
        case YAML::NodeType::Sequence:
            {
                auto seqObj = duk_push_array(m_ctx);
                for (int i = 0; i < node.size(); i++) {
                    parseSceneGlobals(node[i], "", i, seqObj);
                }
                duk_put_prop_string(m_ctx, seqObj-1, key.c_str());
                break;
            }
        case YAML::NodeType::Map:
            {
                //duk_push_string(m_ctx, key.c_str());
                auto mapObj = duk_push_object(m_ctx);
                for (auto& mapNode : node) {
                    auto itemKey = mapNode.first.Scalar();
                    parseSceneGlobals(mapNode.second, itemKey, 0, mapObj);
                }
                duk_put_prop_string(m_ctx, mapObj-1, key.c_str());
            }
        default:
            break;
    }

    return;
}
开发者ID:NabilNoaman,项目名称:tangram-es,代码行数:57,代码来源:styleContext.cpp

示例12: CloneMap

 TEST CloneMap()
 {
     YAML::Node node = YAML::Load("{foo: bar}");
     YAML::Node clone = Clone(node);
     YAML_ASSERT(!(node == clone));
     YAML_ASSERT(clone.Type() == YAML::NodeType::Map);
     YAML_ASSERT(node.size() == clone.size());
     YAML_ASSERT(node["foo"].as<std::string>() == clone["foo"].as<std::string>());
     return true;
 }
开发者ID:egocarib,项目名称:yaml-cpp,代码行数:10,代码来源:nodetests.cpp

示例13: ParseConversions

//==============================================================================
/// Parse the conversion expression and store it in the unit.
/// 
/// \param [in] node The node with the expression.
/// \param [in] unit_p The unit to set up/
/// 
void DefinitionParser::ParseConversions( const YAML::Node& node, Unit *unit_p )
{
    if ( node.Type() == YAML::NodeType::Scalar )
    {
        double value;
        node >> value;

        unit_p->SetToBase( Conversion::ScaleFactor( value ) );
        unit_p->SetFromBase( Conversion::ScaleFactor( 1.0 / value ) );
    }
开发者ID:Fifty-Nine,项目名称:AutoUnits,代码行数:16,代码来源:DefinitionParser.cpp

示例14: CloneAlias

 TEST CloneAlias()
 {
     YAML::Node node = YAML::Load("&foo [*foo]");
     YAML::Node clone = Clone(node);
     YAML_ASSERT(!(node == clone));
     YAML_ASSERT(clone.Type() == YAML::NodeType::Sequence);
     YAML_ASSERT(node.size() == clone.size());
     YAML_ASSERT(clone == clone[0]);
     return true;
 }
开发者ID:egocarib,项目名称:yaml-cpp,代码行数:10,代码来源:nodetests.cpp

示例15: CloneSeq

 TEST CloneSeq()
 {
     YAML::Node node = YAML::Load("[1, 3, 5, 7]");
     YAML::Node clone = Clone(node);
     YAML_ASSERT(!(node == clone));
     YAML_ASSERT(clone.Type() == YAML::NodeType::Sequence);
     YAML_ASSERT(node.size() == clone.size());
     for(std::size_t i=0;i<node.size();i++)
         YAML_ASSERT(node[i].as<int>() == clone[i].as<int>());
     return true;
 }
开发者ID:egocarib,项目名称:yaml-cpp,代码行数:11,代码来源:nodetests.cpp


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