Mistake on this page?
Report an issue in GitHub or email us
Stream.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may 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,
13  * WITHOUT 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/platform.h"
21 #include "platform/FileLike.h"
22 #include "platform/NonCopyable.h"
23 #include "platform/mbed_toolchain.h"
24 #include <cstdio>
25 #include <cstdarg>
26 
27 namespace mbed {
28 /** \addtogroup platform-public-api */
29 /** @{*/
30 
31 /**
32  * \defgroup platform_Stream Stream class
33  * @{
34  */
35 
36 extern void mbed_set_unbuffered_stream(std::FILE *_file);
37 
38 /** File stream
39  *
40  * @note Synchronization level: Set by subclass
41  */
42 class Stream : public FileLike, private NonCopyable<Stream> {
43 
44 public:
45  Stream(const char *name = NULL);
46  virtual ~Stream();
47 
48 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
49  int putc(int c);
50  int puts(const char *s);
51  int getc();
52  char *gets(char *s, int size);
53  int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
54  int scanf(const char *format, ...) MBED_SCANF_METHOD(1, 2);
55  int vprintf(const char *format, std::va_list args) MBED_PRINTF_METHOD(1, 0);
56  int vscanf(const char *format, std::va_list args) MBED_SCANF_METHOD(1, 0);
57 
58  operator std::FILE *()
59  {
60  return _file;
61  }
62 
63 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
64  virtual int close();
65  virtual ssize_t write(const void *buffer, size_t length);
66  virtual ssize_t read(void *buffer, size_t length);
67  virtual off_t seek(off_t offset, int whence);
68  virtual off_t tell();
69  virtual void rewind();
70  virtual int isatty();
71  virtual int sync();
72  virtual off_t size();
73 
74 protected:
75  virtual int _putc(int c) = 0;
76  virtual int _getc() = 0;
77 
78 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
79  std::FILE *_file;
80 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
81 
82  /** Acquire exclusive access to this object.
83  */
84  virtual void lock()
85  {
86  // Stub
87  }
88 
89  /** Release exclusive access to this object.
90  */
91  virtual void unlock()
92  {
93  // Stub
94  }
95 };
96 /**@}*/
97 
98 /**@}*/
99 } // namespace mbed
100 
101 #endif
102 
virtual off_t seek(off_t offset, int whence)
Move the file position to a given offset from from a given location.
File stream.
Definition: Stream.h:42
virtual ssize_t write(const void *buffer, size_t length)
Write the contents of a buffer to a file.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:169
virtual int close()
Close a file.
virtual off_t tell()
Get the file position of the file.
virtual void rewind()
Rewind the file position to the beginning of the file.
virtual int isatty()
Check if the file in an interactive terminal device.
virtual int sync()
Flush any buffers associated with the file.
Class FileLike.
Definition: FileLike.h:38
virtual void unlock()
Release exclusive access to this object.
Definition: Stream.h:91
virtual ssize_t read(void *buffer, size_t length)
Read the contents of a file into a buffer.
virtual void lock()
Acquire exclusive access to this object.
Definition: Stream.h:84
virtual off_t size()
Get the size of the file.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.