void ApplyConfigSection(const ConfigSection &config)
	{
		config.Get("radial_rank", RadialRank);
		config.Get("angular_rank", AngularRank);
		//charge with sign
		config.Get("charge", Charge);
	}
Esempio n. 2
0
	/*
	 * Called once with the corresponding config section
	 * from the configuration file. Do all one time set up routines
	 * here.
	 */
	void ApplyConfigSection(const ConfigSection &config)
	{
		config.Get("zero_before", ZeroBefore);
		config.Get("zero_after", ZeroAfter);
		config.Get("step_rank", StepRank);

	}
Esempio n. 3
0
bool Config::get_allocated(const char* section, const char* key, char** ret, unsigned int& retsize) {
	retsize = 0;

	ConfigSection* cs = find_section(section);
	if (!cs) {
		errcode = CONF_ERR_SECTION;
		return false;
	}

	ConfigEntry* ce = cs->find_entry(key);
	if (!ce) {
		errcode = CONF_ERR_KEY;
		return false;
	}

	char* value = ce->value;
	retsize = ce->valuelen;

	*ret = new char[retsize + 1];
	strncpy(*ret, value, retsize);
	// terminate, since ce->valuelen does not contain terminating char
	char* p = *ret;
	p[retsize] = '\0';

	return true;
}
Esempio n. 4
0
shared_ptr<ndn::Transport>
Nrd::getLocalNfdTransport()
{
  ConfigSection config;

  if (!m_configFile.empty()) {
    // Any format errors should have been caught already
    // If error is thrown at this point, it is development error
    boost::property_tree::read_info(m_configFile, config);
  }
  else
    config = m_configSection;

  if (config.get_child_optional("face_system.unix")) {
    // unix socket enabled

    auto&& socketPath = config.get<std::string>("face_system.unix.path", "/var/run/nfd.sock");
    // default socketPath should be the same as in FaceManager::processSectionUnix

    return make_shared<ndn::UnixTransport>(socketPath);
  }
  else if (config.get_child_optional("face_system.tcp") &&
           config.get<std::string>("face_system.tcp.listen", "yes") == "yes") {
    // tcp is enabled

    auto&& port = config.get<std::string>("face_system.tcp.port", "6363");
    // default port should be the same as in FaceManager::processSectionTcp

    return make_shared<ndn::TcpTransport>("localhost", port);
  }
  else {
    throw Error("No transport is available to communicate with NFD");
  }
}
Esempio n. 5
0
 void ApplyConfigSection(const ConfigSection &config)
 {
     config.Get("radial_rank_1", RadialRank1);
     config.Get("radial_rank_2", RadialRank2);
     config.Get("inner_box_size", InnerBoxSize);
     config.Get("width", Width);
 }
	virtual void ApplyConfigSection(const ConfigSection &config)
	{
		CustomPotentialSphericalBase<Rank>::ApplyConfigSection
			(config);
		config.Get("inter_nuclear_r", R);
		config.Get("theta_inter_nucl", ThetaR);
	}
static void
onConfig(const ConfigSection& configSection,
         bool isDryRun,
         const std::string& filename)
{
  // general
  // {
  //    ; user "ndn-user"
  //    ; group "ndn-user"
  // }

  std::string user;
  std::string group;

  for (ConfigSection::const_iterator i = configSection.begin();
       i != configSection.end();
       ++i)
    {
      if (i->first == "user")
        {
          try
            {
              user = i->second.get_value<std::string>("user");

              if (user.empty())
                {
                  throw ConfigFile::Error("Invalid value for \"user\""
                                          " in \"general\" section");
                }
            }
          catch (const boost::property_tree::ptree_error& error)
            {
              throw ConfigFile::Error("Invalid value for \"user\""
                                      " in \"general\" section");
            }
        }
      else if (i->first == "group")
        {
          try
            {
              group = i->second.get_value<std::string>("group");

              if (group.empty())
                {
                  throw ConfigFile::Error("Invalid value for \"group\""
                                          " in \"general\" section");
                }
            }
          catch (const boost::property_tree::ptree_error& error)
            {
              throw ConfigFile::Error("Invalid value for \"group\""
                                      " in \"general\" section");
            }
        }
    }
  NFD_LOG_TRACE("using user \"" << user << "\" group \"" << group << "\"");

  PrivilegeHelper::initialize(user, group);
}
Esempio n. 8
0
	/*
	 * Called once with the corresponding config section
	 * from the configuration file. Do all one time set up routines
	 * here.
	 */
	void ApplyConfigSection(const ConfigSection &config)
	{
		config.Get("pulse_duration", PulseDuration);
		config.Get("frequency", Frequency);
		config.Get("amplitude", Amplitude);

		convolutionFrequency = M_PI / PulseDuration;
	}
Esempio n. 9
0
	/*
	 * Called once with the corresponding config section
	 * from the configuration file. Do all one time set up routines
	 * here.
	 */
	void ApplyConfigSection(const ConfigSection &config)
	{
		config.Get("field_strength", FieldStrength);
		config.Get("frequency", Frequency);
		config.Get("duration", Duration);
		config.Get("peak_time", PeakTime);
		config.Get("phase", Phase);
	}
Esempio n. 10
0
void CombinedRepresentation<Rank>::ApplyConfigSection(const ConfigSection &config) 
{
	//Do this manually for each sub-representation

	if (config.HasValue("innerproduct_algorithm"))
	{
		config.Get("innerproduct_algorithm", Algorithm);
	}
}
Esempio n. 11
0
void Config::set(const char* section, const char* key, double value) {
	ConfigSection* sc = add_section(section);
	char* locale = nls_locale_to_c();

	char tmp[32];
	snprintf(tmp, sizeof(tmp)-1, "%g", value);

	nls_locale_from_c(locale);
	sc->add_entry(key, tmp);
}
Esempio n. 12
0
 /*
  * Called once with the corresponding config section
  * from the configuration file. Do all one time set up routines
  * here.
  */
 void ApplyConfigSection(const ConfigSection &config)
 {
     config.Get("radial_rank_1", radialRank1);
     config.Get("radial_rank_2", radialRank2);
     config.Get("absorber_start", absorberStart);
     config.Get("absorber_length", absorberLength);
     config.Get("scaling_real", scalingReal);
     config.Get("scaling_imag", scalingImag);
     config.Get("factor_real", factorReal);
     config.Get("factor_imag", factorImag);
 }
Esempio n. 13
0
	void ApplyConfigSection(const ConfigSection &config)
	{
		config.Get("charge", Charge);
		config.Get("laser_frequency", LaserFrequency);
		config.Get("laser_intensity", LaserIntensity);
		
		double laserTurnOnCycles = 0;
		config.Get("laser_turn_on_cycles", laserTurnOnCycles);
		LaserTurnOnTime = laserTurnOnCycles * 2 * M_PI / LaserFrequency;
		
	}
