Exemplo n.º 1
0
bool rpi_configure_devices(TIniFile& file)
{
	TSection* sec = file["devices"];
	if(sec)
	{
		std::string str_aux;
		short       s_aux;
		TParam*     param;
		TSection*   sc_dev;
		TRPiDevice* dev;

		for(size_t i = 0; i < sec->size(); ++i)
		{
			param  = (*sec)[i];
			sc_dev = file[std::string("dev_") + param->name()];

			if(sc_dev)
			{
				param->value() >> s_aux;
				dev = new TRPiDevice(uav_id(s_aux));
				s_aux = UI_INVALID_ID;

				dev->name()    = param->name();
				dev->enabled() = false;
//				dev->enabled() = param->value().str().find("disabled") == std::string::npos;
				dev->kind()    = str2Kind((*sc_dev)["kind"]->value().str());
				if(dev->kind() == UI_INVALID_ID)
				{
					(*sc_dev)["kind"]->value() >> s_aux; dev->kind() = uav_id(s_aux);
				}
				(*sc_dev)["min"]->value()  >> dev->minimum();
				(*sc_dev)["max"]->value()  >> dev->maximum();

//				if(dev->kind() == UI_INVALID_ID)
//					dev->enabled() = false;

				Devices.insert(dev);
			}
			else
			{
				//-- TODO: No information for declared device!!!
			}
		}
Exemplo n.º 2
0
void TIniFile::saveFile(std::string strFilename)
{
	std::fstream file;

	file.open(trim(strFilename).c_str(), std::fstream::out | std::fstream::trunc);

	if(!file.is_open())
		return;

	std::map<std::string, TSection*>::iterator iter = m_mSections.begin();
	TParam* param = NULL;

	if(!m_strHeader.empty())
	{
		size_t      pos;
		std::string str_aux = m_strHeader;
		while((pos = str_aux.find('\n')) != std::string::npos)
		{
			file << "# " << str_aux.substr(0, pos) << std::endl;
			str_aux = str_aux.substr(pos + 1);
		}
		file << "# " << str_aux.substr(0, pos) << std::endl << std::endl;
	}

	while(iter != m_mSections.end())
	{
		if(iter->second)
		{
			if(iter != m_mSections.begin())
				file << std::endl;

			if(iter->second->comment().size())
			{
				size_t      pos;
				std::string comment = iter->second->comment();
				while((pos = comment.find('\n')) != std::string::npos)
				{
					file << "# " << comment.substr(0, pos) << std::endl;
					comment = comment.substr(pos + 1);
				}
				file << "# " << comment.substr(0, pos) << std::endl;
			}

			file << "[" << iter->second->name() << "]" << std::endl;
			for(size_t i = 0; i < iter->second->size(); ++i)
			{
				param = (*(iter->second))[i];
				if(param)
				{
					file << param->name() << "=" << param->value().str();
					if(param->comment().size())
						file << " # " << param->comment();
					file << std::endl;
				}
			}
		}

		++iter;
	}

	file.close();
}