First, some mostly gratuitous background, which you can safely skip if you're not interested, or feel free to comment/give suggestions:
I am writing a configuration interface for a DAQ system which reads in text-based configuration files. Because of the large number of parameters which might need to be set and their grouping into a nice tree-like structure, I've created a ParameterNode class, which holds a map<string,ParameterNode*> of all that node's children (or branches, leaves, whatever). Then to store simple variables, there is a templated Parameter<class T> class which inherits from ParameterNode. This allows me to have arbitrarily complex parameter structures without having to re-write any of the iostream interface.
So here's the problem. My Parameter class looks like
Expand|Select|Wrap|Line Numbers
- template<class T> Parameter{
- public:
- Parameter(const T& val) : _val(T) {}
- ~Parameter() {}
- std::istream& ReadFrom(std::istream& in) { return in>>_val; }
- std::ostream& WriteTo(std::ostream& out) { return out<<_val; }
- private:
- T _val;
- };
Expand|Select|Wrap|Line Numbers
- template<> inline std::istream& Parameter<unsigned>::ReadFrom(std::istream& in)
- {
- in>>std::hex>>std::showbase>>_val>>std::noshowbase>>std::dec;
- }
Many thanks,
~Ben