Esempio n. 14
0
void begin_config(const std::string& block, int *pln, int *pcode, int *cp) throw(ParserError) {
	string block_name(block);
	ConfigSection* section = g_Config.getSection(block_name);
	if (section == NULL) {
		g_throw_parser_error("unrecognized config section '", block_name.c_str(), "'");
	}
	// Don't do config blocks in safe mode (except in RC file)
	GLEInterface* iface = GLEGetInterfacePointer();
	if (iface->getCmdLine()->hasOption(GLE_OPT_SAFEMODE)) {
		GLEGlobalConfig* config = iface->getConfig();
		if (!config->allowConfigBlocks()) {
			g_throw_parser_error("safe mode - config blocks not allowed");
		}
	}
	// Start with pcode from the next line
	(*pln)++;
	begin_init();
	while (true) {
		int st = begin_token(&pcode,cp,pln,srclin,tk,&ntk,outbuff);
		if (!st) {
			/* exit loop */
			break;
		}
		int ct = 1;
		int mode = 0;
		bool plus_is = false;
		CmdLineOption* option = NULL;
		while (ct <= ntk) {
			skipspace;
			if (section != NULL) {
				if (mode == 0) {
					option = section->getOption(tk[ct]);
					if (option == NULL) {
						gprint("Not a valid setting for section '%s': {%s}\n", block_name.c_str(), tk[ct]);
					}
				} else if (mode == 1) {
					if (strcmp(tk[ct], "=") == 0) {
						plus_is = false;
					} else if (strcmp(tk[ct], "+=") == 0) {
						plus_is = true;
					} else {
						gprint("Expected '=' or '+=', not {%s}\n", tk[ct]);
					}
				} else if (option != NULL) {
					CmdLineOptionArg* arg = option->getArg(0);
					if (!plus_is) arg->reset();
					arg->appendValue(tk[ct]);
				}
				mode++;
			}
			ct++;
		}
	}
}
Esempio n. 15
0
void init_installed_versions(CmdLineObj& cmdline, ConfigCollection* collection) {
	CmdLineArgSet* versions = (CmdLineArgSet*)cmdline.getOption(GLE_OPT_VERSION)->getArg(0);
	ConfigSection* gle = collection->getSection(GLE_CONFIG_GLE);
	CmdLineArgSPairList* installs = (CmdLineArgSPairList*)gle->getOption(GLE_CONFIG_GLE_INSTALL)->getArg(0);
	if (installs->size() == 0) {
		versions->addPossibleValue("no older GLE versions found (run \"gle -finddeps\")");
	} else {
		for (int i = 0; i < installs->size(); i++) {
			versions->addPossibleValue(installs->getValue1(i).c_str());
		}
	}
}
Esempio n. 16
0
void
LoggerFactory::onConfig(const ConfigSection& section,
                        bool isDryRun,
                        const std::string& filename)
{
// log
// {
//   ; default_level specifies the logging level for modules
//   ; that are not explicitly named. All debugging levels
//   ; listed above the selected value are enabled.
//
//   default_level INFO
//
//   ; You may also override the default for specific modules:
//
//   FibManager DEBUG
//   Forwarder WARN
// }

  if (!isDryRun) {
    ConfigSection::const_assoc_iterator item = section.find("default_level");
    if (item != section.not_found()) {
      LogLevel level = extractLevel(item->second, "default_level");
      setDefaultLevel(level);
    }
    else {
      setDefaultLevel(LOG_INFO);
    }
  }

  for (const auto& i : section) {
    LogLevel level = extractLevel(i.second, i.first);

    if (i.first == "default_level") {
      // do nothing
    }
    else {
      std::unique_lock<std::mutex> lock(m_loggersGuard);
      LoggerMap::iterator loggerIt = m_loggers.find(i.first);
      if (loggerIt == m_loggers.end()) {
        lock.unlock();
        NFD_LOG_DEBUG("Failed to configure logging level for module \"" <<
                      i.first << "\" (module not found)");
      }
      else if (!isDryRun) {
        loggerIt->second.setLogLevel(level);
        lock.unlock();
        NFD_LOG_DEBUG("Changing level for module " << i.first << " to " << level);
      }
    }
  }
}
Esempio n. 17
0
ConfigSection* ParserHelper::getSection(size_t* initial, std::string* line, size_t* lineNumber, std::string name)
{
#ifdef DEBUG_PARSERHELPER
        std::cout << "\tsection\t pos='" << *initial << "'; char='" << line->at(*initial) << "'\n";
#endif // DEBUG_PARSERHELPER
    std::string l = name + line->substr(*initial);
    size_t* count = new size_t(0);
    ConfigSection* cs = new ConfigSection();
    cs->parse(&l, count, lineNumber);
    *initial += *count - name.size();
    delete count;
    return cs;
}
Esempio n. 18
0
BOOL CMainFrame::BeforeLoadFrame(CFrameWnd* pMainWnd)
{
    m_mainwnd = pMainWnd;
    m_frameNode = g_factoryRoot.GetSection(L"mainframe");
    m_appid = g_factoryRoot->GetString(L"_appid");
    m_appname = g_factoryRoot->GetString(L"appname");
    m_id = GetNodeID(m_frameNode, L"id");
    ASSERT(!m_appname.empty());

    m_barsfile = getConfigPath() + g_factoryRoot->GetString(L"cmdbarsFile", L"cmdbars.xml");

    return TRUE;
}
Esempio n. 19
0
  static shared_ptr<Filter>
  create(const ConfigSection& configSection)
  {
    ConfigSection::const_iterator propertyIt = configSection.begin();

    if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
      throw Error("Expect <filter.type>!");

    std::string type = propertyIt->second.data();

    if (boost::iequals(type, "name"))
      return createNameFilter(configSection);
    else
      throw Error("Unsupported filter.type: " + type);
  }
