Пример #1
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);
    }
}
Пример #2
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;
}
Пример #3
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]);
        }
    }
}
Пример #4
0
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;
}
Пример #5
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;
}
Пример #6
0
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());
    }
}
Пример #7
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;
    }
}