Example #1
0
  void test_parse_line_with_negative() {
    ConfigParser cfg;

    ConfigParser::Entry* e = cfg.parse_line("rbx.blah = -3");
    TS_ASSERT_EQUALS(std::string("rbx.blah"), e->variable);
    TS_ASSERT_EQUALS(std::string("-3"), e->value);
  }
Example #2
0
/*
** Reads and binds secondary measures (MeasureName2 - MeasureNameN).
**
*/
void Meter::BindSecondaryMeasures(ConfigParser& parser, const WCHAR* section)
{
    if (!m_Measures.empty())
    {
        WCHAR tmpName[64];

        int i = 2;
        do
        {
            _snwprintf_s(tmpName, _TRUNCATE, L"MeasureName%i", i);
            const std::wstring& measureName = parser.ReadString(section, tmpName, L"");
            Measure* measure = parser.GetMeasure(measureName);
            if (measure)
            {
                m_Measures.push_back(measure);
            }
            else
            {
                if (!measureName.empty())
                {
                    LogErrorF(this, L"MeasureName%i=%s is not valid", i, measureName.c_str());
                }

                break;
            }
            ++i;
        }
        while (true);
    }
}
Example #3
0
/*
** Read the options specified in the ini file.
**
*/
void MeasureCalc::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	Measure::ReadOptions(parser, section);

	// Store the current values so we know if the value needs to be updated
	int oldLowBound = m_LowBound;
	int oldHighBound = m_HighBound;
	bool oldUpdateRandom = m_UpdateRandom;

	std::wstring oldFormula = m_Formula;
	m_Formula = parser.ReadString(section, L"Formula", L"");

	m_LowBound = parser.ReadInt(section, L"LowBound", 0);
	m_HighBound = parser.ReadInt(section, L"HighBound", 100);
	m_UpdateRandom = 0!=parser.ReadInt(section, L"UpdateRandom", 0);

	if (!m_Initialized ||
		wcscmp(m_Formula.c_str(), oldFormula.c_str()) != 0 ||
		oldLowBound != m_LowBound ||
		oldHighBound != m_HighBound ||
		oldUpdateRandom != m_UpdateRandom)
	{
		if (!m_UpdateRandom)
		{
			FormulaReplace();
		}

		const WCHAR* errMsg = MathParser::Check(m_Formula.c_str());
		if (errMsg != nullptr)
		{
			LogErrorF(this, L"Calc: %s", errMsg);
			m_Formula.clear();
		}
	}
}
Example #4
0
  void test_parse_line_with_dot() {
    ConfigParser cfg;

    ConfigParser::Entry* e = cfg.parse_line("rbx.blah = ./foo.bar");
    TS_ASSERT_EQUALS(std::string("rbx.blah"), e->variable);
    TS_ASSERT_EQUALS(std::string("./foo.bar"), e->value);
  }
