console_streams.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <iostream>
00014 #include <string>
00015 #include <ecl/devices/console.hpp>
00016 #include <ecl/streams/text_stream.hpp>
00017 #include <ecl/streams/console_streams.hpp>
00018 #include <ecl/streams/manipulators/end_of_line.hpp>
00019 
00020 /*****************************************************************************
00021 ** Using
00022 *****************************************************************************/
00023 
00024 using std::string;
00025 using ecl::OConsole;
00026 using ecl::IConsole;
00027 using ecl::endl;
00028 using ecl::TextStream;
00029 using ecl::IConsoleStream;
00030 using ecl::OConsoleStream;
00031 
00032 /*****************************************************************************
00033 ** Main
00034 *****************************************************************************/
00035 
00036 int main(int argc, char** argv) {
00037 
00038         bool test_istreams = false;
00039 
00040     std::cout << std::endl;
00041     std::cout << "***********************************************************" << std::endl;
00042     std::cout << "                   OConsole Stream" << std::endl;
00043     std::cout << "***********************************************************" << std::endl;
00044     std::cout << std::endl;
00045 
00046     std::cout << "These can't really be tested very easily by google tests, so" << std::endl;
00047     std::cout << "it's just provided here as a demo, but functionally is a" << std::endl;
00048     std::cout << "unit test (requiring human approval)." << std::endl;
00049     std::cout << std::endl;
00050 
00051     OConsoleStream ostream;
00052 
00053     std::cout << "Streaming char." << std::endl;
00054     ostream << 'c' << '\n';
00055     std::cout << "Streaming char string." << std::endl;
00056     ostream << "Dude\n";
00057     std::cout << "Streaming string." << std::endl;
00058     string dude("dude_string\n");
00059     ostream << dude;
00060     std::cout << "Streaming integers." << std::endl;
00061     short si = 1;
00062     ostream << si << '\n';
00063     int i = 2;
00064     ostream << i << '\n';
00065     long l = 3;
00066     ostream << l << '\n';
00067     long long ll = 4;
00068     ostream << ll << '\n';
00069     unsigned short us = 5;
00070     ostream << us << '\n';
00071     unsigned int ui = 6;
00072     ostream << ui << '\n';
00073     unsigned long ul = 77;
00074     ostream << ul << '\n';
00075     unsigned long long ull = 8888;
00076     ostream << ull << '\n';
00077     std::cout << "Streaming temporary integers." << std::endl;
00078     ostream << 77 << '\n';
00079     std::cout << "Streaming a boolean." << std::endl;
00080     bool test = true;
00081     ostream << test << '\n';
00082     ostream << false << '\n';
00083     std::cout << "Streaming floating point values." << std::endl;
00084     float f = 32.1;
00085     double d = -33.3;
00086     ostream << f << '\n';
00087     ostream << d << '\n';
00088 
00089     std::cout << "Flushing" << std::endl;
00090     ostream.flush();
00091 
00092     std::cout << std::endl;
00093     std::cout << "***********************************************************" << std::endl;
00094     std::cout << "                OConsole Manipulators" << std::endl;
00095     std::cout << "***********************************************************" << std::endl;
00096     std::cout << std::endl;
00097 
00098     ostream << "dude with an ecl::endl" << endl;
00099 
00100     if ( test_istreams ) {
00101                 std::cout << std::endl;
00102                 std::cout << "***********************************************************" << std::endl;
00103                 std::cout << "                   IConsole Stream" << std::endl;
00104                 std::cout << "***********************************************************" << std::endl;
00105                 std::cout << std::endl;
00106 
00107                 char c;
00108                 string response;
00109                 IConsoleStream istream;
00110         //      TextStream<IConsole> istream;
00111 
00112                 std::cout << "Enter a char." << std::endl;
00113                 istream >> c;
00114                 std::cout << "Char read: " << c << std::endl;
00115                 std::cout << "Enter a word." << std::endl;
00116                 istream >> response;
00117                 std::cout << "Word read: " << response << std::endl;
00118                 std::cout << "Enter a short: " << std::endl;
00119                 istream >> si;
00120                 if ( istream.fail() ) {
00121                         std::cout << "Short read failed: " << istream.errorStatus().what() << std::endl;
00122                 } else {
00123                         std::cout << "Short read: " << si << std::endl;
00124                 }
00125                 std::cout << "Enter a bool: " << std::endl;
00126                 istream >> test;
00127                 if ( istream.fail() ) {
00128                         std::cout << "Bool read failed: " << istream.errorStatus().what() << std::endl;
00129                 } else {
00130                         std::cout << "Bool read: ";
00131                         if ( test ) {
00132                                 std::cout << "true" << std::endl;
00133                         } else {
00134                                 std::cout << "false" << std::endl;
00135                         }
00136                 }
00137                 std::cout << "Enter a double:" << std::endl;
00138                 istream >> d;
00139                 if ( istream.fail() ) {
00140                         std::cout << "Double read failed: " << istream.errorStatus().what() << std::endl;
00141                 } else {
00142                         std::cout << "Double read: " << d << std::endl;
00143                 }
00144     }
00145     std::cout << std::endl;
00146     std::cout << "***********************************************************" << std::endl;
00147     std::cout << "                      Passed" << std::endl;
00148     std::cout << "***********************************************************" << std::endl;
00149     std::cout << std::endl;
00150 
00151         return 0;
00152 }


ecl_streams
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:18:12