Lab 1 Program C
Fork of mbed by
Stream.h@11:1c1ebd0324fa, 2009-08-28 (annotated)
- Committer:
- rolf.meyer@arm.com
- Date:
- Fri Aug 28 12:10:11 2009 +0000
- Revision:
- 11:1c1ebd0324fa
- Parent:
- 8:00a04e5cd407
- Child:
- 27:7110ebee3484
A shiny new version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon.ford@mbed.co.uk | 0:82220227f4fa | 1 | /* mbed Microcontroller Library - Stream |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 2 | * Copyright (c) 2007-2009 ARM Limited. All rights reserved. |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 3 | * sford |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 4 | */ |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 5 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 6 | #ifndef MBED_STREAM_H |
simon.ford@mbed.co.uk | 0:82220227f4fa | 7 | #define MBED_STREAM_H |
simon.ford@mbed.co.uk | 0:82220227f4fa | 8 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 9 | #include "FileLike.h" |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 10 | #include "platform.h" |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 11 | #include <cstdio> |
simon.ford@mbed.co.uk | 0:82220227f4fa | 12 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 13 | namespace mbed { |
simon.ford@mbed.co.uk | 0:82220227f4fa | 14 | |
simon.ford@mbed.co.uk | 8:00a04e5cd407 | 15 | class Stream : public FileLike { |
simon.ford@mbed.co.uk | 0:82220227f4fa | 16 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 17 | public: |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 18 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 19 | Stream(const char *name = NULL); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 20 | virtual ~Stream(); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 21 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 22 | int putc(int c) { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 23 | fflush(_file); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 24 | return std::fputc(c, _file); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 25 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 26 | int puts(const char *s) { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 27 | fflush(_file); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 28 | return std::fputs(s, _file); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 29 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 30 | int getc() { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 31 | fflush(_file); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 32 | return std::fgetc(_file); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 33 | } |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 34 | char *gets(char *s, int size) { |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 35 | fflush(_file); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 36 | return std::fgets(s,size,_file);; |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 37 | } |
simon.ford@mbed.co.uk | 0:82220227f4fa | 38 | int printf(const char* format, ...); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 39 | int scanf(const char* format, ...); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 40 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 41 | operator std::FILE*() { return _file; } |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 42 | |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 43 | #ifdef MBED_RPC |
simon.ford@mbed.co.uk | 8:00a04e5cd407 | 44 | virtual const struct rpc_method *get_rpc_methods(); |
rolf.meyer@arm.com | 11:1c1ebd0324fa | 45 | #endif |
simon.ford@mbed.co.uk | 8:00a04e5cd407 | 46 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 47 | protected: |
simon.ford@mbed.co.uk | 0:82220227f4fa | 48 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 49 | virtual int close(); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 50 | virtual ssize_t write(const void* buffer, size_t length); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 51 | virtual ssize_t read(void* buffer, size_t length); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 52 | virtual off_t lseek(off_t offset, int whence); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 53 | virtual int isatty(); |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 54 | virtual int fsync(); |
simon.ford@mbed.co.uk | 8:00a04e5cd407 | 55 | virtual off_t flen(); |
simon.ford@mbed.co.uk | 0:82220227f4fa | 56 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 57 | virtual int _putc(int c) = 0; |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 58 | virtual int _getc() = 0; |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 59 | |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 60 | std::FILE *_file; |
simon.ford@mbed.co.uk | 4:5d1359a283bc | 61 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 62 | }; |
simon.ford@mbed.co.uk | 0:82220227f4fa | 63 | |
simon.ford@mbed.co.uk | 0:82220227f4fa | 64 | } // namespace mbed |
simon.ford@mbed.co.uk | 0:82220227f4fa | 65 | |
simon.ford@mbed.co.uk | 1:6b7f447ca868 | 66 | #endif |
simon.ford@mbed.co.uk | 1:6b7f447ca868 | 67 |