Example #5
0
void Meter::ReadContainerOptions(ConfigParser& parser, const WCHAR* section)
{
	const std::wstring& style = parser.ReadString(section, L"MeterStyle", L"");
	if (!style.empty())
	{
		parser.SetStyleTemplate(style);
	}

	const std::wstring& container = parser.ReadString(section, L"Container", L"");
	if (_wcsicmp(section, container.c_str()) == 0)
	{
		LogErrorF(this, L"Container cannot self-reference: %s", container.c_str());
		return;
	}

	if (!m_ContainerMeter || _wcsicmp(m_ContainerMeter->GetName(), container.c_str()) != 0)
	{
		if (m_ContainerMeter)
		{
			m_ContainerMeter->RemoveContainerItem(this);
			m_ContainerMeter = nullptr;
		}

		auto meter = m_Skin->GetMeter(container);
		if (meter)
		{
			meter->AddContainerItem(this);
			m_ContainerMeter = meter;
		}
		else if (!container.empty())
		{
			LogErrorF(this, L"Invalid container: %s", container.c_str());
		}
	}
}
Example #6
0
/*
** Read the options specified in the ini file.
**
*/
void MeasureCalc::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	Measure::ReadOptions(parser, section);

	// Store the current values so we know if the value needs to be updated
	int oldLowBound = m_LowBound;
	int oldHighBound = m_HighBound;
	bool oldUpdateRandom = m_UpdateRandom;
	bool oldUniqueRandom = m_UniqueRandom;

	std::wstring oldFormula = m_Formula;
	m_Formula = parser.ReadString(section, L"Formula", L"");

	m_LowBound = parser.ReadInt(section, L"LowBound", DEFAULT_LOWER_BOUND);
	m_HighBound = parser.ReadInt(section, L"HighBound", DEFAULT_UPPER_BOUND);
	m_UpdateRandom = parser.ReadBool(section, L"UpdateRandom", false);

	m_UniqueRandom = parser.ReadBool(section, L"UniqueRandom", false);
	if (!m_UniqueRandom)
	{
		m_UniqueNumbers.clear();
	}

	if (!m_Initialized ||
		wcscmp(m_Formula.c_str(), oldFormula.c_str()) != 0 ||
		oldLowBound != m_LowBound ||
		oldHighBound != m_HighBound ||
		oldUpdateRandom != m_UpdateRandom ||
		oldUniqueRandom != m_UniqueRandom)
	{
		// Reset bounds if |m_LowBound| is greater than |m_HighBound|
		if (m_LowBound > m_HighBound)
		{
			LogErrorF(this, L"\"LowBound\" (%i) must be less then or equal to \"HighBound\" (%i)", m_LowBound, m_HighBound);
			
			m_HighBound = m_LowBound;
		}

		// Reset the list if the bounds are changed
		if (m_UniqueRandom && (
			oldLowBound != m_LowBound ||
			oldHighBound != m_HighBound))
		{
			UpdateUniqueNumberList();
		}

		if (!m_UpdateRandom)
		{
			FormulaReplace();
		}

		const WCHAR* errMsg = MathParser::Check(m_Formula.c_str());
		if (errMsg != nullptr)
		{
			LogErrorF(this, L"Calc: %s", errMsg);
			m_Formula.clear();
		}
	}
}
Example #7
0
void ConfigData::ReadPluginData(ConfigParser &parser)
{
  //Get if the outer log section exists
  const ConfigToken * pluginDataToken = parser.GetToken("PluginData");
  if(!pluginDataToken)
  {
    return;
  }
  const ConfigToken *pluginTestToken;

  //Get the plugin base directory
  pluginTestToken = pluginDataToken->GetChildToken("BaseDir");
  if(pluginTestToken)
  { 
    pluginTestToken->Get(pluginBasePath);

    //Add a directory seperator
    pluginBasePath = pluginBasePath + FileUtils::dirSeparator;
  }

  //Get the plugin token
  pluginTestToken = pluginDataToken->GetChildToken("Plugins");
  if(pluginTestToken)
  { 
    //Loop for all children
    for(uint i=0;i<pluginTestToken->GetNumChildren();i++)
    {
      //Get the token and check that it has a value
      const ConfigToken *pToken = pluginTestToken->GetChildToken(i);
      if(pToken->GetNumValues() != 1)
      {
        LOGERR(("ConfigData::ReadPluginData - Error in PluginData:Plugins:%s -Expected one dll name value",pToken->GetName().c_str()));
        return;
      }

      //Fill out the plugin data
      PluginData newData;
      newData.pluginName = pToken->GetName();
      pToken->Get(newData.pluginDLLName,0);
      
      //Compile all child config data for the token
      for(uint childNum =0;childNum < pToken->GetNumChildren(); childNum++)
      {
        //Convert each child back to raw config string data
        string retString;
        if(parser.GenerateConfigString(pToken->GetChildToken(childNum),retString))
        {
          newData.pluginConfigData += retString;
        }
      }

      //Add the plugin data to the array
      pluginDataArray.push_back(newData);
    }
  }
 

}
Example #8
0
/*
** Read the options specified in the ini file.
**
*/
void MeasureNet::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	Measure::ReadOptions(parser, section);

	double value;
	const WCHAR* netName = nullptr;

	if (m_Net == NET_IN)
	{
		netName = L"NetInSpeed";
		value = GetRainmeter().GetGlobalOptions().netInSpeed;
	}
	else if (m_Net == NET_OUT)
	{
		netName = L"NetOutSpeed";
		value = GetRainmeter().GetGlobalOptions().netOutSpeed;
	}
	else // if (m_Net == NET_TOTAL)
	{
		netName = L"NetTotalSpeed";
		value = GetRainmeter().GetGlobalOptions().netInSpeed + GetRainmeter().GetGlobalOptions().netOutSpeed;
	}

	double maxValue = parser.ReadFloat(section, L"MaxValue", -1);
	if (maxValue == -1)
	{
		maxValue = parser.ReadFloat(section, netName, -1);
		if (maxValue == -1)
		{
			maxValue = value;
		}
	}

	m_Interface = parser.ReadInt(section, L"Interface", 0);

	m_Cumulative = parser.ReadBool(section, L"Cumulative", false);
	if (m_Cumulative)
	{
		GetRainmeter().SetNetworkStatisticsTimer();
	}

	if (maxValue == 0.0)
	{
		if (!m_LogMaxValue)
		{
			m_MaxValue = 1.0;
			m_LogMaxValue = true;
			m_MedianValues.clear();
		}
	}
	else
	{
		m_MaxValue = maxValue / 8;
		m_LogMaxValue = false;
	}
}
Example #9
0
void Seat::setCards(const char *c1, const char *c2)
{
	m_FirstCard.load(QString("gfx/deck/%1/%2.png")
		.arg(QString::fromStdString(config.get("ui_card_deck")))
		.arg(c1));
	
	m_SecondCard.load(QString("gfx/deck/%1/%2.png")
		.arg(QString::fromStdString(config.get("ui_card_deck")))
		.arg(c2));
}
Example #10
0
int main()
{
	list<string>::iterator itor;
	ConfigParser* cp = ConfigParser::instance();
	cp->loader(CONF_PATH);
	cout<<"log_level:"<<cp->getLogLevel()<<endl;
	cout<<"depth:"<<cp->getDepth()<<endl;
	cout<<"job_num:"<<cp->getJobNum()<<endl;
	cout<<"seed:"<<cp->getUrlSeed()<<endl;
	
	cout<<"module_path:"<<cp->getModulePath()<<endl;
	list<string> module_name = cp->getModuleNames();
	itor = module_name.begin();
	while(itor!=module_name.end())
    {
	  cout<< "module_name:"<<*itor<<endl;
	  itor++;
    } 

	list<string> file_type = cp->getFileTypes();
	itor = file_type.begin();
	while(itor!=file_type.end())
    {
	  cout<< "file_type:"<<*itor<<endl;
	  itor++;
    } 
	ConfigParser::release();
	return 0;
}
Example #11
0
// read in the HOG settings
bool cv::base::HOGSettings::configure(ConfigParser& cfg) {
  bool success = true;
  cells_per_block_w = cfg.get("cells_per_block_w", 2, "HOG");
  cells_per_block_h = cfg.get("cells_per_block_h", 2, "HOG");
  cells_per_image_w = cfg.get("cells_per_image_w", 8, "HOG");
  cells_per_image_h = cfg.get("cells_per_image_h", 8, "HOG");
  num_orientations = cfg.get("num_orientations", 9, "HOG");
  min_scale = cfg.get("min_scale", 16);
  max_scale = cfg.get("max_scale", 64);
  return success;
}
void ProjectCreatedGenerator::run()
{
    qDebug() << "EmailGenerator: Generating Project Created Email";

    ProjectCreatedEmail email_message;
    email_message.ParseFromString(this->protoBody.toStdString());

    ConfigParser settings;
    QString error = "";
    QSharedPointer<MySQLHandler> db = MySQLHandler::getInstance();
    QSharedPointer<Email> email = QSharedPointer<Email>(new Email());
    QSharedPointer<Project> project = ProjectDao::getProject(db, email_message.project_id());
    QSharedPointer<Organisation> org = QSharedPointer<Organisation>();

    if (project.isNull()) {
        error = "Project created generation failed. Unable to find  project with id " +
                QString::number(email_message.project_id());
    } else {
        qDebug() << "EmailGenerator: Project Created Email Debugging: " << QString::number(email_message.project_id());
        org = OrganisationDao::getOrg(db, project->organisationid());

        if (org.isNull()) {
            error = "Project created generation failed. Unable to find org with id " +
                    QString::number(project->organisationid());
        }
    }

    if (error.compare("") == 0) {
        QString siteLocation = settings.get("site.url");
        QString siteName = settings.get("site.name");

        ctemplate::TemplateDictionary dict("projectCreated");
        dict.SetValue("SITE_NAME", siteName.toStdString());
        QString projectView = siteLocation + "project/" + QString::number(project->id()) + "/view/";
        dict.SetValue("PROJECT_VIEW", projectView.toStdString());
        dict.SetValue("PROJECT_TITLE", project->title());
        QString orgView = siteLocation + "org/" + QString::number(org->id()) + "/profile/";
        dict.SetValue("ORG_VIEW", orgView.toStdString());
        dict.SetValue("ORG_NAME", org->name());
        std::string email_body;
        QString template_location = QString(TEMPLATE_DIRECTORY) + "emails/project-created.tpl";
        ctemplate::ExpandTemplate(template_location.toStdString(), ctemplate::DO_NOT_STRIP, &dict, &email_body);

        email->setSender(settings.get("site.system_email_address"));
        email->addRecipient(QString::fromStdString(email_message.recipient_email()));
        email->setSubject(siteName + ": Project Created");
        email->setBody(QString::fromUtf8(email_body.c_str()));
    } else {
        email = this->generateErrorEmail(error);
    }

    this->emailQueue->insert(email, currentMessage);
}
Example #13
0
  void test_parse_line() {
    ConfigParser cfg;

    ConfigParser::Entry* e = cfg.parse_line("rbx.blah = 8");
    TS_ASSERT_EQUALS(std::string("rbx.blah"), e->variable);
    TS_ASSERT_EQUALS(std::string("8"), e->value);

    // try again with trailing whitespace
    e = cfg.parse_line("rbx.blah = 8 \t \t");
    TS_ASSERT_EQUALS(std::string("rbx.blah"), e->variable);
    TS_ASSERT_EQUALS(std::string("8"), e->value);
  }
