| 1 | // 
 | 
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
| 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
| 6 | // 
 | 
|---|
| 7 | // io2.c -- 
 | 
|---|
| 8 | // 
 | 
|---|
| 9 | // Author           : Peter A. Buhr
 | 
|---|
| 10 | // Created On       : Wed Mar  2 16:56:02 2016
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Thu May 24 21:17:41 2018
 | 
|---|
| 13 | // Update Count     : 103
 | 
|---|
| 14 | // 
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <fstream>
 | 
|---|
| 17 | 
 | 
|---|
| 18 | int main() {
 | 
|---|
| 19 |         _Bool b;                                                                                        // basic types
 | 
|---|
| 20 |         char c;
 | 
|---|
| 21 |         signed char sc;
 | 
|---|
| 22 |         unsigned char usc;
 | 
|---|
| 23 |         short int si;
 | 
|---|
| 24 |         unsigned short int usi;
 | 
|---|
| 25 |         int i;
 | 
|---|
| 26 |         unsigned int ui;
 | 
|---|
| 27 |         long int li;
 | 
|---|
| 28 |         unsigned long int uli;
 | 
|---|
| 29 |         long long int lli;
 | 
|---|
| 30 |         unsigned long long int ulli;
 | 
|---|
| 31 |         float f;
 | 
|---|
| 32 |         double d;
 | 
|---|
| 33 |         long double ld;
 | 
|---|
| 34 |         float _Complex fc;
 | 
|---|
| 35 |         double _Complex dc;
 | 
|---|
| 36 |         long double _Complex ldc;
 | 
|---|
| 37 |         enum { size = 10 };
 | 
|---|
| 38 |         char s1[size], s2[size];
 | 
|---|
| 39 | 
 | 
|---|
| 40 |         ifstream in = { "io.data" };                                            // create / open file
 | 
|---|
| 41 | 
 | 
|---|
| 42 |         sout | "input bacis types" | endl;
 | 
|---|
| 43 |         in       | b                                                                                    // boolean
 | 
|---|
| 44 |                  | c | sc | usc                                                                 // character
 | 
|---|
| 45 |                  | si | usi | i | ui | li | uli | lli | ulli    // integral
 | 
|---|
| 46 |                  | f | d | ld                                                                   // floating point
 | 
|---|
| 47 |                  | fc | dc | ldc                                                                // floating-point complex
 | 
|---|
| 48 |                  | cstr( s1 ) | cstr( s2, size );                               // C string, length unchecked and checked
 | 
|---|
| 49 |         sout | endl;
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         sout | "output basic types" | endl;
 | 
|---|
| 52 |         sout | b | endl                                                                         // boolean
 | 
|---|
| 53 |                  | c | ' ' | sc | ' ' | usc | endl                              // character
 | 
|---|
| 54 |                  | si | usi | i | ui | li | uli | lli | ulli | endl // integral
 | 
|---|
| 55 |                  | f | d | ld | endl                                                    // floating point
 | 
|---|
| 56 |                  | fc | dc | ldc | endl;                                                // complex
 | 
|---|
| 57 |         sout | endl;
 | 
|---|
| 58 | 
 | 
|---|
| 59 |         sout | "tuples" | endl;
 | 
|---|
| 60 |         [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
 | 
|---|
| 61 |         sout | t1 | t2 | endl;                                                          // print tuple
 | 
|---|
| 62 |         sout | endl;
 | 
|---|
| 63 | 
 | 
|---|
| 64 |         sout | "toggle separator" | endl;
 | 
|---|
| 65 |         sout | f | "" | d | "" | ld | endl                                      // floating point without separator
 | 
|---|
| 66 |                  | sepDisable | fc | dc | ldc | endl                    // complex without separator
 | 
|---|
| 67 |                  | fc | sepOn | dc | ldc | endl                                 // local separator add
 | 
|---|
| 68 |                  | sepEnable | fc | dc | ldc | endl                             // complex with separator
 | 
|---|
| 69 |                  | fc | sepOff | dc | ldc | endl                                // local separator removal
 | 
|---|
| 70 |                  | s1 | sepOff | s2 | endl                                              // local separator removal
 | 
|---|
| 71 |                  | s1 | "" | s2 | endl;                                                 // local separator removal
 | 
|---|
| 72 |         sout | endl;
 | 
|---|
| 73 | 
 | 
|---|
| 74 |         sout | "change separator" | endl;
 | 
|---|
| 75 |         sout | "from \"" | sep | "\"";
 | 
|---|
| 76 |         sepSet( sout, ", $" );                                                          // change separator, maximum of 15 characters
 | 
|---|
| 77 |         sout | " to \"" | sep | "\"" | endl;
 | 
|---|
| 78 |         sout | f | d | ld | endl
 | 
|---|
| 79 |                  | fc | dc | ldc | endl
 | 
|---|
| 80 |                  | s1 | s2 | endl
 | 
|---|
| 81 |                  | t1 | t2 | endl;                                                              // print tuple
 | 
|---|
| 82 |         sout | endl;
 | 
|---|
| 83 |         sout | "from \"" | sep | "\" ";
 | 
|---|
| 84 |         sepSet( sout, " " );                                                            // restore separator
 | 
|---|
| 85 |         sout | "to \"" | sep | "\"" | endl;
 | 
|---|
| 86 |         sout | f | d | ld | endl
 | 
|---|
| 87 |                  | fc | dc | ldc | endl
 | 
|---|
| 88 |                  | s1 | s2 | endl
 | 
|---|
| 89 |                  | t1 | t2 | endl;                                                              // print tuple
 | 
|---|
| 90 |         sout | endl;
 | 
|---|
| 91 | 
 | 
|---|
| 92 |         sout | "check sepOn/sepOff" | endl;
 | 
|---|
| 93 |         sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // no separator at start/end of line
 | 
|---|
| 94 |         sout | 1 | sepOff | 2 | 3 | endl;                                       // locally turn off implicit separator
 | 
|---|
| 95 |         sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
 | 
|---|
| 96 |         sout | 1 | 2 | 3 | "\n\n" | sepOn;                                      // no separator at start of next line
 | 
|---|
| 97 |         sout | 1 | 2 | 3 | endl;
 | 
|---|
| 98 |         sout | endl;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |         sout | "check enable/disable" | endl;
 | 
|---|
| 101 |         sout | sepDisable | 1 | 2 | 3 | endl;                           // globally turn off implicit separation
 | 
|---|
| 102 |         sout | 1 | sepOn | 2 | 3 | endl;                                        // locally turn on implicit separator
 | 
|---|
| 103 |         sout | sepEnable | 1 | 2 | 3 | endl | sepDisable;       // globally turn on/off implicit separation
 | 
|---|
| 104 |         sout | 1 | 2 | 3 | endl | sepEnable;                            // globally turn on implicit separation
 | 
|---|
| 105 |         sout | 1 | 2 | 3 | sepOn | sepDisable | endl;           // ignore seperate at end of line
 | 
|---|
| 106 |         sout | 1 | 2 | 3 | sepOn | sepEnable | endl;            // separator at end of line
 | 
|---|
| 107 |         sout | 1 | 2 | 3 | endl;
 | 
|---|
| 108 |         sout | endl;
 | 
|---|
| 109 | 
 | 
|---|
| 110 | //      sout | fmt( d, "%8.3f" ) || endl;
 | 
|---|
| 111 | //      sout | endl;
 | 
|---|
| 112 | 
 | 
|---|
| 113 |         sepSetTuple( sout, " " );                                                       // set tuple separator from ", " to " "
 | 
|---|
| 114 |         sout | t1 | t2 | " \"" | sep | "\"" | endl;
 | 
|---|
| 115 |         sepSetTuple( sout, ", " );                                                      // reset tuple separator to ", "
 | 
|---|
| 116 |         sout | t1 | t2 | " \"" | sep | "\"" | endl;
 | 
|---|
| 117 |         sout | t1 | t2 | endl;                                                          // print tuple
 | 
|---|
| 118 |         sout | endl;
 | 
|---|
| 119 | 
 | 
|---|
| 120 |         [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
 | 
|---|
| 121 |         sout | [ 3, 4, "a", 7.2 ] | endl;
 | 
|---|
| 122 |         sout | t3 | endl;
 | 
|---|
| 123 |         sepSetTuple( sout, " " );
 | 
|---|
| 124 |         sout | t3 | endl;
 | 
|---|
| 125 |         sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl;
 | 
|---|
| 126 |         sepSet( sout, "^" );
 | 
|---|
| 127 |         sepSetTuple( sout, "-" );
 | 
|---|
| 128 |         sout | t3 | 3 | 4 | t3 | endl;
 | 
|---|
| 129 | }
 | 
|---|
| 130 | 
 | 
|---|
| 131 | // Local Variables: //
 | 
|---|
| 132 | // tab-width: 4 //
 | 
|---|
| 133 | // compile-command: "cfa io2.c" //
 | 
|---|
| 134 | // End: //
 | 
|---|