Esempio n. 1
0
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;
}
Esempio n. 2
0
/**
 * 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);
	}
}
Esempio n. 3
0
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 );
}
Esempio n. 4
0
//==============================================================================
/// 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 );
    }
}
Esempio n. 5
0
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;
    }
}
Esempio n. 6
0
/**
  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");

}
Esempio n. 7
0
// 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;
		}
	}
}
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;
}
Esempio n. 9
0
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");
}
Esempio n. 10
0
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;
}
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 "";
}
Esempio n. 12
0
/**
 * 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));
    }
}
Esempio n. 13
0
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);
		}
	}
}
Esempio n. 14
0
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));
		}
	}
}
Esempio n. 15
0
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;
}
Esempio n. 16
0
		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;
		}
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);
        }
    }


}
Esempio n. 18
0
		void set_field(doid_t do_id, const Field* field, const val_t &value)
		{
			m_log->trace() << "Setting field on obj-" << do_id << endl;

			YAML::Node document;
			if(!load(do_id, document))
			{
				return;
			}

			// Get the fields from the file that are not being updated
			const Class* dcc = g_dcf->get_class_by_name(document["class"].as<string>());
			ObjectData dbo(dcc->get_id());
			YAML::Node existing = document["fields"];
			for(auto it = existing.begin(); it != existing.end(); ++it)
			{
				const Field* field = dcc->get_field_by_name(it->first.as<string>());
				if(!field)
				{
					m_log->warning() << "Field '" << it->first.as<string>()
					                 << "', loaded from '" << filename(do_id)
					                 << "', does not exist." << endl;
					continue;
				}
				vector<uint8_t> value = read_yaml_field(field, it->second, do_id);
				if(value.size() > 0)
				{
					dbo.fields[field] = value;
				}
			}

			dbo.fields[field] = value;
			write_yaml_object(do_id, dcc, dbo);
		}
Esempio n. 19
0
 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;
 }
Esempio n. 20
0
		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;
		}
    int GazeboRosPulson::ParseBeaconMapFile(std::string f)
    {
        ROS_INFO("Opening Beacon Map File: %s", f.c_str());

        // open file
        std::fstream fs;
        fs.open(f.c_str());
        if (!fs.is_open())
            return -1;
        YAML::Node map = YAML::LoadFile(f.c_str());
        assert(map.IsSequence());

        num_beacons_ = map.size();

        // read beacon locations
        for (int i = 0; i < num_beacons_; i++)
        {
            Beacon b;
            b.x = (double) map[i]["x"].as<double>();
            b.y = (double) map[i]["y"].as<double>();
            b.z = (double) map[i]["z"].as<double>();
            b.id = (int) map[i]["id"].as<int>();

            ROS_INFO("Beacon %d at : %f %f %f", b.id, b.x, b.y, b.z);

            beacons_.push_back(b);
        }

        // close file
        fs.close();
        return 0;
    }
Esempio n. 22
0
		bool get_fields(doid_t do_id, const vector<const Field*> &fields, map_t &values)
		{
			m_log->trace() << "Getting fields 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
			for(auto it = fields.begin(); it != fields.end(); ++it)
			{
				const Field* field = *it;
				m_log->trace() << "Searching for field: " << field->get_name() << endl;

				YAML::Node existing = document["fields"];
				for(auto it2 = existing.begin(); it2 != existing.end(); ++it2)
				{
					if(it2->first.as<string>() == field->get_name())
					{
						vector<uint8_t> value = read_yaml_field(field, it2->second, do_id);
						if(value.size() > 0)
						{
							values[*it] = value;
							m_log->trace() << "Found requested field: " + field->get_name() << endl;
						}
					}
				}
			}
			return true;
		}
Esempio n. 23
0
//==============================================================================
/// Parse the converted units list from a document.
/// 
/// \param [in] unit_list The list of converted units.
/// 
void DefinitionParser::ParseConvertedUnits( const YAML::Node& unit_list )
{
    for ( YAML::Iterator it = unit_list.begin(); it != unit_list.end(); ++it )
    {
        ParseConvertedUnit( *it );
    }
}
TEST(TransferParticlesToPointCloudBehaviorTests, SerializationTest)
{
	std::shared_ptr<Framework::Component> particles = std::make_shared<Particles::SphRepresentation>("Particles");
	std::shared_ptr<Framework::Component> pointCloud =
		std::make_shared<Graphics::OsgPointCloudRepresentation>("Graphics");

	auto behavior = std::make_shared<TransferParticlesToPointCloudBehavior>("Behavior");

	EXPECT_NO_THROW(behavior->setValue("Source", particles));
	EXPECT_NO_THROW(behavior->setValue("Target", pointCloud));

	YAML::Node node;
	ASSERT_NO_THROW(node = YAML::convert<Framework::Component>::encode(*behavior));
	EXPECT_EQ(1u, node.size());

	YAML::Node data = node["SurgSim::Blocks::TransferParticlesToPointCloudBehavior"];
	EXPECT_EQ(5u, data.size());

	std::shared_ptr<TransferParticlesToPointCloudBehavior> newBehavior;
	std::shared_ptr<Framework::Component> nodeAsComponent = node.as<std::shared_ptr<Framework::Component>>();
	ASSERT_NO_THROW(newBehavior = std::dynamic_pointer_cast<TransferParticlesToPointCloudBehavior>(nodeAsComponent));

	EXPECT_EQ("SurgSim::Blocks::TransferParticlesToPointCloudBehavior", newBehavior->getClassName());
	EXPECT_NE(nullptr, newBehavior->getValue<std::shared_ptr<Particles::Representation>>("Source"));
	EXPECT_NE(nullptr, newBehavior->getValue<std::shared_ptr<Graphics::PointCloudRepresentation>>("Target"));
}
Esempio n. 25
0
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;
    }
}
Esempio n. 26
0
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;
        }
    }
Esempio n. 27
0
void GraphIO::saveFulcrums(YAML::Node& fulcrum, const ConnectionDescription& connection)
{
    fulcrum["from"] = connection.from.getFullName();
    fulcrum["to"] = connection.to.getFullName();

    for (const Fulcrum& f : connection.fulcrums) {
        YAML::Node pt;
        pt.push_back(f.pos().x);
        pt.push_back(f.pos().y);

        fulcrum["pts"].push_back(pt);
    }

    for (const Fulcrum& f : connection.fulcrums) {
        YAML::Node handle;
        handle.push_back(f.handleIn().x);
        handle.push_back(f.handleIn().y);
        handle.push_back(f.handleOut().x);
        handle.push_back(f.handleOut().y);

        fulcrum["handles"].push_back(handle);
    }

    for (const Fulcrum& f : connection.fulcrums) {
        fulcrum["types"].push_back(f.type());
    }
}
Esempio n. 28
0
YAML::Node YamlPath::get(YAML::Node node) {
    size_t beginToken = 0, endToken = 0, pathSize = codedPath.size();
    auto delimiter = MAP_DELIM; // First token must be a map key.
    while (endToken < pathSize) {
        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]);
            node.reset(node[index]);
        } else if (delimiter == MAP_DELIM) {
            auto key = codedPath.substr(beginToken, endToken - beginToken);
            node.reset(node[key]);
        } else {
            return Node(); // Path is malformed, return null node.
        }
        delimiter = codedPath[endToken]; // Get next character as the delimiter.
        ++endToken; // Move past the delimiter.
        if (endToken < pathSize && !node) {
            return Node(); // A node in the path was missing, return null node.
        }
    }
    return node;
}
		bool Bases()
		{
			std::string input =
				"- 15\n"
				"- 0x10\n"
				"- 030\n"
				"- 0xffffffff\n";
			
			std::stringstream stream(input);
			YAML::Parser parser(stream);
			YAML::Node doc;
			
			parser.GetNextDocument(doc);
			if(doc.size() != 4)
				return false;
			if(doc[0] != 15)
				return false;
			if(doc[1] != 0x10)
				return false;
			if(doc[2] != 030)
				return false;
			if(doc[3] != 0xffffffff)
				return false;
			return true;
		}
Esempio n. 30
0
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;
}