source: src/tests/io.c@ 9bd6105

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 9bd6105 was 7bc4e6b, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change iostream to use references, and update affected tests

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[53ba273]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// io.c --
8//
9// Author : Peter A. Buhr
10// Created On : Wed Mar 2 16:56:02 2016
11// Last Modified By : Peter A. Buhr
[7bc4e6b]12// Last Modified On : Wed Aug 23 21:27:50 2017
13// Update Count : 79
[53ba273]14//
15
16#include <fstream>
17
18int main() {
[5a7966bb]19 char c; // basic types
[53ba273]20 short int si;
21 unsigned short int usi;
22 int i;
23 unsigned int ui;
24 long int li;
25 unsigned long int uli;
26 long long int lli;
27 unsigned long long int ulli;
28 float f;
29 double d;
30 long double ld;
31 float _Complex fc;
32 double _Complex dc;
33 long double _Complex ldc;
[5a7966bb]34 enum { size = 10 };
35 char s1[size], s2[size];
[53ba273]36
[58b5d03]37 int x = 3, y = 5, z = 7;
38 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
39 sout | 1 | 2 | 3 | endl;
40 sout | '1' | '2' | '3' | endl;
41 sout | 1 | "" | 2 | "" | 3 | endl;
42 sout | endl;
43
[86f384b]44 sout | "opening delimiters" | endl;
[5a7966bb]45 sout
46 | "x (" | 1
47 | "x [" | 2
48 | "x {" | 3
49 | "x =" | 4
50 | "x $" | 5
51 | "x £" | 6
52 | "x ¥" | 7
53 | "x ¡" | 8
54 | "x ¿" | 9
55 | "x «" | 10
[86f384b]56 | endl | endl;
57
58 sout | "closing delimiters" | endl;
[5a7966bb]59 sout
60 | 1 | ", x"
61 | 2 | ". x"
62 | 3 | "; x"
63 | 4 | "! x"
64 | 5 | "? x"
65 | 6 | "% x"
66 | 7 | "¢ x"
67 | 8 | "» x"
68 | 9 | ") x"
69 | 10 | "] x"
70 | 11 | "} x"
[86f384b]71 | endl | endl;
72
73 sout | "opening/closing delimiters" | endl;
[5a7966bb]74 sout
75 | "x`" | 1 | "`x'" | 2
76 | "'x\"" | 3 | "\"x:" | 4
77 | ":x " | 5 | " x\t" | 6
78 | "\tx\f" | 7 | "\fx\v" | 8
79 | "\vx\n" | 9 | "\nx\r" | 10
[86f384b]80 | "\rx"
81 | endl | endl;
82
83 sout | "override opening/closing delimiters" | endl;
[5a7966bb]84 sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
[86f384b]85 sout | endl;
[5a7966bb]86
87 ifstream in; // create / open file
[6b6597c]88 open( &in, "io.data", "r" );
[53ba273]89
[86f384b]90 sout | "input bacis types" | endl;
[7bc4e6b]91 &in | c // character
92 | si | usi | i | ui | li | uli | lli | ulli // integral
93 | f | d | ld // floating point
94 | fc | dc | ldc // floating-point complex
[5a7966bb]95 | cstr( s1 ) | cstr( s2, size ); // C string, length unchecked and checked
[86f384b]96 sout | endl;
[53ba273]97
[86f384b]98 sout | "output basic types" | endl;
[5a7966bb]99 sout | c | ' ' | endl // character
100 | si | usi | i | ui | li | uli | lli | ulli | endl // integral
101 | f | d | ld | endl // floating point
102 | fc | dc | ldc | endl; // complex
[53ba273]103 sout | endl;
[86f384b]104
105 sout | "tuples" | endl;
[53a6c2a]106 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
[86f384b]107 sout | t1 | t2 | endl; // print tuple
108 sout | endl;
109
110 sout | "toggle separator" | endl;
[5a7966bb]111 sout | f | "" | d | "" | ld | endl // floating point without separator
[53a6c2a]112 | sepDisable | fc | dc | ldc | endl // complex without separator
113 | fc | sepOn | dc | ldc | endl // local separator add
114 | sepEnable | fc | dc | ldc | endl // complex with separator
115 | fc | sepOff | dc | ldc | endl // local separator removal
116 | s1 | sepOff | s2 | endl // local separator removal
117 | s1 | "" | s2 | endl; // local separator removal
[53ba273]118 sout | endl;
119
[86f384b]120 sout | "change separator" | endl;
[53a6c2a]121 sout | "from \"" | sep | "\"";
[5a7966bb]122 sepSet( sout, ", $" ); // change separator, maximum of 15 characters
[53a6c2a]123 sout | " to \"" | sep | "\"" | endl;
[829c907]124 sout | f | d | ld | endl
[5a7966bb]125 | fc | dc | ldc | endl
[86f384b]126 | s1 | s2 | endl
127 | t1 | t2 | endl; // print tuple
[d395012]128 sout | endl;
[53a6c2a]129 sout | "from \"" | sep | "\" ";
[86f384b]130 sepSet( sout, " " ); // restore separator
[53a6c2a]131 sout | "to \"" | sep | "\"" | endl;
[86f384b]132 sout | f | d | ld | endl
133 | fc | dc | ldc | endl
134 | s1 | s2 | endl
135 | t1 | t2 | endl; // print tuple
[d395012]136 sout | endl;
[6b6597c]137
[53a6c2a]138 sout | "check sepOn/sepOff" | endl;
139 sout | sepOn | 1 | 2 | 3 | sepOn | endl; // no separator at start/end of line
[5a7966bb]140 sout | 1 | sepOff | 2 | 3 | endl; // locally turn off implicit separator
[53a6c2a]141 sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
142 sout | 1 | 2 | 3 | "\n\n" | sepOn; // no separator at start of next line
[d395012]143 sout | 1 | 2 | 3 | endl;
144 sout | endl;
[5a7966bb]145
[53a6c2a]146 sout | "check enable/disable" | endl;
[5a7966bb]147 sout | sepDisable | 1 | 2 | 3 | endl; // globally turn off implicit separation
148 sout | 1 | sepOn | 2 | 3 | endl; // locally turn on implicit separator
[d395012]149 sout | sepEnable | 1 | 2 | 3 | endl | sepDisable; // globally turn on/off implicit separation
150 sout | 1 | 2 | 3 | endl | sepEnable; // globally turn on implicit separation
151 sout | 1 | 2 | 3 | sepOn | sepDisable | endl; // ignore seperate at end of line
152 sout | 1 | 2 | 3 | sepOn | sepEnable | endl; // separator at end of line
153 sout | 1 | 2 | 3 | endl;
154 sout | endl;
[5a7966bb]155
[53a6c2a]156// sout | fmt( d, "%8.3f" ) || endl;
157// sout | endl;
158
[5a7966bb]159 sepSetTuple( sout, " " ); // set tuple separator from ", " to " "
[53a6c2a]160 sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966bb]161 sepSetTuple( sout, ", " ); // reset tuple separator to ", "
[53a6c2a]162 sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966bb]163 sout | t1 | t2 | endl; // print tuple
[d395012]164 sout | endl;
[829c907]165
[5a7966bb]166 [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
[cb91437]167 sout | [ 3, 4, "a", 7.2 ] | endl;
[5a7966bb]168 sout | t3 | endl;
[829c907]169 sepSetTuple( sout, " " );
[5a7966bb]170 sout | t3 | endl;
171 sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl;
[829c907]172 sepSet( sout, "^" );
173 sepSetTuple( sout, "-" );
[5a7966bb]174 sout | t3 | 3 | 4 | t3 | endl;
[53ba273]175}
176
177// Local Variables: //
178// tab-width: 4 //
179// compile-command: "cfa io.c" //
180// End: //
Note: See TracBrowser for help on using the repository browser.