Files
HPPA/HPPA/hppaConfigFile.cpp
tangchao0503 c1e4144ed6 add
支持corning 410,并添加配置文件
2025-05-09 17:27:04 +08:00

925 lines
25 KiB
C++
Raw Blame History

//
// Created by tangchao on 2023/3/25.
//
#include "hppaConfigFile.h"
Configfile::Configfile()
{
}
void Configfile::setConfigfilePath(string configfilePath)
{
m_configfilePath = configfilePath;
}
bool Configfile::isConfigfileExist()
{
QFileInfo info(QString::fromStdString(m_configfilePath));
return info.exists();
}
bool Configfile::parseConfigfile()
{
// Read the file. If there is an error, report it and exit.
try
{
cfg.readFile(m_configfilePath);
return true;
}
catch(const FileIOException &fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return false;
}
catch(const ParseException &pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return false;
}
}
bool Configfile::getPositionRestriction(int& max, int& min)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& autoFocus = root["autoFocus"];
int count = autoFocus.getLength();
const Setting& positionRestriction = autoFocus["PositionRestriction"];
string name = positionRestriction.getName();
if (!(positionRestriction.lookupValue("max", max)
&& positionRestriction.lookupValue("min", min)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getTuningStepSize(int& coarse, int& fine)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& autoFocus = root["autoFocus"];
int count = autoFocus.getLength();
const Setting& TuningStepSize = autoFocus["TuningStepSize"];
string name = TuningStepSize.getName();
if (!(TuningStepSize.lookupValue("coarse", coarse)
&& TuningStepSize.lookupValue("fine", fine)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getFitParams(float& fa, float& fb)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& autoFocus = root["autoFocus"];
int count = autoFocus.getLength();
const Setting& FitParams = autoFocus["FitParams"];
string name = FitParams.getName();
if (!(FitParams.lookupValue("fa", fa)
&& FitParams.lookupValue("fb", fb)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getAutoFocusRange(int& max, int& min)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& autoFocus = root["autoFocus"];
int count = autoFocus.getLength();
const Setting& AutoFocusRange = autoFocus["AutoFocusRange"];
string name = AutoFocusRange.getName();
if (!(AutoFocusRange.lookupValue("max", max)
&& AutoFocusRange.lookupValue("min", min)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getXMotorParm(float& StepAnglemar, float& Lead, int& SubdivisionMultiples, float& ScaleFactor, float& MaxRange)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& motionPlatform = root["motionPlatform"];
int count = motionPlatform.getLength();
const Setting& x = motionPlatform["x"];
string name = x.getName();
if (!(x.lookupValue("StepAnglemar", StepAnglemar)
&& x.lookupValue("Lead", Lead) && x.lookupValue("SubdivisionMultiples", SubdivisionMultiples)
&& x.lookupValue("ScaleFactor", ScaleFactor)
&& x.lookupValue("MaxRange", MaxRange)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getYMotorParm(float& StepAnglemar, float& Lead, int& SubdivisionMultiples, float& ScaleFactor, float& MaxRange)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& motionPlatform = root["motionPlatform"];
int count = motionPlatform.getLength();
const Setting& y = motionPlatform["y"];
string name = y.getName();
if (!(y.lookupValue("StepAnglemar", StepAnglemar)
&& y.lookupValue("Lead", Lead) && y.lookupValue("SubdivisionMultiples", SubdivisionMultiples)
&& y.lookupValue("ScaleFactor", ScaleFactor)
&& y.lookupValue("MaxRange", MaxRange)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::setMaxRange(float maxRange, QString x_y)
{
const Setting& root = cfg.getRoot();
try
{
Setting& _maxRange = root["motionPlatform"][x_y.toStdString()]["MaxRange"];
_maxRange = maxRange;
writeConfig2File();
return true;
}
catch (const SettingNotFoundException& nfex)
{
cerr << "No 'MaxRange' setting in configuration file." << endl;
return false;
}
}
bool Configfile::writeConfig2File()
{
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
// cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch (const FileIOException& fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return false;
}
return true;
}
bool Configfile::getSN(string &SN)
{
try
{
std::string SN_tem = cfg.lookup("SN");
SN = SN_tem;
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool Configfile::createConfigFile()
{
using namespace std;
using namespace libconfig;
Config cfg;
Setting &root = cfg.getRoot();
// Add some settings to the configuration.
Setting &SN = root.add("SN", Setting::TypeString) = "2004";
//autoFocus
Setting & autoFocus = root.add("autoFocus", Setting::TypeGroup);
Setting & PositionRestriction = autoFocus.add("PositionRestriction", Setting::TypeGroup);
Setting& TuningStepSize = autoFocus.add("TuningStepSize", Setting::TypeGroup);
Setting& FitParams = autoFocus.add("FitParams", Setting::TypeGroup);
Setting& AutoFocusRange = autoFocus.add("AutoFocusRange", Setting::TypeGroup);
Setting & PositionRestriction_max = PositionRestriction.add("max", Setting::TypeInt) = 1000;
Setting & PositionRestriction_min = PositionRestriction.add("min", Setting::TypeInt) = 120;
Setting& TuningStepSize_coarse = TuningStepSize.add("coarse", Setting::TypeInt) = 10;
Setting& TuningStepSize_fine = TuningStepSize.add("fine", Setting::TypeInt) = 2;
Setting& FitParams_fa = FitParams.add("fa", Setting::TypeFloat) = 0.0017;
Setting& FitParams_fb = FitParams.add("fb", Setting::TypeFloat) = 0.3277;
Setting& AutoFocusRange_max = AutoFocusRange.add("max", Setting::TypeInt) = 688;
Setting& AutoFocusRange_min = AutoFocusRange.add("min", Setting::TypeInt) = 144;
//motionPlatform
Setting& motionPlatform = root.add("motionPlatform", Setting::TypeGroup);
Setting& x = motionPlatform.add("x", Setting::TypeGroup);
Setting& y = motionPlatform.add("y", Setting::TypeGroup);
Setting& x_StepAnglemar = x.add("StepAnglemar", Setting::TypeFloat) = 1.8;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Setting& x_Lead = x.add("Lead", Setting::TypeFloat) = 13.5;//<2F><><EFBFBD>̣<EFBFBD><CCA3><EFBFBD>λ<EFBFBD><CEBB>cm
Setting& x_SubdivisionMultiples = x.add("SubdivisionMultiples", Setting::TypeInt) = 7;//ϸ<>ֱ<EFBFBD><D6B1><EFBFBD>
Setting& x_ScaleFactor = x.add("ScaleFactor", Setting::TypeFloat) = 1.0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Setting& x_MaxRange = x.add("MaxRange", Setting::TypeFloat) = 120.0;
Setting& y_StepAnglemar = y.add("StepAnglemar", Setting::TypeFloat) = 1.8;
Setting& y_Lead = y.add("Lead", Setting::TypeFloat) = 13.5;
Setting& y_SubdivisionMultiples = y.add("SubdivisionMultiples", Setting::TypeInt) = 7;
Setting& y_ScaleFactor = y.add("ScaleFactor", Setting::TypeFloat) = 0.2;
Setting& y_MaxRange = y.add("MaxRange", Setting::TypeFloat) = 120.0;
// Write out the new configuration.
try
{
cfg.writeFile(m_configfilePath.c_str());
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return true;
}
return true;
}
bool Configfile::updateConfigFile()
{
using namespace std;
using namespace libconfig;
static const char *output_file = "updated.cfg";
Config cfg;
cfg.setOptions(Config::OptionFsync
| Config::OptionSemicolonSeparators
| Config::OptionColonAssignmentForGroups
| Config::OptionOpenBraceOnSeparateLine);
// Read the file. If there is an error, report it and exit.
try
{
cfg.readFile("example.cfg");
}
catch(const FileIOException &fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return false;
}
catch(const ParseException &pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return false;
}
// Find the 'movies' setting. Add intermediate settings if they don't yet
// exist.
Setting &root = cfg.getRoot();
if(! root.exists("inventory"))
root.add("inventory", Setting::TypeGroup);
Setting &inventory = root["inventory"];
if(! inventory.exists("movies"))
inventory.add("movies", Setting::TypeList);
Setting &movies = inventory["movies"];
// Create the new movie entry.
Setting &movie = movies.add(Setting::TypeGroup);
movie.add("title", Setting::TypeString) = "Buckaroo Banzai";
movie.add("media", Setting::TypeString) = "DVD";
movie.add("price", Setting::TypeFloat) = 12.99;
movie.add("qty", Setting::TypeInt) = 20;
// Write out the updated configuration.
try
{
cfg.writeFile(output_file);
cerr << "Updated configuration successfully written to: " << output_file
<< endl;
}
catch(const FileIOException &fioex)
{
cerr << "I/O error while writing file: " << output_file << endl;
return false;
}
return true;
}
CorningConfigfile::CorningConfigfile()
{
}
void CorningConfigfile::setConfigfilePath(string configfilePath)
{
m_configfilePath = configfilePath;
}
bool CorningConfigfile::isConfigfileExist()
{
QFileInfo info(QString::fromStdString(m_configfilePath));
return info.exists();
}
bool CorningConfigfile::parseConfigfile()
{
// Read the file. If there is an error, report it and exit.
try
{
cfg.readFile(m_configfilePath);
return true;
}
catch (const FileIOException& fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return false;
}
catch (const ParseException& pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return false;
}
}
bool CorningConfigfile::getSpectralBin(int& spectralBin)
{
try
{
spectralBin = cfg.lookup("spectralBin");
return true;
}
catch (const SettingNotFoundException& nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool CorningConfigfile::getspatialBin(int& spatialBin)
{
try
{
spatialBin = cfg.lookup("spatialBin");
return true;
}
catch (const SettingNotFoundException& nfex)
{
cerr << "No 'spatialBin' setting in configuration file." << endl;
return false;
}
}
bool CorningConfigfile::getEffectiveWindow(int& width, int& offsetx, int& height, int& offsety)
{
const Setting& root = cfg.getRoot();
try
{
int spatialBin;
int spectralBin;
getspatialBin(spatialBin);
getSpectralBin(spectralBin);
string spatialBinString;
if (spatialBin == 1)
{
spatialBinString = "bin1";
}
else
{
spatialBinString = "bin2";
}
const Setting& spatialArgument = root["effective_window"][spatialBinString]["spatial"];
if (!(spatialArgument.lookupValue("width", width)
&& spatialArgument.lookupValue("offsetx", offsetx)))
{
return false;
}
string spectralBinString;
if (spectralBin == 1)
{
spectralBinString = "bin1";
}
else
{
spectralBinString = "bin2";
}
const Setting& spectralArgument = root["effective_window"][spectralBinString]["spectral"];
if (!(spectralArgument.lookupValue("height", height)
&& spectralArgument.lookupValue("offsety", offsety)))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool CorningConfigfile::getEffectiveWindowRoi(int& width, int& offsetx)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& effective_window = root["effective_window_roi"];
int count = effective_window.getLength();
int spatialBin;
getspatialBin(spatialBin);
string spatialBinString;
if (spatialBin == 1)
{
spatialBinString = "spatialBin1";
}
else
{
spatialBinString = "spatialBin2";
}
const Setting& window = effective_window[spatialBinString];
string name = window.getName();
if (!(window.lookupValue("width", width)
&& window.lookupValue("offsetx", offsetx)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool CorningConfigfile::getPushFlowParam(int& flowSwitch, int& rgbHeight, int& framerateVideo)
{
Setting& root = cfg.getRoot();
if (!root.exists("push_flow_param"))
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEB2BB><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Setting& push_flow_param = root.add("push_flow_param", Setting::TypeGroup);
push_flow_param.add("flow_switch", Setting::TypeInt) = 0;
push_flow_param.add("rgb_height", Setting::TypeInt) = 720;
push_flow_param.add("framerate_video", Setting::TypeInt) = 5;
// <20><><EFBFBD><EFBFBD><EFBFBD>޸ĺ<DEB8><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ļ<EFBFBD>
try
{
QList<QString> fileInfo = getFileInfo(QString::fromStdString(m_configfilePath));
bool ret = createDir(fileInfo[0]);
cfg.writeFile(m_configfilePath.c_str());
std::cout << "Config item 'push_flow_param' added." << std::endl;
flowSwitch = 0;
rgbHeight = 720;
framerateVideo = 5;
return true;
}
catch (const libconfig::FileIOException& fioex)
{
std::cerr << "I/O error while writing file." << std::endl;
return false;
}
}
else
{
try
{
const Setting& push_flow_param = root["push_flow_param"];
if (!(push_flow_param.lookupValue("rgb_height", rgbHeight)
&& push_flow_param.lookupValue("framerate_video", framerateVideo)
&& push_flow_param.lookupValue("flow_switch", flowSwitch)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
}
bool CorningConfigfile::getWindowOffsety_HeightOfSpectral(int& offsety, int& height, string spectralBinString)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& spectralArgument = root["effective_window"][spectralBinString]["spectral"];
if (!(spectralArgument.lookupValue("height", height)
&& spectralArgument.lookupValue("offsety", offsety)))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool CorningConfigfile::getGainOffset(float& gain, float& offset)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& gainOffset = root["gainOffset"];
int count = gainOffset.getLength();
int spectralBin;
getSpectralBin(spectralBin);
string spectralBinString;
if (spectralBin == 1)
{
spectralBinString = "spectralBin1";
}
else
{
spectralBinString = "spectralBin2";
}
const Setting& gainOffsetSetting = gainOffset[spectralBinString];
string name = gainOffsetSetting.getName();
if (!(gainOffsetSetting.lookupValue("gain", gain)
&& gainOffsetSetting.lookupValue("offset", offset)))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool CorningConfigfile::getGainOffsetOfSpectralBin1(float& gain, float& offset)
{
const Setting& root = cfg.getRoot();
try
{
const Setting& gainOffset = root["gainOffset"];
int count = gainOffset.getLength();
string spectralBinString = "spectralBin1";
const Setting& gainOffsetSetting = gainOffset[spectralBinString];
string name = gainOffsetSetting.getName();
if (!(gainOffsetSetting.lookupValue("gain", gain)
&& gainOffsetSetting.lookupValue("offset", offset)))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
// Ignore.
return false;
}
return true;
}
bool CorningConfigfile::getSN(QString& SN)
{
try
{
std::string SN_tem = cfg.lookup("SN");
SN = QString::fromStdString(SN_tem);
return true;
}
catch (const SettingNotFoundException& nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool CorningConfigfile::getBufferPolicy(int& bufferPolicy)
{
const Setting& root = cfg.getRoot();
const Setting& ximeadll = root["ximeadll"];
try
{
if (!(ximeadll.lookupValue("buffer_policy", bufferPolicy)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
return true;
}
bool CorningConfigfile::getAcqBufferSize(int& acqBufferSize)
{
const Setting& root = cfg.getRoot();
const Setting& ximeadll = root["ximeadll"];
try
{
if (!(ximeadll.lookupValue("acq_buffer_size", acqBufferSize)
))
{
return false;
}
}
catch (const SettingNotFoundException& nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
return true;
}
bool CorningConfigfile::createConfigFile()
{
using namespace std;
using namespace libconfig;
Config cfg;
Setting& root = cfg.getRoot();
// Add some settings to the configuration.
Setting& SN = root.add("SN", Setting::TypeString) = "0098";
Setting& spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
Setting& SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting& effective_window = root.add("effective_window", Setting::TypeGroup);
Setting& effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup);
Setting& effective_window_Bin1_spatial = effective_window_Bin1.add("spatial", Setting::TypeGroup);
Setting& effective_window_Bin1_Spectral = effective_window_Bin1.add("spectral", Setting::TypeGroup);
Setting& effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup);
Setting& effective_window_Bin2_spatial = effective_window_Bin2.add("spatial", Setting::TypeGroup);
Setting& effective_window_Bin2_Spectral = effective_window_Bin2.add("spectral", Setting::TypeGroup);
effective_window_Bin1_spatial.add("width", Setting::TypeInt) = 1368;
effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 288;
effective_window_Bin1_Spectral.add("height", Setting::TypeInt) = 300;
effective_window_Bin1_Spectral.add("offsety", Setting::TypeInt) = 348;
effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 688;
effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 144;
effective_window_Bin2_Spectral.add("height", Setting::TypeInt) = 150;
effective_window_Bin2_Spectral.add("offsety", Setting::TypeInt) = 174;
Setting& effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup);
Setting& effective_window_roi_spatialBin1 = effective_window_roi.add("spatialBin1", Setting::TypeGroup);
Setting& effective_window_roi_spatialBin2 = effective_window_roi.add("spatialBin2", Setting::TypeGroup);
effective_window_roi_spatialBin1.add("width", Setting::TypeInt) = 1364;
effective_window_roi_spatialBin1.add("offsetx", Setting::TypeInt) = 14;
// effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300;
// effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348;
effective_window_roi_spatialBin2.add("width", Setting::TypeInt) = 682;
effective_window_roi_spatialBin2.add("offsetx", Setting::TypeInt) = 15;
// effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151;
// effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174;
Setting& gainOffset = root.add("gainOffset", Setting::TypeGroup);
Setting& gainOffsetSpectralBin1 = gainOffset.add("spectralBin1", Setting::TypeGroup);
Setting& gainOffsetSpectralBin2 = gainOffset.add("spectralBin2", Setting::TypeGroup);
gainOffsetSpectralBin1.add("gain", Setting::TypeFloat) = 2.00313433;
gainOffsetSpectralBin1.add("offset", Setting::TypeFloat) = -300.46283157590585;
gainOffsetSpectralBin2.add("gain", Setting::TypeFloat) = 4.00626868;
gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
Setting& ximeadll = root.add("ximeadll", Setting::TypeGroup);
ximeadll.add("buffer_policy", Setting::TypeInt) = 0;
ximeadll.add("acq_buffer_size", Setting::TypeInt) = 400;
Setting& push_flow_param = root.add("push_flow_param", Setting::TypeGroup);
push_flow_param.add("flow_switch", Setting::TypeInt) = 1;
push_flow_param.add("rgb_height", Setting::TypeInt) = 720;
push_flow_param.add("framerate_video", Setting::TypeInt) = 5;
// Write out the new configuration.
try
{
cfg.writeFile(m_configfilePath.c_str());
cerr << "New configuration successfully written to: " << m_configfilePath.c_str() << endl;
}
catch (const FileIOException& fioex)
{
cerr << "I/O error while writing configuration file: " << m_configfilePath.c_str() << endl;
return true;
}
return true;
}
bool CorningConfigfile::updateConfigFile()
{
using namespace std;
using namespace libconfig;
static const char* output_file = "updated.cfg";
Config cfg;
cfg.setOptions(Config::OptionFsync
| Config::OptionSemicolonSeparators
| Config::OptionColonAssignmentForGroups
| Config::OptionOpenBraceOnSeparateLine);
// Read the file. If there is an error, report it and exit.
try
{
cfg.readFile("example.cfg");
}
catch (const FileIOException& fioex)
{
std::cerr << "I/O error while reading file." << std::endl;
return false;
}
catch (const ParseException& pex)
{
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
<< " - " << pex.getError() << std::endl;
return false;
}
// Find the 'movies' setting. Add intermediate settings if they don't yet
// exist.
Setting& root = cfg.getRoot();
if (!root.exists("inventory"))
root.add("inventory", Setting::TypeGroup);
Setting& inventory = root["inventory"];
if (!inventory.exists("movies"))
inventory.add("movies", Setting::TypeList);
Setting& movies = inventory["movies"];
// Create the new movie entry.
Setting& movie = movies.add(Setting::TypeGroup);
movie.add("title", Setting::TypeString) = "Buckaroo Banzai";
movie.add("media", Setting::TypeString) = "DVD";
movie.add("price", Setting::TypeFloat) = 12.99;
movie.add("qty", Setting::TypeInt) = 20;
// Write out the updated configuration.
try
{
cfg.writeFile(output_file);
cerr << "Updated configuration successfully written to: " << output_file
<< endl;
}
catch (const FileIOException& fioex)
{
cerr << "I/O error while writing file: " << output_file << endl;
return false;
}
return true;
}