Flow123d
xio.h
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file xio.h
26  * @brief I/O functions with filename storing, able to track current line in opened file. All standard
27  * stdio functions working with files (not stdin, stdout, stderr) should be replaced
28  * by their equivalents from XIO library.
29  *
30  * @date 6.4.2010
31  * @author Jiri Jenicek
32  *
33  */
34 
35 /*
36  *
37  * Commented lines contains functions of stdio library that are not used in Flow123d.
38  * Their equivalents are currently not implemented in XIO library.
39  *
40  */
41 
42 #ifndef XIO_H_
43 #define XIO_H_
44 
45 #include "global_defs.h"
46 #include "system/system.hh"
47 
48 #include <map>
49 
50 // Size of buffer for text input lines.
51 #define LINE_SIZE 65536
52 
53 //! @brief XFILE structure holds additional info to generic FILE
54 /// @{
55 typedef struct xfile {
56  char * filename; ///< file name in the time of opening
57  char * mode; ///< opening mode
58  int lineno; ///< last read line (only for text files)
59 } XFILE;
60 //! @}
61 
62 
63 /**
64  * Base class of XIO library.
65  *
66  * The class implements a singleton pattern.
67  * Stores data of file mapping and debug output for XIO function.
68  */
69 class Xio {
70 public:
71  /// mapping of ptr to regular file structure to extended structure
73 
74  /// return instance
75  static Xio *get_instance();
76  /// initialize XIO library
77  static void init();
78 
79  /// Enable/Disable XIO debug output for EACH XIO function call
80  void set_verbosity(int verb);
81  /// Get current XIO debug verbosity level
82  int get_verbosity();
83  /// Get XIO mapping instance
85 
86 private:
87  // Singleton instance
88  static Xio *instance;
89 
90  /**
91  * Constructor.
92  *
93  * Initialize XIO library.
94  */
95  Xio();
96 
97  /// mapping instance
99  /// internal XIO debug: print info at each XIO function
101 
102 };
103 
104 //! @brief XIO library extensions
105 /// @{
106 char * xio_getfname( FILE * f ); ///< Get file name from file stream
107 char * xio_getfmode( FILE * f ); ///< Get file mode from file stream
108 int xio_getlinesread( FILE * f ); ///< Get number of read lines from stream
109 char * xio_getfulldescription( FILE * f ); ///< Get pointer to string with full file description
110 //! @}
111 
112 //! @brief File access
113 /// @{
114 FILE * xfopen( const char * fname, const char * mode ); ///< Open file (function)
115 FILE * xfopen( const std::string &fname, const char * mode );
116 int xfclose( FILE * stream ); ///< Close file (function)
117 int xfflush( FILE * f ); ///< Flush stream (function)
118 FILE * xfreopen( const char * filename, const char * mode, FILE * stream );
119 
120 //#define setbuf xsetbuf NOT_USED ///< Set stream buffer (function)
121 //#define setvbuf xsetvbuf NOT_USED ///< Change stream buffering (function)
122 //! @}
123 
124 //! @brief Formatted input/output
125 /// @{
126 int xfprintf( FILE * out, const char * fmt, ... ); ///< Write formatted output to stream (function)
127 int xfscanf( FILE * in, const char * fmt, ... ); ///< Read formatted data from stream (function)
128 
129 //#define vfprintf xvfprintf NOT_USED ///< Write formatted variable argument list to stream (function)
130 //! @}
131 
132 //! @brief Character input/output
133 /// @{
134 char * xfgets( char *s, int n, FILE *in ); ///< Get string from stream (function)
135 int xfgetc( FILE * f ); ///< Get character from stream (function)
136 int xgetc( FILE * f ); ///< Get character from stream (function)
137 int xungetc( int c, FILE * f ); ///< Unget character from stream (function)
138 
139 //#define fputc xfputc NOT_USED ///< Write character to stream (function)
140 //#define fputs xfputs NOT_USED ///< Write string to stream (function)
141 //#define putc xputc NOT_USED ///< Write character to stream (function)
142 
143 //! @}
144 
145 //! @brief Direct input/output
146 /// @{
147 size_t xfread( void * ptr, size_t size, size_t count, FILE * stream ); ///< Read block of data from stream (function)
148 size_t xfwrite( const void * ptr, size_t size, size_t count, FILE * stream ); ///< Write block of data to stream (function)
149 //! @}
150 
151 //! @brief File positioning
152 /// @{
153 void xrewind( FILE * f ); ///< Set position indicator to the beginning (function)
154 
155 //#define fgetpos xfgetpos NOT_USED ///< Get current position in stream (function)
156 //#define fseek xfseek NOT_USED ///< Reposition stream position indicator (function)
157 //#define fsetpos xfsetpos NOT_USED ///< Set position indicator of stream (function)
158 //#define ftell xftell NOT_USED ///< Get current position in stream (function)
159 //! @}
160 
161 //! @brief Error-handling
162 /// @{
163 int xfeof ( FILE * f ); ///< Check End-of-File indicator (function)
164 
165 //#define clearerr xclearerr NOT_USED ///< Clear error indicators (function)
166 //#define ferror xferror NOT_USED ///< Check error indicator (function)
167 //#define perror xperror NOT_USED ///< Print error message (function)
168 //! @}
169 
170 #endif /* XIO_H_ */