Esempio n. 20
0
BOOL CMainFrame::CreateRibbonBar()
{
    std::wstring xcbfile(getConfigPath() + g_factoryRoot->GetString(L"xcbfile"));
    CFile file(xcbfile.c_str(), CFile::modeRead);
    CArchive ar(&file, CArchive::load);
    
    m_cmdbars->LoadDesignerBars(ar);

    CXTPRibbonBar* pRibbonBar = DYNAMIC_DOWNCAST(
        CXTPRibbonBar, m_cmdbars->GetMenuBar());
    if (NULL == pRibbonBar)
        return FALSE;

    SetRibbonFont();

    std::wstring themeName(getUIOptions()->GetString(L"themeName"));
    if (themeName.find(L"WINDOWS7") != std::wstring::npos
        || themeName.find(L"OFFICE201") != std::wstring::npos)
    {
        pRibbonBar->GetSystemButton()->SetStyle(xtpButtonCaption);
    }
    pRibbonBar->EnableFrameTheme();

    return TRUE;
}
Esempio n. 21
0
  static shared_ptr<KeyLocatorChecker>
  create(const ConfigSection& configSection, const std::string& filename)
  {
    ConfigSection::const_iterator propertyIt = configSection.begin();

    // Get checker.key-locator.type
    if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
      BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.type>!"));

    std::string type = propertyIt->second.data();

    if (boost::iequals(type, "name"))
      return createKeyLocatorNameChecker(configSection, filename);
    else
      BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator.type: " + type));
  }
