本文整理汇总了C++中DataTree::rootNode方法的典型用法代码示例。如果您正苦于以下问题:C++ DataTree::rootNode方法的具体用法?C++ DataTree::rootNode怎么用?C++ DataTree::rootNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTree
的用法示例。
在下文中一共展示了DataTree::rootNode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
bool AppConfig::save() {
DataTree cfg;
cfg.rootNode()->setName("cubicsdr_config");
if (winW.load() && winH.load()) {
DataNode *window_node = cfg.rootNode()->newChild("window");
*window_node->newChild("x") = winX.load();
*window_node->newChild("y") = winY.load();
*window_node->newChild("w") = winW.load();
*window_node->newChild("h") = winH.load();
*window_node->newChild("max") = winMax.load();
*window_node->newChild("theme") = themeId.load();
*window_node->newChild("snap") = snap.load();
*window_node->newChild("center_freq") = centerFreq.load();
*window_node->newChild("waterfall_lps") = waterfallLinesPerSec.load();
*window_node->newChild("spectrum_avg") = spectrumAvgSpeed.load();
}
DataNode *devices_node = cfg.rootNode()->newChild("devices");
std::map<std::string, DeviceConfig *>::iterator device_config_i;
for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) {
DataNode *device_node = devices_node->newChild("device");
device_config_i->second->save(device_node);
}
if (manualDevices.size()) {
DataNode *manual_node = cfg.rootNode()->newChild("manual_devices");
for (std::vector<SDRManualDef>::const_iterator i = manualDevices.begin(); i != manualDevices.end(); i++) {
DataNode *rig_node = manual_node->newChild("device");
*rig_node->newChild("factory") = i->factory;
*rig_node->newChild("params") = i->params;
}
}
#ifdef USE_HAMLIB
DataNode *rig_node = cfg.rootNode()->newChild("rig");
*rig_node->newChild("model") = rigModel.load();
*rig_node->newChild("rate") = rigRate.load();
*rig_node->newChild("port") = rigPort;
#endif
std::string cfgFileName = getConfigFileName();
if (!cfg.SaveToFileXML(cfgFileName)) {
std::cout << "Error saving :: configuration file '" << cfgFileName << "' is not writable!" << std::endl;
return false;
}
return true;
}
示例2: save
bool AppConfig::save() {
DataTree cfg;
cfg.rootNode()->setName("cubicsdr_config");
if (winW.load() && winH.load()) {
DataNode *window_node = cfg.rootNode()->newChild("window");
*window_node->newChild("x") = winX.load();
*window_node->newChild("y") = winY.load();
*window_node->newChild("w") = winW.load();
*window_node->newChild("h") = winH.load();
*window_node->newChild("max") = winMax.load();
*window_node->newChild("theme") = themeId.load();
*window_node->newChild("snap") = snap.load();
*window_node->newChild("center_freq") = centerFreq.load();
}
DataNode *devices_node = cfg.rootNode()->newChild("devices");
std::map<std::string, DeviceConfig *>::iterator device_config_i;
for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) {
DataNode *device_node = devices_node->newChild("device");
device_config_i->second->save(device_node);
}
std::string cfgFileName = getConfigFileName();
if (!cfg.SaveToFileXML(cfgFileName)) {
std::cout << "Error saving :: configuration file '" << cfgFileName << "' is not writable!" << std::endl;
return false;
}
return true;
}
示例3: load
bool AppConfig::load() {
DataTree cfg;
std::string cfgFileDir = getConfigDir();
std::string cfgFileName = getConfigFileName();
wxFileName cfgFile = wxFileName(cfgFileName);
if (!cfgFile.Exists()) {
if (configName.length()) {
wxFileName baseConfig = wxFileName(getConfigFileName(true));
if (baseConfig.Exists()) {
std::string baseConfigFileName = baseConfig.GetFullPath(wxPATH_NATIVE).ToStdString();
std::cout << "Creating new configuration file '" << cfgFileName << "' by copying '" << baseConfigFileName << "'..";
wxCopyFile(baseConfigFileName, cfgFileName);
if (!cfgFile.Exists()) {
std::cout << "failed." << std::endl;
return true;
}
std::cout << "ok." << std::endl;
} else {
return true;
}
} else {
return true;
}
}
if (cfgFile.IsFileReadable()) {
std::cout << "Loading:: configuration file '" << cfgFileName << "'" << std::endl;
cfg.LoadFromFileXML(cfgFileName);
} else {
std::cout << "Error loading:: configuration file '" << cfgFileName << "' is not readable!" << std::endl;
return false;
}
if (cfg.rootNode()->hasAnother("window")) {
int x,y,w,h;
int max;
DataNode *win_node = cfg.rootNode()->getNext("window");
if (win_node->hasAnother("w") && win_node->hasAnother("h") && win_node->hasAnother("x") && win_node->hasAnother("y")) {
win_node->getNext("x")->element()->get(x);
win_node->getNext("y")->element()->get(y);
win_node->getNext("w")->element()->get(w);
win_node->getNext("h")->element()->get(h);
winX.store(x);
winY.store(y);
winW.store(w);
winH.store(h);
}
if (win_node->hasAnother("max")) {
win_node->getNext("max")->element()->get(max);
winMax.store(max?true:false);
}
if (win_node->hasAnother("theme")) {
int theme;
win_node->getNext("theme")->element()->get(theme);
themeId.store(theme);
}
if (win_node->hasAnother("snap")) {
long long snapVal;
win_node->getNext("snap")->element()->get(snapVal);
snap.store(snapVal);
}
if (win_node->hasAnother("center_freq")) {
long long freqVal;
win_node->getNext("center_freq")->element()->get(freqVal);
centerFreq.store(freqVal);
}
}
if (cfg.rootNode()->hasAnother("devices")) {
DataNode *devices_node = cfg.rootNode()->getNext("devices");
while (devices_node->hasAnother("device")) {
DataNode *device_node = devices_node->getNext("device");
if (device_node->hasAnother("id")) {
std::string deviceId;
device_node->getNext("id")->element()->get(deviceId);
getDevice(deviceId)->load(device_node);
}
}
}
return true;
}
示例4: load
bool AppConfig::load() {
DataTree cfg;
std::string cfgFileDir = getConfigDir();
std::string cfgFileName = getConfigFileName();
wxFileName cfgFile = wxFileName(cfgFileName);
if (!cfgFile.Exists()) {
if (configName.length()) {
wxFileName baseConfig = wxFileName(getConfigFileName(true));
if (baseConfig.Exists()) {
std::string baseConfigFileName = baseConfig.GetFullPath(wxPATH_NATIVE).ToStdString();
std::cout << "Creating new configuration file '" << cfgFileName << "' by copying '" << baseConfigFileName << "'..";
wxCopyFile(baseConfigFileName, cfgFileName);
if (!cfgFile.Exists()) {
std::cout << "failed." << std::endl;
return true;
}
std::cout << "ok." << std::endl;
} else {
return true;
}
} else {
return true;
}
}
if (cfgFile.IsFileReadable()) {
std::cout << "Loading:: configuration file '" << cfgFileName << "'" << std::endl;
cfg.LoadFromFileXML(cfgFileName);
} else {
std::cout << "Error loading:: configuration file '" << cfgFileName << "' is not readable!" << std::endl;
return false;
}
if (cfg.rootNode()->hasAnother("window")) {
int x,y,w,h;
int max;
DataNode *win_node = cfg.rootNode()->getNext("window");
if (win_node->hasAnother("w") && win_node->hasAnother("h") && win_node->hasAnother("x") && win_node->hasAnother("y")) {
win_node->getNext("x")->element()->get(x);
win_node->getNext("y")->element()->get(y);
win_node->getNext("w")->element()->get(w);
win_node->getNext("h")->element()->get(h);
winX.store(x);
winY.store(y);
winW.store(w);
winH.store(h);
}
if (win_node->hasAnother("max")) {
win_node->getNext("max")->element()->get(max);
winMax.store(max?true:false);
}
if (win_node->hasAnother("theme")) {
int theme;
win_node->getNext("theme")->element()->get(theme);
themeId.store(theme);
}
if (win_node->hasAnother("snap")) {
long long snapVal;
win_node->getNext("snap")->element()->get(snapVal);
snap.store(snapVal);
}
if (win_node->hasAnother("center_freq")) {
long long freqVal;
win_node->getNext("center_freq")->element()->get(freqVal);
centerFreq.store(freqVal);
}
if (win_node->hasAnother("waterfall_lps")) {
int lpsVal;
win_node->getNext("waterfall_lps")->element()->get(lpsVal);
waterfallLinesPerSec.store(lpsVal);
}
if (win_node->hasAnother("spectrum_avg")) {
float avgVal;
win_node->getNext("spectrum_avg")->element()->get(avgVal);
spectrumAvgSpeed.store(avgVal);
}
}
if (cfg.rootNode()->hasAnother("devices")) {
DataNode *devices_node = cfg.rootNode()->getNext("devices");
while (devices_node->hasAnother("device")) {
DataNode *device_node = devices_node->getNext("device");
if (device_node->hasAnother("id")) {
std::string deviceId = device_node->getNext("id")->element()->toString();
getDevice(deviceId)->load(device_node);
}
//.........这里部分代码省略.........
示例5: load
bool AppConfig::load() {
DataTree cfg;
std::string cfgFileDir = getConfigDir();
std::string cfgFileName = getConfigFileName();
wxFileName cfgFile = wxFileName(cfgFileName);
if (!cfgFile.Exists()) {
if (configName.length()) {
wxFileName baseConfig = wxFileName(getConfigFileName(true));
if (baseConfig.Exists()) {
std::string baseConfigFileName = baseConfig.GetFullPath(wxPATH_NATIVE).ToStdString();
std::cout << "Creating new configuration file '" << cfgFileName << "' by copying '" << baseConfigFileName << "'..";
wxCopyFile(baseConfigFileName, cfgFileName);
if (!cfgFile.Exists()) {
std::cout << "failed." << std::endl;
return true;
}
std::cout << "ok." << std::endl;
} else {
return true;
}
} else {
return true;
}
}
if (cfgFile.IsFileReadable()) {
std::cout << "Loading:: configuration file '" << cfgFileName << "'" << std::endl;
cfg.LoadFromFileXML(cfgFileName);
} else {
std::cout << "Error loading:: configuration file '" << cfgFileName << "' is not readable!" << std::endl;
return false;
}
if (cfg.rootNode()->hasAnother("window")) {
int x = 0 ,y = 0 ,w = 0 ,h = 0;
int max = 0 ,tips = 0 ,perf_mode = 0 ,mpc = 0;
DataNode *win_node = cfg.rootNode()->getNext("window");
if (win_node->hasAnother("w") && win_node->hasAnother("h") && win_node->hasAnother("x") && win_node->hasAnother("y")) {
win_node->getNext("x")->element()->get(x);
win_node->getNext("y")->element()->get(y);
win_node->getNext("w")->element()->get(w);
win_node->getNext("h")->element()->get(h);
winX.store(x);
winY.store(y);
winW.store(w);
winH.store(h);
}
if (win_node->hasAnother("max")) {
win_node->getNext("max")->element()->get(max);
winMax.store(max?true:false);
}
if (win_node->hasAnother("tips")) {
win_node->getNext("tips")->element()->get(tips);
showTips.store(tips?true:false);
}
// default:
perfMode.store(PERF_NORMAL);
if (win_node->hasAnother("perf_mode")) {
win_node->getNext("perf_mode")->element()->get(perf_mode);
if (perf_mode == (int)PERF_LOW) {
perfMode.store(PERF_LOW);
} else if (perf_mode == (int)PERF_HIGH) {
perfMode.store(PERF_HIGH);
}
}
if (win_node->hasAnother("theme")) {
int theme;
win_node->getNext("theme")->element()->get(theme);
themeId.store(theme);
}
if (win_node->hasAnother("font_scale")) {
int fscale;
win_node->getNext("font_scale")->element()->get(fscale);
fontScale.store(fscale);
}
if (win_node->hasAnother("snap")) {
long long snapVal;
win_node->getNext("snap")->element()->get(snapVal);
snap.store(snapVal);
}
if (win_node->hasAnother("center_freq")) {
long long freqVal;
win_node->getNext("center_freq")->element()->get(freqVal);
centerFreq.store(freqVal);
//.........这里部分代码省略.........
示例6: save
bool AppConfig::save() {
DataTree cfg;
cfg.rootNode()->setName("cubicsdr_config");
if (winW.load() && winH.load()) {
DataNode *window_node = cfg.rootNode()->newChild("window");
*window_node->newChild("x") = winX.load();
*window_node->newChild("y") = winY.load();
*window_node->newChild("w") = winW.load();
*window_node->newChild("h") = winH.load();
*window_node->newChild("max") = winMax.load();
*window_node->newChild("tips") = showTips.load();
*window_node->newChild("perf_mode") = (int)perfMode.load();
*window_node->newChild("theme") = themeId.load();
*window_node->newChild("font_scale") = fontScale.load();
*window_node->newChild("snap") = snap.load();
*window_node->newChild("center_freq") = centerFreq.load();
*window_node->newChild("waterfall_lps") = waterfallLinesPerSec.load();
*window_node->newChild("spectrum_avg") = spectrumAvgSpeed.load();
*window_node->newChild("modemprops_collapsed") = modemPropsCollapsed.load();;
*window_node->newChild("db_offset") = dbOffset.load();
*window_node->newChild("main_split") = mainSplit.load();
*window_node->newChild("vis_split") = visSplit.load();
*window_node->newChild("bookmark_split") = bookmarkSplit.load();
*window_node->newChild("bookmark_visible") = bookmarksVisible.load();
}
//Recording settings:
DataNode *rec_node = cfg.rootNode()->newChild("recording");
*rec_node->newChild("path") = recordingPath;
*rec_node->newChild("squelch") = recordingSquelchOption;
*rec_node->newChild("file_time_limit") = recordingFileTimeLimitSeconds;
DataNode *devices_node = cfg.rootNode()->newChild("devices");
std::map<std::string, DeviceConfig *>::iterator device_config_i;
for (device_config_i = deviceConfig.begin(); device_config_i != deviceConfig.end(); device_config_i++) {
DataNode *device_node = devices_node->newChild("device");
device_config_i->second->save(device_node);
}
if (manualDevices.size()) {
DataNode *manual_node = cfg.rootNode()->newChild("manual_devices");
for (std::vector<SDRManualDef>::const_iterator i = manualDevices.begin(); i != manualDevices.end(); i++) {
DataNode *rig_node = manual_node->newChild("device");
*rig_node->newChild("factory") = i->factory;
*rig_node->newChild("params") = i->params;
}
}
#ifdef USE_HAMLIB
DataNode *rig_node = cfg.rootNode()->newChild("rig");
*rig_node->newChild("enabled") = rigEnabled.load()?1:0;
*rig_node->newChild("model") = rigModel.load();
*rig_node->newChild("rate") = rigRate.load();
*rig_node->newChild("port") = rigPort;
*rig_node->newChild("control") = rigControlMode.load()?1:0;
*rig_node->newChild("follow") = rigFollowMode.load()?1:0;
*rig_node->newChild("center_lock") = rigCenterLock.load()?1:0;
*rig_node->newChild("follow_modem") = rigFollowModem.load()?1:0;
#endif
std::string cfgFileName = getConfigFileName();
if (!cfg.SaveToFileXML(cfgFileName)) {
std::cout << "Error saving :: configuration file '" << cfgFileName << "' is not writable!" << std::endl;
return false;
}
return true;
}
示例7: loadSession
bool AppFrame::loadSession(std::string fileName) {
DataTree l;
if (!l.LoadFromFileXML(fileName)) {
return false;
}
wxGetApp().getDemodMgr().terminateAll();
try {
DataNode *header = l.rootNode()->getNext("header");
std::string version(*header->getNext("version"));
long long center_freq = *header->getNext("center_freq");
std::cout << "Loading " << version << " session file" << std::endl;
std::cout << "\tCenter Frequency: " << center_freq << std::endl;
wxGetApp().setFrequency(center_freq);
DataNode *demodulators = l.rootNode()->getNext("demodulators");
while (demodulators->hasAnother("demodulator")) {
DataNode *demod = demodulators->getNext("demodulator");
if (!demod->hasAnother("bandwidth") || !demod->hasAnother("frequency")) {
continue;
}
long bandwidth = *demod->getNext("bandwidth");
long long freq = *demod->getNext("frequency");
int type = demod->hasAnother("type") ? *demod->getNext("type") : DEMOD_TYPE_FM;
float squelch_level = demod->hasAnother("squelch_level") ? (float) *demod->getNext("squelch_level") : 0;
int squelch_enabled = demod->hasAnother("squelch_enabled") ? (int) *demod->getNext("squelch_enabled") : 0;
int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0;
std::string output_device = demod->hasAnother("output_device") ? string(*(demod->getNext("output_device"))) : "";
float gain = demod->hasAnother("gain") ? (float) *demod->getNext("gain") : 1.0;
DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().newThread();
newDemod->setDemodulatorType(type);
newDemod->setBandwidth(bandwidth);
newDemod->setFrequency(freq);
newDemod->setGain(gain);
newDemod->updateLabel(freq);
if (squelch_enabled) {
newDemod->setSquelchEnabled(true);
newDemod->setSquelchLevel(squelch_level);
}
if (stereo) {
newDemod->setStereo(true);
}
bool found_device = false;
std::map<int, RtAudio::DeviceInfo>::iterator i;
for (i = outputDevices.begin(); i != outputDevices.end(); i++) {
if (i->second.name == output_device) {
newDemod->setOutputDevice(i->first);
found_device = true;
}
}
if (!found_device) {
std::cout << "\tWarning: named output device '" << output_device << "' was not found. Using default output.";
}
newDemod->run();
newDemod->setActive(false);
wxGetApp().bindDemodulator(newDemod);
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
std::cout << "\t\tSquelch Level: " << squelch_level << std::endl;
std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl;
std::cout << "\t\tStereo: " << (stereo ? "true" : "false") << std::endl;
std::cout << "\t\tOutput Device: " << output_device << std::endl;
}
} catch (DataInvalidChildException &e) {
std::cout << e.what() << std::endl;
return false;
} catch (DataTypeMismatchException &e) {
std::cout << e.what() << std::endl;
return false;
}
currentSessionFile = fileName;
std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator) + 1);
GetStatusBar()->SetStatusText(wxString::Format(wxT("Loaded session file: %s"), currentSessionFile.c_str()));
SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str()));
return true;
}