Modeco80/Cool Hello World code
Jump to navigation
Jump to search
// ==== Hello World Enterprise Edition ===
//
// (c) 2018 FakeCorp Ltd. All rights reserved.
//
// hwent.cc: Main entry point for the application.
#include <iostream>
#include <string>
#include <sstream>
using std::cout;
using std::endl;
using std::string;
using std::stringstream;
namespace HelloWorld {
class Stream {
public:
Stream(string str){
mp_stream << str; // Push str into the underlying stream.
}
void pushString(string str) { /* Push a string into the stream. */ mp_stream << str; }
string toString() { /* Return the resulting string buffer. */ return mp_stream.str(); }
private:
stringstream mp_stream;
};
class StreamWriter {
public:
virtual void writeStream(Stream& stream, string buffer) {}
};
class HelloWorldStreamWriter : public StreamWriter {
public:
void writeStream(Stream& stream, string buffer){
stream.pushString(buffer); // Push the string to the stream.
}
};
class HelloWorldApplication {
public:
int Run(){
Stream f_Stream("");
mp_Hw.writeStream(f_Stream, "Hello World!"); // Start the stream writer.
cout << f_Stream.toString() << endl; // Print the resulting stream buffer to the standard console output
return 0; // Return a successful exit code.
}
private:
HelloWorldStreamWriter mp_Hw;
};
}
int main(){
HelloWorld::HelloWorldApplication hwapp; // Initalize the application.
return hwapp.Run(); // Run the application.
}