Example #1
0
 /// Assert guard that ensures the `union_` property ain't nullptr.
 void _assert_not_null_union() const
   throw (base_exception)
 {
   if (this->union_ == nullptr)
     throw base_exception();
 }
Example #2
0
unsigned int conf_reader::read(const std::string & _filename, bool _clear)
{
	if (_filename != "") { filename = _filename; };
	if (filename != "")
	{
		try
		{
			ifstream cfile(filename.c_str());
			if (!cfile) throw base_exception();
			if (_clear) values.clear();
			// read the file line by line, ignoring comments.
			char inbuff[16*1024];
			while (cfile)
			{
				cfile.getline(inbuff, 16*1024);
				string in = inbuff;
				// truncate at the start of a comment.
				unsigned long int where = in.find("#");
				while (where != string::npos)
				{
					if (in[where-1] == '\\')
					{
						// comment char was escaped.. ignore.
						where = in.find("#",where+1);
					}
					else
					{
						// truncate the string at this point.
						in.erase(where);
						where = string::npos;
					};
				};
				// see if we can parse what's left.
				in = trim(in);
				unsigned long int split_point = in.find_first_of("\t ");
				if (split_point != string::npos)
				{
					// okay.. get the fields.
					pair arg;
					arg.first = gsub(trim(in.substr(0,split_point)),"\\#","#");
					arg.second = gsub(trim(in.substr(split_point)),"\\#","#");
					// is this an include directive?
					if (arg.first == "*INCLUDE")
					{
						read(arg.second,false);
					} 
					else if (arg.first != "")
					{
						values.insert(arg);
					};
				};
			};
		}
		catch (...)
		{
			cerr << "\nProblems reading configuration file \""
				<< filename << "\";\n\tdata may be incomplete." << endl;
		}
	};
	return values.size();
};