Esempio n. 22
0
std::ostream& ConfigFile::DebugPrint( std::ostream& pOut )
{
    ConfigSection*                          section = NULL;
    Map<String,ConfigSection*>::iterator    itMap;

    for( itMap = mSections.begin(); itMap != mSections.end(); itMap++ )
    {
        section = (*itMap).second;

        pOut << "[" << (*itMap).first.c_str() << "]" << std::endl;
        section->Save( pOut );
        pOut << std::endl;
    }

    return pOut;
}
Esempio n. 23
0
void GmresWrapper<Rank>::ApplyConfigSection(const ConfigSection &config)
{
	config.Get("krylov_basis_size", Solver.BasisSize);

	if (config.HasValue("krylov_tolerance"))
	{
		config.Get("krylov_tolerance", Solver.Tolerance);
	}

	//Perform double orthogonalization step?
	if (config.HasValue("krylov_double_orthogonalization"))
	{
		bool performDoubleOrthogonalization;
		config.Get("krylov_double_orthogonalization", performDoubleOrthogonalization);
		cout << "Using doubleorth = " << performDoubleOrthogonalization << endl;
		Solver.PerformDoubleOrthogonalization = performDoubleOrthogonalization;
	}
}
Esempio n. 24
0
bool try_save_config(const string& fname, GLEInterface* iface, bool isUser) {
	ConfigCollection* collection = iface->getConfig()->getRCFile();
	if (collection->allDefaults()) {
		return true;
	}
	if (fname == "") {
		return false;
	}
	if (IsAbsPath(fname)) {
		std::string dirname;
		GetDirName(fname, dirname);
		EnsureMkDir(dirname);
	}
	ofstream fout(fname.c_str());
	if (!fout.is_open()) {
		return false;
	}
	CmdLineOption* versionOption = collection->getSection(GLE_CONFIG_GLE)->getOption(GLE_CONFIG_GLE_VERSION);
	ostringstream out;
	out << "Save configuration to: '" << fname << "'";
	GLEOutputStream* output = iface->getOutput();
	output->println(out.str().c_str());
	for (int i = 0; i < collection->getNbSections(); i++) {
		ConfigSection* sec = collection->getSection(i);
		if (!sec->allDefaults()) {
			fout << "begin config " << sec->getName() << endl;
			for (int j = 0; j < sec->getNbOptions(); j++) {
				CmdLineOption* option = sec->getOption(j);
				if (!option->allDefaults() && (!isUser || option != versionOption)) {
					fout << "\t" << option->getName() << " = ";
					for (int k = 0; k < option->getMaxNbArgs(); k++) {
						if (k != 0) fout << " ";
						CmdLineOptionArg* arg = option->getArg(k);
						arg->write(fout);
					}
					fout << endl;
				}
			}
			fout << "end config" << endl << endl;
		}
	}
	fout.close();
	return true;
}
Esempio n. 25
0
void ConfigFile::load(const std::string &fname)
{
    std::ifstream stream(fname.c_str(), std::ios_base::binary);
    if(!stream.is_open()) return;

    ConfigSection *section = nullptr;
    std::string cur_section;
    std::string line;
    size_t linenum = 0;
    while(stream)
    {
        line.clear();
        if(!std::getline(stream, line))
            break;
        ++linenum;

        line = trim_whitespace(line, 0, line.find('#'));
        if(line.empty()) continue;

        if(line.front() == '[' && line.back() == ']')
        {
            cur_section = line.substr(1, line.length()-2);
            section = &mSections[cur_section];
            continue;
        }

        size_t split = line.find('=');
        if(split == std::string::npos)
        {
            std::cerr<< "Option missing value on line "<<linenum<<" in "<<fname <<std::endl;
            continue;
        }
        if(split == 0)
        {
            std::cerr<< "Option name missing on line "<<linenum<<" in "<<fname <<std::endl;
            continue;
        }

        if(!section)
            section = &mSections[cur_section];
        section->insert(std::make_pair(trim_whitespace(line, 0, split-1),
                                       expand_env(trim_whitespace(line, split+1))));
    }
}
Esempio n. 26
0
void CFrameWndFactory::RegisterDocTemplate(bool mdi, const ConfigSection& frame, 
                                           const ConfigSection& views)
{
    UINT id = frame->GetUInt32(L"id");
    ASSERT(id != 0);
    ViewItem item;

    if (mdi)
    {
        for (int i = 0; i < 20; i++)
        {
            ConfigSection view(views.GetSectionByIndex(L"view", i));

            if (!view->IsValid())
                break;
            
            item.frameID = view->GetUInt32(L"id", id);
            item.layout = view->GetString(L"layout");
            item.caption = view->GetString(L"caption");
            item.clsid = view->GetString(L"clsid");

            item.pTemplate = new CMultiDocTemplate(
                item.frameID,
                RUNTIME_CLASS(CDummyDoc),
                RUNTIME_CLASS(CChildFrame),
                RUNTIME_CLASS(CEmbedView));
            AfxGetApp()->AddDocTemplate(item.pTemplate);
            s_views.push_back(item);
        }
    }
    else
    {
        item.pTemplate = new CSingleDocTemplate(id,
            RUNTIME_CLASS(CDummyDoc),
            RUNTIME_CLASS(CMainSDIFrame),
            RUNTIME_CLASS(CEmbedView));
        AfxGetApp()->AddDocTemplate(item.pTemplate);

        item.clsid = frame->GetString(L"viewClsid");
        if (!item.clsid.empty())
            s_views.push_back(item);
    }
}
Esempio n. 27
0
string ConfigFile::LoadStr(const wchar * Section, const wchar * Key, const wchar* Default)
{
	verify(Section != 0 && strlen(Section) != 0);
	verify(Key != 0 && strlen(Key) != 0);

	if (Default == 0)
		Default = "";
	ConfigSection* cs = this->GetEntry(Section);
	ConfigEntry* ce = cs->FindEntry(Key);
	if (!ce)
	{
		cs->SetEntry(Key, Default, CEM_SAVE);
		return Default;
	}
	else
	{
		return ce->GetValue();
	}
}
Esempio n. 28
0
bool Config::get(const char* section, const char* key, char* ret, unsigned int size) {
	ConfigSection* cs = find_section(section);
	if (!cs) {
		errcode = CONF_ERR_SECTION;
		return false;
	}
	ConfigEntry* ce = cs->find_entry(key);
	if (!ce) {
		errcode = CONF_ERR_KEY;
		return false;
	}
	char* value = ce->value;
	strncpy(ret, value, size);

	// again, strncpy does not terminate string if size is less that actual
	if(ce->valuelen > size)
		ret[size-1] = '\0';

	return true;
}
Esempio n. 29
0
BOOL CMainFrame::AfterLoadFrame()
{
    CString title;
    VERIFY(title.LoadString(m_id));
    m_mainwnd->SetWindowText(title);

    m_frameNode.release();
    g_factoryRoot.release();
    AfxGetApp()->m_pMainWnd = m_mainwnd;

    return TRUE;
}
Esempio n. 30
0
void EditorTool::LoadSettings( ConfigSection& pSection )
{
    // Get our information from the config file.
    mVisible =  (Bool)pSection.Get( "Visible",  true );
    mPosX    = (Int32)pSection.Get( "PosX",     (Int32)10 );
    mPosY    = (Int32)pSection.Get( "PosY",     (Int32)10 );
    mWidth   = (Int32)pSection.Get( "Width",    (Int32)50 );
    mHeight  = (Int32)pSection.Get( "Height",   (Int32)50 );

    // Set the window information.
    mWindow->resize( mWidth, mHeight );

    if( mWindow->parentWidget() )
        mWindow->parentWidget()->move( mPosX, mPosY );

    // Show or hide the window depending of the setting.
    if( mVisible )
        Show();
    else
        Hide();
}