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; }
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); }
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); }
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; }
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()); } }