Esempio n. 1
0
template<typename T> static void writeVar(libconfig::Setting& setting, const char* key, T val) {
    //info("writeVal %s", key);
    const char* sep = strchr(key, '.');
    if (sep) {
        assert(*sep == '.');
        uint32_t plen = (size_t)(sep-key);
        char prefix[plen+1];
        strncpy(prefix, key, plen);
        prefix[plen] = 0;
        // libconfig strdups all passed strings, so it's fine that prefix is local.
        if (!setting.exists(prefix)) {
            try {
                setting.add((const char*)prefix, SType::TypeGroup);
            } catch (libconfig::SettingNameException sne) {
                panic("libconfig error adding group setting %s", prefix);
            }
        }
        libconfig::Setting& child = setting[(const char*)prefix];
        writeVar(child, sep+1, val);
    } else {
        if (!setting.exists(key)) {
            try {
                setting.add(key, getSType<T>()) = val;
            } catch (libconfig::SettingNameException sne) {
                panic("libconfig error adding leaf setting %s", key);
            }
        } else {
            //If this panics, what the hell are you doing in the code? Multiple reads and different defaults??
            T origVal = setting[key];
            if (!getEq(val, origVal)) panic("Duplicate writes to out config key %s with different values!", key);
        }
    }
}
Esempio n. 2
0
bool look(libconfig::Setting& setting,std::string place,ValueType &value)
{
	if (setting.exists(place))
	{
		return setting.lookupValue(place, value);

	}
	else std::cout << setting.getPath() + place << " does not exist. Value remains unchanged." << std::endl;
	return false;
}
Esempio n. 3
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;
}
MillerReciprocalHexIndices readMillerReciprocalHexIndices(const libconfig::Setting& stg)
{
    MillerReciprocalHexIndices index;
	if(stg.isArray() && stg.getLength() == MillerHexIndicesDimension)
	{
			index.H = stg[0];
			index.K = stg[1];
			index.I = stg[2];
			index.L = stg[3];
	}
	else
	{
		throw ProgramSettings::Exception("Check setting: " + toString(stg.getPath()));
	}
	return index;
}
ProgramSettings::EngineSettings::CalculatorType ProgramSettings::defineCalculatorType(const libconfig::Setting& stg)
{
	std::string calculatorType;

	calculatorType = stg.c_str();
	if(calculatorType.compare("LOCAL_DISPLACEMENT") == 0)
	{
		return EngineSettings::calcLDISPL;
	}
	else if (calculatorType.compare("LOCAL_STRAIN") == 0)
	{
		return EngineSettings::calcLSTRAIN;
	} else if (calculatorType.compare("MEAN_STRAIN") == 0)
	{
		return EngineSettings::calcMSTRAIN;
	} else if (calculatorType.compare("COPLANAR_INTENSITY") == 0)
	{
		return EngineSettings::calcCOINTENSITY;
	}else if (calculatorType.compare("COPLANAR_CORRELATION") == 0)
	{
		return EngineSettings::calcCOCORRELATION;
	}
	else
	{
		return EngineSettings::calcUNKNOWN;
	}
}
ProgramSettings::SampleSettings::InterfaceType ProgramSettings::defineInterfaceType(const libconfig::Setting& stg)
{
	std::string interfaceType;

	interfaceType = stg.c_str();
	if (interfaceType.compare("STRAIGHT_GAMMA") == 0)
	{
		return SampleSettings::itfSTRAIGHT_GAMMA;
	}else if(interfaceType.compare("STRAIGHT_GG") == 0)
	{
		return SampleSettings::itfSTRAIGHT_GG;
	}else if(interfaceType.compare("STRAIGHT_GAUSS") == 0)
	{
		return SampleSettings::itfSTRAIGHT_GAUSS;
	}else if(interfaceType.compare("HEXRSH") == 0)
	{
		return SampleSettings::itfHEXRSH;
	}else if(interfaceType.compare("HEXRSO") == 0)
	{
		return SampleSettings::itfHEXRSO;
	}else if(interfaceType.compare("HEXRW") == 0)
	{
		return SampleSettings::itfHEXRW;
	}else if(interfaceType.compare("CONSTFIELD") == 0)
	{
		return SampleSettings::itfCONSTFIELD;
	}else
	{
		return SampleSettings::itfUNKNOWN;
	}
}
Esempio n. 7
0
void initialize_from_array(libconfig::Setting& plugins)
{
    for (int i = 0; i < plugins.getLength(); i++) {
        const char* plugin_path = plugins[i];
        initialize_single_plugin(plugin_path);
    }
}
Esempio n. 8
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;
	}
}
Esempio n. 9
0
void get_value(const libconfig::Setting& root, config_map_type& config_map,
    const std::string& key_name, const T& fallback_value)
{
    T value;

    // libconfig is ANSI/MBCS on Windows - no Unicode support.
    // This reads ANSI/MBCS values from config. If they are UTF-8 (and above
    // the ASCII band) the values will be misinterpreted upon use.
    config_map[key_name] = (root.lookupValue(key_name, value)) ?
        boost::lexical_cast<std::string>(value) :
        boost::lexical_cast<std::string>(fallback_value);
}
Esempio n. 10
0
Sound::Sound(const std::string & _id, libconfig::Setting & _setting) : splashouilleImpl::Object(_id)
{
    type = TYPE_SOUND;
    sound = 0;
    isChunk = false;

    // Fashion and style import
    Object::import(_setting);

    // Get the chunk
    _setting.lookupValue(DEFINITION_CHUNK, isChunk);

    // Get the filename
    if (_setting[DEFINITION_FILENAME].getType() == libconfig::Setting::TypeGroup)
    {
        _setting[DEFINITION_FILENAME].lookupValue(Engine::locale, filename);
    }
    else
    {
        _setting.lookupValue(DEFINITION_FILENAME, filename);
    }
    setFilename(filename, isChunk);
}
Esempio n. 11
0
void SettingUsageRecorder::get_unused(std::vector<std::string> & unused, const libconfig::Setting & aggregate_setting) const{
    int n = aggregate_setting.getLength();
    for(int i=0; i<n; ++i){
        std::string path = aggregate_setting[i].getPath();
        bool a_unused = false;
        if(used_paths.find(path) == used_paths.end()){
            unused.push_back(path);
            a_unused = true;
        }
        //don't descend if already aggregate was reported as unused ...
        if(aggregate_setting[i].isAggregate() && !a_unused){
            get_unused(unused, aggregate_setting[i]);
        }
    }
}
Esempio n. 12
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;
}
Esempio n. 13
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"]);
	}
}
Esempio n. 14
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 + "'.");
}
Esempio n. 15
0
void
Configuration::ConfigFile::showSetting(libconfig::Setting &s, std::string prefix)
{
    unsigned int children = s.getLength();
    Setting::Type t = s.getType();

    switch(t) {
    case Setting::TypeGroup:
        debugOutput(DEBUG_LEVEL_NORMAL, "  %sGroup: %s\n", prefix.c_str(), s.getName());
        for(unsigned int i = 0; i < children; i++) {
            showSetting(s[i], prefix + "  ");
        }
        break;
    case Setting::TypeList:
        debugOutput(DEBUG_LEVEL_NORMAL, "  %sList: %s\n", prefix.c_str(), s.getName());
        for(unsigned int i = 0; i < children; i++) {
            showSetting(s[i], prefix + "  ");
        }
        break;
    case Setting::TypeArray:
        debugOutput(DEBUG_LEVEL_NORMAL, "  %sArray: %s\n", prefix.c_str(), s.getName());
        for(unsigned int i = 0; i < children; i++) {
            showSetting(s[i], prefix + "  ");
        }
        break;
    case Setting::TypeInt:
        {
            int32_t i = s;
            debugOutput(DEBUG_LEVEL_NORMAL,
                        "  %s%s = %d (0x%08X)\n",
                        prefix.c_str(), s.getName(), i, i);
        }
        break;
    case Setting::TypeInt64:
        {
            int64_t i = s;
            debugOutput(DEBUG_LEVEL_NORMAL,
                        "  %s%s = %"PRId64" (0x%016"PRIX64")\n",
                        prefix.c_str(), s.getName(), i, i);
        }
        break;
    case Setting::TypeFloat:
        {
            float f = s;
            debugOutput(DEBUG_LEVEL_NORMAL,
                        "  %s%s = %f\n",
                        prefix.c_str(), s.getName(), f);
        }
        break;
    case Setting::TypeString:
        {
            std::string str = s;
            debugOutput(DEBUG_LEVEL_NORMAL,
                        "  %s%s = %s\n",
                        prefix.c_str(), s.getName(), str.c_str());
        }
        break;
    case Setting::TypeBoolean:
        {
            bool b = s;
            std::string str = (b?"true":"false");
            debugOutput(DEBUG_LEVEL_NORMAL,
                        "  %s%s = %s\n",
                        prefix.c_str(), s.getName(), str.c_str());
        }
        break;
    default:
        {
            debugOutput(DEBUG_LEVEL_NORMAL,
                        "  %s%s = Unsupported Type\n",
                        prefix.c_str(), s.getName());
        }
        break;
    }
}
Esempio n. 16
0
File: ao.cpp Progetto: udoprog/momd
void output_ao::setup(libconfig::Setting& setting)
{
    int channels;
    int rate;
    int bps;
    std::string driver;
    
    if (setting.lookupValue("channels", channels)) {
        setting.remove("channels");
        format.channels = channels;
    }
    else {
        format.channels = DEFAULT_GLOBAL_CHANNELS;
    }
    
    if (setting.lookupValue("rate", rate)) {
        setting.remove("rate");
        format.rate = rate;
    }
    else {
        format.rate = 44100;
    }
    
    if (setting.lookupValue("bps", bps)) {
        setting.remove("bps");
        format.bits = bps;
    }
    else {
        format.bits = 16;
    }
    
    format.byte_format = AO_FMT_LITTLE;
    
    if (setting.lookupValue("driver", driver)) {
        setting.remove("driver");
        driver = ao_driver_id(driver.c_str());
    }
    else {
        driver = ao_default_driver_id();
    }
    
    int length = setting.getLength();

    ao_option *current = NULL;
    
    for (int i = 0; i < length; i++) {
        libconfig::Setting& s = setting[i];

        if (current == NULL) {
            current = new ao_option;
            options = current;
        }
        else {
            current->next = new ao_option;
        }

        std::string key = s.getName();
        std::string value = s;

        current->key = new char[key.size() + 1];
        current->value = new char[value.size() + 1];

        ::strncpy(current->key, key.c_str(), key.size());
        ::strncpy(current->value, value.c_str(), value.size());
    }
}
Esempio n. 17
0
//Static function
static void _remove_if_exists(libconfig::Setting &setting,
			      const std::string& alias)
{
  if(setting.exists(alias))
    setting.remove(alias);
}
Esempio n. 18
0
void ScanHdf5Op::init(libconfig::Config& root, libconfig::Setting& cfg)
{
    ZeroInputOp::init(root, cfg);

    filename = (const char*) root.getRoot()["path"];
    filename += "/";
    filename += (const char*) cfg["file"];

    // Remember partition id and total partitions.
    //
    int pid = 0;
    cfg.lookupValue("thispartition", pid);
    int ptotal = 1;
    cfg.lookupValue("totalpartitions", ptotal);

    assert(ptotal > 0);
    assert(pid < ptotal);
    thispartition = pid;
    totalpartitions = ptotal;

    // Store dataset names.
    //
    libconfig::Setting& grp = cfg["pick"];
    unsigned int size = grp.getLength();

    for (unsigned int i=0; i<size; ++i)
    {
        string n = grp[i];
        datasetnames.push_back(n);
    }

    // Open file, open datasets.
    //
    hdf5file = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
    for (unsigned int i=0; i<size; ++i)
    {
        hdf5sets.push_back(H5Dopen2(hdf5file, datasetnames[i].c_str(), H5P_DEFAULT));
        hdf5space.push_back(H5Dget_space(hdf5sets[i]));
    }

    // Create schema from datasets, and check that types are supported.
    //
    for (unsigned int i=0; i<size; ++i)
    {
        appendFromDataset(hdf5sets[i], schema);
    }

    // Assert all datasets are vectors, not arrays.
    //
    hid_t space;
    for (unsigned int i=0; i<size; ++i)
    {
        space = H5Dget_space(hdf5sets[i]);
        assert(H5Sget_simple_extent_ndims(space) == 1);
        H5Sclose(space);
    }

    // Assert all datasets have same length.
    // Remember data size.
    //
    hsize_t length;

    assert(size != 0);
    space = H5Dget_space(hdf5sets[0]);
    H5Sget_simple_extent_dims(space, &length, NULL);
    H5Sclose(space);

    totaltuples = length;
    for (unsigned int i=1; i<size; ++i)
    {
        space = H5Dget_space(hdf5sets[i]);
        H5Sget_simple_extent_dims(space, &length, NULL);
        H5Sclose(space);
        assert(totaltuples == length);
    }

    assert(hdf5sets.size() == hdf5space.size());

    sizeintup = buffsize/schema.getTupleSize();
    memspace = H5Screate_simple(1, &sizeintup, NULL);

    // Specify totaltuples for requested partition.
    //
    unsigned long long step = totaltuples/totalpartitions;
    assert(totaltuples >= totalpartitions);
    origoffset = step * thispartition;
    totaltuples = ( thispartition == (totalpartitions - 1) )
                  ? totaltuples - origoffset
                  : step;
}
Esempio n. 19
0
void SettingUsageRecorder::markAsUsed(const libconfig::Setting & s){
    used_paths.insert(s.getPath());
}
Esempio n. 20
0
SettingWrapper::SettingWrapper(const libconfig::Setting & s, const libconfig::Setting & root,
                             const boost::shared_ptr<SettingUsageRecorder> & recorder):
           rootsetting(root), rec(recorder), setting(resolve_link(s, rootsetting, rec)), setting_name("<noname>"){
    const char * name = s.getName();
    if(name) setting_name = name;
}