mbed-drivers
Stream.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_STREAM_H
18 #define MBED_STREAM_H
19 
20 #include "platform.h"
21 #include "FileLike.h"
22 #include <cstdarg>
23 
24 namespace mbed {
25 
26 class Stream : public FileLike {
27 
28 public:
29  Stream(const char *name=NULL);
30  virtual ~Stream();
31 
32  int putc(int c);
33  int puts(const char *s);
34  int getc();
35  char *gets(char *s, int size);
36  int printf(const char* format, ...);
37  int scanf(const char* format, ...);
38  int vprintf(const char* format, std::va_list args);
39  int vscanf(const char* format, std::va_list args);
40 
41  operator std::FILE*() {return _file;}
42 
43 protected:
44  virtual int close();
45  virtual ssize_t write(const void* buffer, size_t length);
46  virtual ssize_t read(void* buffer, size_t length);
47  virtual off_t lseek(off_t offset, int whence);
48  virtual int isatty();
49  virtual int fsync();
50  virtual off_t flen();
51 
52  virtual int _putc(int c) = 0;
53  virtual int _getc() = 0;
54 
55  std::FILE *_file;
56 
57  /* disallow copy constructor and assignment operators */
58 private:
59  Stream(const Stream&);
60  Stream & operator = (const Stream&);
61 };
62 
63 } // namespace mbed
64 
65 #endif
virtual off_t lseek(off_t offset, int whence)
Definition: Stream.cpp:76
Definition: Stream.h:26
virtual ssize_t read(void *buffer, size_t length)
Definition: Stream.cpp:65
virtual int isatty()
Definition: Stream.cpp:81
Definition: FileLike.h:30
virtual int fsync()
Definition: Stream.cpp:85
virtual int close()
Definition: Stream.cpp:50
Definition: BusIn.cpp:19
virtual ssize_t write(const void *buffer, size_t length)
Definition: Stream.cpp:54