Passing objects by referrence instead by value (#24)
diff --git a/INIReader.h b/INIReader.h
index 11f3191..e1db5c6 100644
--- a/INIReader.h
+++ b/INIReader.h
@@ -317,11 +317,11 @@
// Construct INIReader and parse given filename. See ini.h for more info
// about the parsing.
- INIReader(std::string filename);
+ explicit INIReader(const std::string& filename);
// Construct INIReader and parse given file. See ini.h for more info
// about the parsing.
- INIReader(FILE *file);
+ explicit INIReader(FILE *file);
// Return the result of ini_parse(), i.e., 0 on success, line number of
// first error on parse error, or -1 on file open error.
@@ -331,33 +331,33 @@
const std::set<std::string>& Sections() const;
// Get a string value from INI file, returning default_value if not found.
- std::string Get(std::string section, std::string name,
- std::string default_value) const;
+ std::string Get(const std::string& section, const std::string& name,
+ const std::string& default_value) const;
// Get an integer (long) value from INI file, returning default_value if
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
- long GetInteger(std::string section, std::string name, long default_value) const;
+ long GetInteger(const std::string& section, const std::string& name, long default_value) const;
// Get a real (floating point double) value from INI file, returning
// default_value if not found or not a valid floating point value
// according to strtod().
- double GetReal(std::string section, std::string name, double default_value) const;
+ double GetReal(const std::string& section, const std::string& name, double default_value) const;
// Get a single precision floating point number value from INI file, returning
// default_value if not found or not a valid floating point value
// according to strtof().
- float GetFloat(std::string section, std::string name, float default_value) const;
+ float GetFloat(const std::string& section, const std::string& name, float default_value) const;
// Get a boolean value from INI file, returning default_value if not found or if
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
// and valid false values are "false", "no", "off", "0" (not case sensitive).
- bool GetBoolean(std::string section, std::string name, bool default_value) const;
+ bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const;
protected:
int _error;
std::map<std::string, std::string> _values;
std::set<std::string> _sections;
- static std::string MakeKey(std::string section, std::string name);
+ static std::string MakeKey(const std::string& section, const std::string& name);
static int ValueHandler(void* user, const char* section, const char* name,
const char* value);
};
@@ -372,7 +372,7 @@
#include <cctype>
#include <cstdlib>
-inline INIReader::INIReader(std::string filename)
+inline INIReader::INIReader(const std::string& filename)
{
_error = ini_parse(filename.c_str(), ValueHandler, this);
}
@@ -392,13 +392,13 @@
return _sections;
}
-inline std::string INIReader::Get(std::string section, std::string name, std::string default_value) const
+inline std::string INIReader::Get(const std::string& section, const std::string& name, const std::string& default_value) const
{
std::string key = MakeKey(section, name);
return _values.count(key) ? _values.at(key) : default_value;
}
-inline long INIReader::GetInteger(std::string section, std::string name, long default_value) const
+inline long INIReader::GetInteger(const std::string& section, const std::string& name, long default_value) const
{
std::string valstr = Get(section, name, "");
const char* value = valstr.c_str();
@@ -408,7 +408,7 @@
return end > value ? n : default_value;
}
-inline double INIReader::GetReal(std::string section, std::string name, double default_value) const
+inline double INIReader::GetReal(const std::string& section, const std::string& name, double default_value) const
{
std::string valstr = Get(section, name, "");
const char* value = valstr.c_str();
@@ -417,7 +417,7 @@
return end > value ? n : default_value;
}
-inline float INIReader::GetFloat(std::string section, std::string name, float default_value) const
+inline float INIReader::GetFloat(const std::string& section, const std::string& name, float default_value) const
{
std::string valstr = Get(section, name, "");
const char* value = valstr.c_str();
@@ -426,7 +426,7 @@
return end > value ? n : default_value;
}
-inline bool INIReader::GetBoolean(std::string section, std::string name, bool default_value) const
+inline bool INIReader::GetBoolean(const std::string& section, const std::string& name, bool default_value) const
{
std::string valstr = Get(section, name, "");
// Convert to lower case to make string comparisons case-insensitive
@@ -439,7 +439,7 @@
return default_value;
}
-inline std::string INIReader::MakeKey(std::string section, std::string name)
+inline std::string INIReader::MakeKey(const std::string& section, const std::string& name)
{
std::string key = section + "=" + name;
// Convert to lower case to make section/name lookups case-insensitive