Skip to content

Instantly share code, notes, and snippets.

@aggieben
Created June 10, 2009 13:08
Show Gist options
  • Save aggieben/127197 to your computer and use it in GitHub Desktop.
Save aggieben/127197 to your computer and use it in GitHub Desktop.
#include <istream>
#include <map>
#include <string>
#include <sstream>
class text_config
: public std::map<std::string, std::map<std::string, std::string> >
{
public:
friend std::istream& operator>>(std::istream&, text_config&);
friend std::ostream& operator<<(std::ostream&, text_config&);
template <typename Ty>
void get(std::string section, std::string key, Ty& out)
{
std::stringstream ss((*this)[section][key]);
ss >> out;
}
template <typename Ty>
void set(std::string section, std::string key, Ty val)
{
std::stringstream ss;
ss << val;
(*this)[section][key] = ss.str();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment