Debian Codegraph @

include/mps/private/system/memory-file-stream.h

raw
1 /*
2 * This file is part of MPSolve 3.2.2
3 *
4 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6 *
7 * Authors:
8 * Leonardo Robol <[email protected]>
9 */
10
11 /**
12 * @file
13 * @brief Implementation of a fmemopen-like stream.
14 */
15
16 #ifndef MPS_MEMORY_FILE_STREAM_H_
17 #define MPS_MEMORY_FILE_STREAM_H_
18
19 MPS_BEGIN_DECLS
20
21 /**
22 * @brief C wrapper around {@link MemoryFileStream}.
23 */
24 struct mps_memory_file_stream;
25
26 /**
27 * @brief C wrapper around {@link MemoryFileStream}.
28 */
29 typedef struct mps_memory_file_stream mps_memory_file_stream;
30
31 /**
32 * @brief Allocate a new {@link MemoryFileStream} that will output
33 * the data pointed by source.
34 *
35 * @param source The data that will be provided by the mps_memory_file_stream.
36 */
37 mps_memory_file_stream * mps_memory_file_stream_new (const char * source);
38
39 /**
40 * @brief Release the resources holded by a {@link MemoryFileStream}.
41 *
42 * @param stream The {@link MemoryFileStream} to release.
43 */
44 void mps_memory_file_stream_free (mps_memory_file_stream * stream);
45
46 MPS_END_DECLS
47
48 #ifdef __cplusplus
49
50 #include <iostream>
51 #include <sstream>
52
53 #include <mps/mps.h>
54
55 namespace mps {
56 /**
57 * @brief The MemoryFileStream class provides an implementation of
58 * the abstract class {@link AbstractInputStream} that will stream
59 * the data contained in the area stored in memory.
60 */
61 class MemoryFileStream : public AbstractInputStream {
62 public:
63
64 /**
65 * @brief Allocate a new MemoryFileStream that wil provide that data
66 * stored by the given pointer.
67 *
68 * @param source A pointer to the data that should be provided
69 * by this instance.
70 */
71 MemoryFileStream(const char * source);
72
73 ~MemoryFileStream();
74
75 /**
76 * @brief Implementation of the readline() method of the
77 * {@link AbstractInputStream} parent.
78 *
79 * @param buffer A pointer to the buffer where the line will be stored.
80 * @param length A pointer where the length of the allocated buffer at
81 * the end will be saved.
82 *
83 * @return The number of characters that have been stored in
84 * buffer.
85 */
86 size_t readline (char ** buffer, size_t * length);
87
88 /**
89 * @brief Implementation of the eof() method of {@link AbstractInputStream}.
90 *
91 * @return true if the source stream has reached the end.
92 */
93 bool eof ();
94
95 /**
96 * @brief Obtain a single character.
97 *
98 * @return A new character read from the stream.
99 */
100 int getchar ();
101
102 private:
103 std::istringstream mInputStream;
104 };
105 }
106
107 #endif
108
109 #endif /* MPS_MEMORY_FILE_STREAM_H_ */
110