I'm designing a C++ Decoder class for decoding a format, and would like some feedback on my design choice: I want the user to be able to provide input to the decoder by either supplying an array, a std::string or a file. Internally, the decoder will use std::ifstream or std::istringstream (by using a private pointer to a std::istream which they both derive from) as appropriate and call a templated, private Decode method. Here's a rough outline of the header file:
class Decoder {
public:
Decoder();
Decoder(const char* filename);
Decoder(const std::string& filename);
virtual ~Decoder();
void FromArray(const char* c);
void FromString(const std::string& s);
void OpenFromFile(const std::string& filename);
void Close();
Value Decode(); // Calls templated version
private:
std::istream* is;
template<typename InputStream>
Value Decode(InputStream is);
};
I also want to provide a custom Iterator class for the decoder. While I think this is an ok design, the rest of the project will have to conform to this design choice, so I'm wondering if there is a better/more flexible/sensible way to design what I'm looking for. Or maybe there is a C++ design pattern I don't know about? I tried searching the internet, but I'm not sure what to search for.