Mistake on this page?
Report an issue in GitHub or email us
Stream.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MBED_STREAM_H
17 #define MBED_STREAM_H
18 
19 #include "platform/platform.h"
20 #include "platform/FileLike.h"
21 #include "platform/FileHandle.h"
22 #include "platform/NonCopyable.h"
23 #include <cstdio>
24 #include <cstdarg>
25 
26 namespace mbed {
27 /** \addtogroup platform */
28 /** @{*/
29 /**
30  * \defgroup platform_Stream Stream class
31  * @{
32  */
33 
34 extern void mbed_set_unbuffered_stream(std::FILE *_file);
35 extern int mbed_getc(std::FILE *_file);
36 extern char *mbed_gets(char *s, int size, 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  int putc(int c);
49  int puts(const char *s);
50  int getc();
51  char *gets(char *s, int size);
52  int printf(const char *format, ...);
53  int scanf(const char *format, ...);
54  int vprintf(const char *format, std::va_list args);
55  int vscanf(const char *format, std::va_list args);
56 
57  operator std::FILE *()
58  {
59  return _file;
60  }
61 
62 protected:
63  virtual int close();
64  virtual ssize_t write(const void *buffer, size_t length);
65  virtual ssize_t read(void *buffer, size_t length);
66  virtual off_t seek(off_t offset, int whence);
67  virtual off_t tell();
68  virtual void rewind();
69  virtual int isatty();
70  virtual int sync();
71  virtual off_t size();
72 
73  virtual int _putc(int c) = 0;
74  virtual int _getc() = 0;
75 
76  std::FILE *_file;
77 
78  /** Acquire exclusive access to this object.
79  */
80  virtual void lock()
81  {
82  // Stub
83  }
84 
85  /** Release exclusive access to this object.
86  */
87  virtual void unlock()
88  {
89  // Stub
90  }
91 };
92 /**@}*/
93 
94 /**@}*/
95 } // namespace mbed
96 
97 #endif
98 
virtual void rewind()
Definition: Stream.cpp:125
Definition: Stream.h:42
virtual int close()
Definition: Stream.cpp:76
virtual off_t tell()
Definition: Stream.cpp:120
virtual int isatty()
Definition: Stream.cpp:129
virtual void lock()
Definition: Stream.h:80
Definition: NonCopyable.h:150
virtual ssize_t read(void *buffer, size_t length)
Definition: Stream.cpp:97
virtual void unlock()
Definition: Stream.h:87
Definition: FileLike.h:38
virtual off_t size()
Definition: Stream.cpp:139
virtual ssize_t write(const void *buffer, size_t length)
Definition: Stream.cpp:81
virtual int sync()
Definition: Stream.cpp:134
virtual off_t seek(off_t offset, int whence)
Definition: Stream.cpp:115
Definition: AnalogIn.cpp:21
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.