Example #14
0
int main(int argc, char **argv) {
  boost::mpi::environment env(argc, argv);
  std::shared_ptr<boost::mpi::communicator> world(new
                                                  boost::mpi::communicator());

  string config_file;

  if (IsMaster(world)) {
    ros::init(argc, argv, "real_test");
    ros::NodeHandle nh("~");
    nh.param("config_file", config_file, std::string(""));
  }

  ObjectRecognizer object_recognizer(world);

  // All processes should wait until master has loaded params.
  world->barrier();
  broadcast(*world, config_file, kMasterRank);

  ConfigParser parser;
  parser.Parse(config_file);

  RecognitionInput input;
  input.x_min = parser.min_x;
  input.x_max = parser.max_x;
  input.y_min = parser.min_y;
  input.y_max = parser.max_y;
  input.table_height = parser.table_height;
  input.camera_pose = parser.camera_pose;
  input.model_names = parser.ConvertModelNamesInFileToIDs(
                        object_recognizer.GetModelBank());

  boost::filesystem::path config_file_path(config_file);
  input.heuristics_dir = ros::package::getPath("sbpl_perception") +
                         "/heuristics/" + config_file_path.stem().string();

  // Objects for storing the point clouds.
  pcl::PointCloud<PointT>::Ptr cloud_in(new PointCloud);

  // Read the input PCD file from disk.
  if (pcl::io::loadPCDFile<PointT>(parser.pcd_file_path.c_str(),
                                   *cloud_in) != 0) {
    cerr << "Could not find input PCD file!" << endl;
    return -1;
  }

  input.cloud = cloud_in;

  vector<ContPose> detected_poses;
  object_recognizer.LocalizeObjects(input, &detected_poses);
  return 0;
}
void TaskScoreEmailGenerator::run()
{
    qDebug() << "EmailGenerator - Generating TaskScoreEmail";
    TaskScoreEmail email_message;
    email_message.ParseFromString(this->protoBody.toStdString());

    QSharedPointer<Email> email = QSharedPointer<Email>(new Email());
    ConfigParser settings;

    QStringList admins = settings.get("mail.admin_emails").split(",");
    foreach(QString admin, admins) {
        email->addRecipient(admin.trimmed());
    }
MessagingClient::MessagingClient()
{
    ConfigParser mParser;
    this->hostname = mParser.get("messaging.host");
    this->port = mParser.get("messaging.port").toInt();
    this->user = mParser.get("messaging.mess_user");
    this->pass = mParser.get("messaging.mess_pass");
    this->vhost = mParser.get("messaging.virtualhost");
    this->finished = false;
    this->conn = NULL;
    this->mQueue = NULL;
    this->mExchange = NULL;
}
Example #17
0
bool Game::LoadConfig(const std::string& str)
{
	// default options
	options_.fps = APP_FPS;
	options_.verbosity = DEFAULT_VERBOSITY;

	options_.panel_on_top = 1;

	ConfigParser config;
	if (!config.LoadFromFile(str.c_str()))
	{
		printf("info: config file '%s' not found, using default configuration\n", str.c_str());
		return false;
	}
	printf("info: configuration '%s' loaded\n", str.c_str());

    // Engine options
    config.SeekSection("Engine");
    config.ReadItem("fps", options_.fps);
    config.ReadItem("verbosity", options_.verbosity);
    Log::SetVerboseLevel(options_.verbosity);

    Output << "verbose: " << options_.verbosity << lEnd;

	// Game options
    config.SeekSection("Settings");
    config.ReadItem("panel_on_top", options_.panel_on_top);
	bool music = false;
	if (config.ReadItem("enable_music", music) && !music)
	{
		SoundSystem::GetInstance().EnableMusic(false);
	}

	return true;
}
Example #18
0
bool MainDialog::ReadDiskProfiles()
{
  wxStandardPaths stdPaths;
  wxFileName dirProcess;

  // Get the main profile directory
  dirProcess.AssignDir(stdPaths.GetDataDir());
  dirProcess.AppendDir("Profiles");
  wxString profileDir = dirProcess.GetPath();

  // Test if the directory exists
  if(!wxDir::Exists(profileDir))
  {
    wxLogWarning("Unable to find profiles directory %s", profileDir.c_str());
    return false;
  }

  // Get the profile filenames
  wxArrayString profileFileNameArray;
  if(wxDir::GetAllFiles(profileDir, &profileFileNameArray, wxString(wxT("*.xni")), wxDIR_FILES) == 0)
  {
    wxLogWarning("No profiles in directory %s", profileDir.c_str());
    return false;
  }

  // Loop for all profiles
  diskProfiles.clear();
  for(uint i=0; i<profileFileNameArray.GetCount(); i++)
  {
    // Load the profile data
    ConfigParser parserLoader;
    if(parserLoader.Parse(string(profileFileNameArray[i].c_str())))
    {
      // Add to the profile array
      diskProfiles.push_back(*parserLoader.GetRootToken());
    }
  } 

  // Should also parse the user data directory
  //wxStandardPaths::GetUserDataDir

  // Check that some profiles were valid
  if(diskProfiles.size() <= 0)
  {
    wxLogWarning("No valid profiles loaded in directory %s", profileDir.c_str());
    return false;
  }

  return true;
}
Example #19
0
void createFiles(ConfigParser &config) {
    FeaturesComplexNetwork cn;
    SunDatabaseReader reader(config.getDatabasePath());

    KFoldDatabaseReader kfold(reader, config.getKFoldTrainPercentage());

    kfold.save(config.getKFoldFilePath());

    KFoldDatabaseReader::PathDatabaseReader testSet = kfold.getTestReader();

    RegionChooser chooser(testSet);
    chooser.save(config.getChoosenRegionFilePath());

}
Example #20
0
// Deprecated!
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
{
	NULLCHECK(section);
	NULLCHECK(option);
	NULLCHECK(defValue);

	ConfigParser* parser = GetRainmeter().GetCurrentParser();
	if (parser)
	{
		return parser->ReadString(section, option, defValue, false).c_str();
	}

	return defValue;
}
Example #21
0
/*
** Read the common options specified in the ini file. The inherited classes must
** call this base implementation if they overwrite this method.
**
*/
void Section::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
	if (updateDivider != m_UpdateDivider)
	{
		m_UpdateCounter = m_UpdateDivider = updateDivider;
	}

	m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);

	m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);

	const std::wstring& group = parser.ReadString(section, L"Group", L"");
	InitializeGroup(group);
}
    virtual void SetUp()
    {
        //-- Read test data
        configParser.parse("../../data/robots/Test_robot.xml");

        //-- Create gait table
        gaitTable = new GaitTable(GAIT_TABLE_FILEPATH);

        //-- Create robot, simulated type
        robotInterface = createModularRobotInterface( "simulated", configParser);

        //-- Create sinusoidal oscillators with the test parameters
        for ( int i = 0; i < configParser.getNumModules(); i++)
            oscillators.push_back(new SinusoidalOscillator());
    }
Example #23
0
/*
** Read the options specified in the ini file.
**
*/
void MeasureUptime::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	Measure::ReadOptions(parser, section);

	m_Format = parser.ReadString(section, L"Format", L"%4!i!d %3!i!:%2!02i!");

	if (m_Format.find(L"%4") == std::wstring::npos)
	{
		m_AddDaysToHours = 0!=parser.ReadInt(section, L"AddDaysToHours", 1);
	}
	else
	{
		m_AddDaysToHours = false;
	}
}
Example #24
0
void ConfigData::ReadTimerConfigData(ConfigParser &parser)
{
  //Get if the outer log section
  const ConfigToken * timerToken = parser.GetToken("TimerLog");
  if(!timerToken)
  {
    return;
  }
  const ConfigToken *timerTestToken;

  //Get if the log is enabled
  timerTestToken = timerToken->GetChildToken("LogEnabled");
  if(timerTestToken)
  { 
    timerTestToken->Get(timerLogEnabled);
  }

  //Get if we log the state on render calls 
  timerTestToken = timerToken->GetChildToken("LogCutoff");
  if(timerTestToken)
  { 
    timerTestToken->Get(timerLogCutOff);
  }


}
Example #25
0
/*
** Read the options specified in the ini file.
**
*/
void MeasureRegistry::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	Measure::ReadOptions(parser, section);

	const WCHAR* keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER").c_str();
	if (_wcsicmp(keyname, L"HKEY_CURRENT_USER") == 0)
	{
		m_HKey = HKEY_CURRENT_USER;
	}
	else if (_wcsicmp(keyname, L"HKEY_LOCAL_MACHINE") == 0)
	{
		m_HKey = HKEY_LOCAL_MACHINE;
	}
	else if (_wcsicmp(keyname, L"HKEY_CLASSES_ROOT") == 0)
	{
		m_HKey = HKEY_CLASSES_ROOT;
	}
	else if (_wcsicmp(keyname, L"HKEY_CURRENT_CONFIG") == 0)
	{
		m_HKey = HKEY_CURRENT_CONFIG;
	}
	else if (_wcsicmp(keyname, L"HKEY_PERFORMANCE_DATA") == 0)
	{
		m_HKey = HKEY_PERFORMANCE_DATA;
	}
	else if (_wcsicmp(keyname, L"HKEY_DYN_DATA") == 0)
	{
		m_HKey = HKEY_DYN_DATA;
	}
	else
	{
		LogErrorF(this, L"RegHKey=%s is not valid", keyname);
	}

	m_RegKeyName = parser.ReadString(section, L"RegKey", L"");
	m_RegValueName = parser.ReadString(section, L"RegValue", L"");

	if (m_MaxValue == 0.0)
	{
		m_MaxValue = 1.0;
		m_LogMaxValue = true;
	}

	// Try to open the key
	if (m_RegKey) RegCloseKey(m_RegKey);
	RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
}
Example #26
0
/*
** Read the common options specified in the ini file. The inherited classes must
** call this base implementation if they overwrite this method.
**
*/
void Measure::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	bool oldOnChangeActionEmpty = m_OnChangeAction.empty();

	Section::ReadOptions(parser, section);

	// Clear substitutes to prevent from being added more than once.
	if (!m_Substitute.empty())
	{
		m_Substitute.clear();
	}

	m_Invert = parser.ReadBool(section, L"InvertMeasure", false);

	m_Disabled = parser.ReadBool(section, L"Disabled", false);
	m_Paused = parser.ReadBool(section, L"Paused", false);

	m_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue);
	m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue);

	m_IfActions.ReadOptions(parser, section);

	// The first time around, we read the conditions here. Subsequent rereads will be done in
	// Update() if needed.
	if (!m_Initialized)
	{
		m_IfActions.ReadConditionOptions(parser, section);
	}

	m_OnChangeAction = parser.ReadString(section, L"OnChangeAction", L"", false);

	m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0);

	m_RegExpSubstitute = parser.ReadBool(section, L"RegExpSubstitute", false);
	std::wstring subs = parser.ReadString(section, L"Substitute", L"");
	if (!subs.empty())
	{
		if ((subs[0] != L'"' || subs[subs.length() - 1] != L'\'') &&
			(subs[0] != L'\'' || subs[subs.length() - 1] != L'"'))
		{
			// Add quotes since they are removed by the GetProfileString
			subs.insert(0, 1, L'"');
			subs += L'"';
		}
		if (!ParseSubstitute(subs))
		{
			LogErrorF(this, L"Measure: Invalid Substitute=%s", subs.c_str());
		}
	}

	if (m_Initialized &&
		oldOnChangeActionEmpty && !m_OnChangeAction.empty())
	{
		DoChangeAction(false);
	}
}
Example #27
0
  void test_get_section() {
    std::istringstream stream;

    stream.str("rbx.test.blah = 8\nrbx.test.foo = fun\nrbx.crazy = true");

    ConfigParser cfg;

    cfg.import_stream(stream);

    ConfigParser::EntryList* l = cfg.get_section("rbx.test");

    TS_ASSERT_EQUALS(l->size(), (unsigned int)2);
    TS_ASSERT_EQUALS(l->at(0)->variable, "rbx.test.blah");
    TS_ASSERT_EQUALS(l->at(1)->variable, "rbx.test.foo");

    delete l;
  }
