source: src/examples/iostream.h@ 7cd23d5

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

allow nested routines to use type variables in containing scope, fix missing adapters, generalized iostream write

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[86bd7c1f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 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// iostream.h --
8//
9// Author : Richard C. Bilson
10// Created On : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
[e56cfdb0]12// Last Modified On : Thu Nov 19 17:56:51 2015
13// Update Count : 5
[86bd7c1f]14//
15
[51b73452]16#ifndef IOSTREAM_H
17#define IOSTREAM_H
18
[e56cfdb0]19#include "iterator.h"
20
[51b73452]21typedef unsigned long streamsize_type;
22
[134b86a]23context ostream( dtype ostype ) {
[86bd7c1f]24 ostype *write( ostype *, const char *, streamsize_type );
25 int fail( ostype * );
[51b73452]26};
27
[134b86a]28context writeable( type T ) {
[86bd7c1f]29 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, T );
[51b73452]30};
31
32// implement writable for some intrinsic types
33
34forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, char );
35forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, int );
[134b86a]36forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double );
[51b73452]37forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * );
[e56cfdb0]38forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * );
39
40// writes the range [begin, end) to the given stream
41forall( type elt_type | writeable( elt_type ),
42 type iterator_type | iterator( iterator_type, elt_type ),
43 dtype os_type | ostream( os_type ) )
44void write( iterator_type begin, iterator_type end, os_type *os );
45
46forall( type elt_type | writeable( elt_type ),
47 type iterator_type | iterator( iterator_type, elt_type ),
48 dtype os_type | ostream( os_type ) )
49void write_reverse( iterator_type begin, iterator_type end, os_type *os );
[51b73452]50
51
[134b86a]52context istream( dtype istype ) {
[86bd7c1f]53 istype *read( istype *, char *, streamsize_type );
54 istype *unread( istype *, char );
55 int fail( istype * );
56 int eof( istype * );
[51b73452]57};
58
[134b86a]59context readable( type T ) {
[86bd7c1f]60 forall( dtype istype | istream( istype ) ) istype * ?<<?( istype *, T );
[51b73452]61};
62
63forall( dtype istype | istream( istype ) )
[134b86a]64istype * ?>>?( istype *, char * );
[51b73452]65
66forall( dtype istype | istream( istype ) )
[134b86a]67istype * ?>>?( istype *, int * );
[51b73452]68
[134b86a]69#endif // IOSTREAM_H
[86bd7c1f]70
71// Local Variables: //
72// tab-width: 4 //
73// compile-command: "cfa iostream.c" //
74// End: //
Note: See TracBrowser for help on using the repository browser.