| 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 |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef MPS_FILE_INPUT_STREAM_H_ |
| 17 |
#define MPS_FILE_INPUT_STREAM_H_ |
| 18 |
|
| 19 |
MPS_BEGIN_DECLS |
| 20 |
|
| 21 |
/** |
| 22 |
* @brief Wrapper around {@link FileInputStream}. |
| 23 |
*/ |
| 24 |
struct mps_file_input_stream; |
| 25 |
|
| 26 |
/** |
| 27 |
* @brief Wrapper around {@link FileInputStream}. |
| 28 |
*/ |
| 29 |
typedef struct mps_file_input_stream mps_file_input_stream; |
| 30 |
|
| 31 |
/** |
| 32 |
* @brief Allocate a new {@link FileInputStream} instane that will |
| 33 |
* stream the given file. |
| 34 |
* |
| 35 |
* @param source A FILE* object returned by a call to fopen() on the |
| 36 |
* desired file. |
| 37 |
*/ |
| 38 |
mps_file_input_stream * mps_file_input_stream_new (FILE * source); |
| 39 |
|
| 40 |
/** |
| 41 |
* @brief Release the resources holded by this {@link FileInputStream} |
| 42 |
* instance. |
| 43 |
* |
| 44 |
* @param stream The {@link FileInputStream} that should be freed. |
| 45 |
*/ |
| 46 |
void mps_file_input_stream_free (mps_file_input_stream * stream); |
| 47 |
|
| 48 |
MPS_END_DECLS |
| 49 |
|
| 50 |
#ifdef __cplusplus |
| 51 |
|
| 52 |
namespace mps { |
| 53 |
class FileInputStream : public AbstractInputStream { |
| 54 |
public: |
| 55 |
|
| 56 |
/** |
| 57 |
* @brief Create a new instance of FileInputStream that will output the |
| 58 |
* content of the FILE opened. |
| 59 |
* |
| 60 |
* @param source A FILE* object returned by a fopen() call on the |
| 61 |
* file whose content should be provided by this stream. |
| 62 |
*/ |
| 63 |
FileInputStream (FILE * source); |
| 64 |
|
| 65 |
~FileInputStream (); |
| 66 |
|
| 67 |
/** |
| 68 |
* @brief Implementation of the readline() method of the |
| 69 |
* {@link AbstractInputStream} parent. |
| 70 |
* |
| 71 |
* @param buffer A pointer to the buffer where the line will be stored. |
| 72 |
* @param length A pointer where the length of the allocated buffer at |
| 73 |
* the end will be saved. |
| 74 |
* |
| 75 |
* @return The number of characters that have been stored in |
| 76 |
* buffer. |
| 77 |
*/ |
| 78 |
size_t readline (char ** buffer, size_t * length); |
| 79 |
|
| 80 |
/** |
| 81 |
* @brief Implementation of the eof() method of {@link AbstractInputStream}. |
| 82 |
* |
| 83 |
* @return true if the source stream has reached the end. |
| 84 |
*/ |
| 85 |
bool eof (); |
| 86 |
|
| 87 |
/** |
| 88 |
* @brief Obtain a single character. |
| 89 |
* |
| 90 |
* @return A new character read from the stream. |
| 91 |
*/ |
| 92 |
int getchar (); |
| 93 |
|
| 94 |
private: |
| 95 |
FILE * mSource; |
| 96 |
}; |
| 97 |
} |
| 98 |
|
| 99 |
#endif /* __cplusplus */ |
| 100 |
|
| 101 |
#endif /* MPS_FILE_INPUT_STREAM_H_ */ |
| 102 |
|