Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <memory>
- #include <iostream>
- #include <ostream>
- class IConfig
- {
- public:
- virtual ~IConfig() { }
- virtual std::ostream& output(std::ostream& o) const { return o; }
- friend std::ostream& operator<<(std::ostream& o, const IConfig &c)
- {
- return o << c.output(o);
- }
- };
- class MultiConfig : public IConfig
- {
- public:
- virtual ~MultiConfig() { }
- virtual std::ostream& output(std::ostream& o) const
- {
- for (std::vector<std::string>::const_iterator cit = m_vals.begin();
- cit != m_vals.end(); cit ++)
- o << (*cit) << std::endl;
- return o;
- }
- protected:
- std::vector<std::string> m_vals;
- };
- class SingleConfig : public IConfig
- {
- public:
- virtual ~SingleConfig() { }
- virtual std::ostream& output(std::ostream& o) const
- {
- return o << m_val;
- }
- protected:
- std::string m_val;
- };
- class IndexConfig : public IConfig
- {
- public:
- virtual ~IndexConfig() { }
- virtual std::ostream& output(std::ostream& o) const
- {
- return o << m_val;
- }
- protected:
- std::string m_val;
- int m_index;
- };
- class IpConfig : public SingleConfig
- {
- public:
- IpConfig() { m_val = "8.8.8.8"; }
- virtual ~IpConfig() { }
- };
- using ConfigPtr = std::shared_ptr<IConfig>;
- using Configs = std::vector<ConfigPtr>;
- int main(int argc, char* argv[])
- {
- ConfigPtr c(new IpConfig());
- Configs s;
- s.push_back(c);
- for (Configs::const_iterator cit = s.begin(); cit != s.end(); cit++)
- std::cout << (**cit) << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment