source: tests/collections/string-istream.cfa@ b28ce93

Last change on this file since b28ce93 was 3f631d6, checked in by Michael Brooks <mlbrooks@…>, 6 months ago

Switch string io to be generic upon iostream, rather than specific upon fstream.

No direct test added because we currently lack a second implementation of the abstract streams.

Benefit is removing polymorphism-induced noise from cost calculations, in upcoming string-overload reorganizations.

The change in tests 'collections/string-operator*' shows cases where we stopped picking string for the wrong reason. (If we should be picking string for a better reason, that's just ahead.)

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include <fstream.hfa>
2#include <string.hfa>
3#include <string_res.hfa>
4
5
6void istream_cstr(void) {
7 enum { size = 999, rsize = size - 1 }; // string size, read size
8 char s1[size], s2[size], s3[size], si[size];
9 sin | wdi(size,rsize,s1) | wdi(size,rsize,s2) | wdi(size,rsize,s3);
10 sout | s1;
11 sout | s2;
12 sout | s3;
13 for(;;) {
14 sin | wdi(size,rsize,si);
15 if (si[0] == '=') break;
16 sout | si;
17 }
18}
19
20string accumulator;
21
22void reset_otherStringAction(void) {
23 accumulator = "";
24}
25void step_otherStringAction(void) {
26 string localAction = "--";
27 accumulator += localAction(0,1);
28 sout | accumulator;
29}
30
31void istream_string_res(void) {
32 string_res s1, s2, s3, si;
33 sin | s1 | s2 | s3;
34 sout | s1; step_otherStringAction();
35 sout | s2; step_otherStringAction();
36 sout | s3; step_otherStringAction();
37 for(;;) {
38 sin | si;
39 if (len(si) > 0 && si[0] == '=') break;
40 sout | si; step_otherStringAction();
41 }
42}
43
44void istream_string(void) {
45 string s1, s2, s3, si;
46 sin | s1 | s2 | s3;
47 sout | s1; step_otherStringAction();
48 sout | s2; step_otherStringAction();
49 sout | s3; step_otherStringAction();
50 for(;;) {
51 sin | si;
52 if (len(si) > 0 && si[0] == '=') break;
53 sout | si; step_otherStringAction();
54 }
55}
56
57
58int main() {
59 istream_cstr(); sout | "=";
60 istream_string_res(); sout | "="; reset_otherStringAction();
61 istream_string();
62}
Note: See TracBrowser for help on using the repository browser.