/*
** Read the options specified in the ini file.
**
*/
void MeasureMemory::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	double oldMaxValue = m_MaxValue;
	Measure::ReadOptions(parser, section);
	m_MaxValue = oldMaxValue;

	m_Total = parser.ReadBool(section, L"Total", false);
}
Example #29
0
void buildCN(ConfigParser &config ){
    FeaturesComplexNetwork cn;
    QList<const FeatureFactoryAbstract *> factories = config.getFactories();
    KFoldDatabaseReader kfold(config.getKFoldFilePath());

    KFoldDatabaseReader::PathDatabaseReader trainSet = kfold.getTrainReader();

    if(config.getNumThreads() <= 1) {
        ComplexNetworkConstructor constructor(cn, trainSet, factories);
        constructor.build();
    }else{
        ComplexNetworkConstructorP constructor(cn, trainSet, factories, config.getNumThreads());
        constructor.build();
    }
    cn.refreshCache();
    cn.save(config.getCnOutput().toStdString().c_str());
}
Example #30
0
ExtmethodFace::ExtmethodFace(const ConfigParser &parent_config,
                             const string &name) : _name(name) {

    vector<boost::filesystem::path> libs = parent_config.getListOfPaths("libs");
    const string name_func_create = name + "_create";
    const string name_func_destroy = name + "_destroy";
    stringstream err_msg;

    bool fail = true;
    for (const boost::filesystem::path &lib_path: libs) {
        // Load the shared library
        _lib_handle = dlopen(lib_path.string().c_str(), RTLD_NOW);
        if (_lib_handle == NULL) {
            cerr << "Cannot load library: " << dlerror() << '\n';
            throw runtime_error("Extmethod: Cannot load library");
        }

        // Load the extmethod's create and destroy functions
        // The (clumsy) cast conforms with the ISO C standard and will
        // avoid any compiler warnings.
        bool found = true;
        {
            dlerror(); // Reset errors
            *(void **) (&_create) = dlsym(_lib_handle, name_func_create.c_str());
            const char* dlsym_error = dlerror();
            if (dlsym_error) {
                err_msg << "Failed loading '" << name_func_create << "' in "
                        << lib_path << ": " << dlsym_error << endl;
                found = false;
            }
        }
        {
            dlerror(); // Reset errors
            *(void **) (&_destroy) = dlsym(_lib_handle, name_func_destroy.c_str());
            const char* dlsym_error = dlerror();
            if (dlsym_error) {
                err_msg << "Failed loading '" << name_func_destroy << "' in "
                        << lib_path << ": " << dlsym_error << endl;
                found = false;
            }
        }
        if (found) {
            fail = false;
            break;
        } else {
            dlerror(); // Reset errors
            if (dlclose(_lib_handle)) {
                cerr << dlerror() << endl;
                throw runtime_error("Extmethod: Cannot close library");
            }
        }
    }
    if (fail) {
        err_msg << "Extmethod: Cannot find '" << _name << "':" << endl;
        throw ExtmethodNotFound(err_msg.str());
    }
    _implementation = _create();
}