Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.