Make ConfigTag::items private

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11956 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
danieldg 2009-10-22 22:29:35 +00:00
parent 4663fd393f
commit efc75198de
4 changed files with 39 additions and 11 deletions

View File

@ -37,24 +37,39 @@ typedef std::vector<std::string> file_cache;
*/ */
typedef std::pair<std::string, std::string> KeyVal; typedef std::pair<std::string, std::string> KeyVal;
struct CoreExport ConfigTag : public refcountbase /** Structure representing a single <tag> in config */
class CoreExport ConfigTag : public refcountbase
{ {
std::vector<KeyVal> items;
public:
const std::string tag; const std::string tag;
const std::string src_name; const std::string src_name;
const int src_line; const int src_line;
std::vector<KeyVal> items;
ConfigTag(const std::string& Tag, const std::string& file, int line)
: tag(Tag), src_name(file), src_line(line) {}
/** Get the value of an option, using def if it does not exist */
std::string getString(const std::string& key, const std::string& def = ""); std::string getString(const std::string& key, const std::string& def = "");
/** Get the value of an option, using def if it does not exist */
long getInt(const std::string& key, long def = 0); long getInt(const std::string& key, long def = 0);
/** Get the value of an option, using def if it does not exist */
double getFloat(const std::string& key, double def = 0); double getFloat(const std::string& key, double def = 0);
/** Get the value of an option, using def if it does not exist */
bool getBool(const std::string& key, bool def = false); bool getBool(const std::string& key, bool def = false);
/** Get the value of an option
* @param key The option to get
* @param value The location to store the value (unmodified if does not exist)
* @param allow_newline Allow newlines in the option (normally replaced with spaces)
* @return true if the option exists
*/
bool readString(const std::string& key, std::string& value, bool allow_newline = false); bool readString(const std::string& key, std::string& value, bool allow_newline = false);
std::string getTagLocation(); std::string getTagLocation();
/** Create a new ConfigTag, giving access to the private KeyVal item list */
static ConfigTag* create(const std::string& Tag, const std::string& file, int line,
std::vector<KeyVal>*&items);
private:
ConfigTag(const std::string& Tag, const std::string& file, int line);
}; };
/** An entire config file, built up of KeyValLists /** An entire config file, built up of KeyValLists

View File

@ -131,7 +131,7 @@ namespace irc
} }
} }
struct ConfigTag; class ConfigTag;
/** This class handles incoming connections on client ports. /** This class handles incoming connections on client ports.
* It will create a new User for every valid connection * It will create a new User for every valid connection
* and assign it a file descriptor. * and assign it a file descriptor.

View File

@ -59,7 +59,7 @@ enum RegistrationState {
/* Required forward declaration */ /* Required forward declaration */
class Channel; class Channel;
class UserResolver; class UserResolver;
struct ConfigTag; class ConfigTag;
class OperInfo; class OperInfo;
/** Holds information relevent to &lt;connect allow&gt; and &lt;connect deny&gt; tags in the config file. /** Holds information relevent to &lt;connect allow&gt; and &lt;connect deny&gt; tags in the config file.

View File

@ -84,7 +84,7 @@ struct Parser
unget(ch); unget(ch);
} }
bool kv() bool kv(std::vector<KeyVal>* items)
{ {
std::string key; std::string key;
nextword(key); nextword(key);
@ -138,7 +138,7 @@ struct Parser
break; break;
value.push_back(ch); value.push_back(ch);
} }
tag->items.push_back(KeyVal(key, value)); items->push_back(KeyVal(key, value));
return true; return true;
} }
@ -157,9 +157,10 @@ struct Parser
if (name.empty()) if (name.empty())
throw CoreException("Empty tag name"); throw CoreException("Empty tag name");
tag = new ConfigTag(name, current.filename, current.line); std::vector<KeyVal>* items;
tag = ConfigTag::create(name, current.filename, current.line, items);
while (kv()); while (kv(items));
if (name == "include") if (name == "include")
{ {
@ -376,6 +377,18 @@ std::string ConfigTag::getTagLocation()
return src_name + ":" + ConvToStr(src_line); return src_name + ":" + ConvToStr(src_line);
} }
ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*&items)
{
ConfigTag* rv = new ConfigTag(Tag, file, line);
items = &rv->items;
return rv;
}
ConfigTag::ConfigTag(const std::string& Tag, const std::string& file, int line)
: tag(Tag), src_name(file), src_line(line)
{
}
std::string OperInfo::getConfig(const std::string& key) std::string OperInfo::getConfig(const std::string& key)
{ {
std::string rv; std::string rv;