shared_ptr
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 03 May 2015 23:41:43 +0200
changeset 10145b45ef7751
parent 9 598a575ae57f
child 11 870b868b6b57
shared_ptr
c++/parameter-lister/CLI.cpp
c++/parameter-lister/info/globalcode/parameterLister/OutputModule.h
c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h
     1.1 --- a/c++/parameter-lister/CLI.cpp	Sun May 03 22:19:03 2015 +0200
     1.2 +++ b/c++/parameter-lister/CLI.cpp	Sun May 03 23:41:43 2015 +0200
     1.3 @@ -3,6 +3,7 @@
     1.4  #include <vector>
     1.5  #include <algorithm>
     1.6  #include <boost/optional.hpp>
     1.7 +#include <memory>
     1.8  
     1.9  #include "info/globalcode/parameterLister/terminalCodes/TerminalCodes.h"
    1.10  #include "info/globalcode/parameterLister/OutputModule.h"
    1.11 @@ -24,6 +25,9 @@
    1.12  	}
    1.13  }
    1.14  
    1.15 +void process(shared_ptr<OutputModule> om) {
    1.16 +	om->process(cout);
    1.17 +}
    1.18  
    1.19  }
    1.20  }
    1.21 @@ -62,15 +66,16 @@
    1.22  			cout << "ENV: " << envName << " is missing" << endl;
    1.23  		}
    1.24  	}
    1.25 -	
    1.26 +
    1.27  	{
    1.28 -		OutputModule om;
    1.29 -		TerminalOutputModule tom;
    1.30 -		
    1.31 -		om.process(cout);
    1.32 -		tom.process(cout);
    1.33 +		shared_ptr<OutputModule> om(new OutputModule());
    1.34 +		shared_ptr<TerminalOutputModule> tom(new TerminalOutputModule());
    1.35 +		shared_ptr<OutputModule> o(new TerminalOutputModule());
    1.36 +
    1.37 +		process(om);
    1.38 +		process(tom);
    1.39 +		process(o);
    1.40  	}
    1.41  
    1.42 -
    1.43  	return 0;
    1.44 -}
    1.45 \ No newline at end of file
    1.46 +}
     2.1 --- a/c++/parameter-lister/info/globalcode/parameterLister/OutputModule.h	Sun May 03 22:19:03 2015 +0200
     2.2 +++ b/c++/parameter-lister/info/globalcode/parameterLister/OutputModule.h	Sun May 03 23:41:43 2015 +0200
     2.3 @@ -12,7 +12,7 @@
     2.4  	OutputModule();
     2.5  	OutputModule(const OutputModule& orig);
     2.6  	virtual ~OutputModule();
     2.7 -	void process(std::ostream &output);
     2.8 +	virtual void process(std::ostream &output);
     2.9  private:
    2.10  
    2.11  };
     3.1 --- a/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h	Sun May 03 22:19:03 2015 +0200
     3.2 +++ b/c++/parameter-lister/info/globalcode/parameterLister/TerminalOutputModule.h	Sun May 03 23:41:43 2015 +0200
     3.3 @@ -3,16 +3,18 @@
     3.4  
     3.5  #include <iostream>
     3.6  
     3.7 +#include "OutputModule.h"
     3.8 +
     3.9  namespace info {
    3.10  namespace globalcode {
    3.11  namespace parameterLister {
    3.12  
    3.13 -class TerminalOutputModule {
    3.14 +class TerminalOutputModule : public OutputModule {
    3.15  public:
    3.16  	TerminalOutputModule();
    3.17  	TerminalOutputModule(const TerminalOutputModule& orig);
    3.18  	virtual ~TerminalOutputModule();
    3.19 -	void process(std::ostream &output);
    3.20 +	virtual void process(std::ostream &output);
    3.21  private:
    3.22  
    3.23  };