Пример #1
0
// Helper function: Compares two settings recursively, checking for inclusion
// Returns number of settings without inclusion (given but unused)
static uint32_t checkIncluded(libconfig::Setting& s1, libconfig::Setting& s2, std::string prefix) {
    uint32_t unused = 0;
    for (uint32_t i = 0; i < (uint32_t)s1.getLength(); i++) {
        const char* name = s1[i].getName();
        if (!s2.exists(name)) {
            warn("Setting %s not used during configuration", (prefix + name).c_str());
            unused++;
        } else if (s1[i].isGroup()) {
            unused += checkIncluded(s1[i], s2[name], prefix + name + ".");
        }
    }
    return unused;
}
Пример #2
0
// Helper function: Add "*"-prefixed vars, which are used by our scripts but not zsim, to outCfg
// Returns number of copied vars
static uint32_t copyNonSimVars(libconfig::Setting& s1, libconfig::Setting& s2, std::string prefix) {
    uint32_t copied = 0;
    for (uint32_t i = 0; i < (uint32_t)s1.getLength(); i++) {
        const char* name = s1[i].getName();
        if (name[0] == '*') {
            if (s2.exists(name)) panic("Setting %s was read, should be private", (prefix + name).c_str());
            // This could be as simple as:
            //s2.add(s1[i].getType()) = s1[i];
            // However, because Setting kinda sucks, we need to go type by type:
            libconfig::Setting& ns = s2.add(name, s1[i].getType());
            if      (libconfig::Setting::Type::TypeInt     == s1[i].getType()) ns = (int) s1[i];
            else if (libconfig::Setting::Type::TypeInt64   == s1[i].getType()) ns = (lc_int64) s1[i];
            else if (libconfig::Setting::Type::TypeBoolean == s1[i].getType()) ns = (bool) s1[i];
            else if (libconfig::Setting::Type::TypeString  == s1[i].getType()) ns = (const char*) s1[i];
            else panic("Unknown type for priv setting %s, cannot copy", (prefix + name).c_str());
            copied++;
        }

        if (s1[i].isGroup() && s2.exists(name)) {
            copied += copyNonSimVars(s1[i], s2[name], prefix + name + ".");
        }
    }
    return copied;
}
Пример #3
0
void ProgramSettings::readLocalDisplacementCalculatorSettings(const libconfig::Setting& stg)
{
	if (stg.exists("input"))
	{
		m_engineSettings.localDisplacementCalculatorSettings->infile = stg["input"].c_str();
	}else
	{
		m_engineSettings.localDisplacementCalculatorSettings->infile = "";
		m_engineSettings.localDisplacementCalculatorSettings->xrange =
				readRange(stg["xrange"]);
		m_engineSettings.localDisplacementCalculatorSettings->yrange =
				readRange(stg["yrange"]);
		m_engineSettings.localDisplacementCalculatorSettings->zrange =
				readRange(stg["zrange"]);
	}
}
Пример #4
0
bool look(libconfig::Setting& current, std::string place ,Vector3& vec,std::string ent)
{
	using namespace libconfig;
	if (current.exists(place))
	{
		Setting& posit = current.lookup(place);
		vec[0] = posit[0];
		vec[1] = posit[1];
		vec[2] = posit[2];
		return true;
	}
	else
	{
		std::cout << place<<" error in " << ent << std::endl;
		return false;
	}
}
Пример #5
0
void sanitycheck(libconfig::Config& cfg, libconfig::Setting& cfgnode, 
		const string& branch)
{
	// Check that a branch with the given name exists under cfgnode.
	//
	if (!cfgnode.exists(branch))
		throw MissingParameterException("Cannot find `" + branch + "' attribute in query subtree.");

	// Check that the child has a name.
	//
	if (!cfgnode[branch].exists("name"))
		throw MissingParameterException("Cannot find `name' attribute in query subtree.");

	// Check that the top-level contains a node of this name.
	//
	string name = cfgnode[branch]["name"];
	if (!cfg.getRoot().exists(name))
		throw MissingParameterException("Cannot find description for node `" + name + "'.");

	// Check that the top-level node of this name names a type.
	//
	if (!cfg.getRoot()[name].exists("type"))
		throw MissingParameterException("Cannot find mandatory `type' parameter in description for node `" + name + "'.");
}
Пример #6
0
//Static function
static void _remove_if_exists(libconfig::Setting &setting,
			      const std::string& alias)
{
  if(setting.exists(alias))
    setting.remove(alias);
}