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 
51 //! @brief XFILE structure holds additional info to generic FILE
52 /// @{
53 typedef struct xfile {
54  char * filename; ///< file name in the time of opening
55  char * mode; ///< opening mode
56  int lineno; ///< last read line (only for text files)
57 } XFILE;
58 //! @}
59 
60 
61 /**
62  * Base class of XIO library.
63  *
64  * The class implements a singleton pattern.
65  * Stores data of file mapping and debug output for XIO function.
66  */
67 class Xio {
68 public:
69  /// mapping of ptr to regular file structure to extended structure
71 
72  /// return instance
73  static Xio *get_instance();
74  /// initialize XIO library
75  static void init();
76 
77  /// Enable/Disable XIO debug output for EACH XIO function call
78  void set_verbosity(int verb);
79  /// Get current XIO debug verbosity level
80  int get_verbosity();
81  /// Get XIO mapping instance
83 
84 private:
85  // Singleton instance
86  static Xio *instance;
87 
88  /**
89  * Constructor.
90  *
91  * Initialize XIO library.
92  */
93  Xio();
94 
95  /// mapping instance
97  /// internal XIO debug: print info at each XIO function
99 
100 };
101 
102 //! @brief XIO library extensions
103 /// @{
104 char * xio_getfname( FILE * f ); ///< Get file name from file stream
105 char * xio_getfmode( FILE * f ); ///< Get file mode from file stream
106 int xio_getlinesread( FILE * f ); ///< Get number of read lines from stream
107 char * xio_getfulldescription( FILE * f ); ///< Get pointer to string with full file description
108 //! @}
109 
110 //! @brief File access
111 /// @{
112 FILE * xfopen( const char * fname, const char * mode ); ///< Open file (function)
113 FILE * xfopen( const std::string &fname, const char * mode );
114 int xfclose( FILE * stream ); ///< Close file (function)
115 int xfflush( FILE * f ); ///< Flush stream (function)
116 FILE * xfreopen( const char * filename, const char * mode, FILE * stream );
117 
118 //#define setbuf xsetbuf NOT_USED ///< Set stream buffer (function)
119 //#define setvbuf xsetvbuf NOT_USED ///< Change stream buffering (function)
120 //! @}
121 
122 //! @brief Formatted input/output
123 /// @{
124 int xfprintf( FILE * out, const char * fmt, ... ); ///< Write formatted output to stream (function)
125 int xfscanf( FILE * in, const char * fmt, ... ); ///< Read formatted data from stream (function)
126 
127 //#define vfprintf xvfprintf NOT_USED ///< Write formatted variable argument list to stream (function)
128 //! @}
129 
130 //! @brief Character input/output
131 /// @{
132 char * xfgets( char *s, int n, FILE *in ); ///< Get string from stream (function)
133 int xfgetc( FILE * f ); ///< Get character from stream (function)
134 int xgetc( FILE * f ); ///< Get character from stream (function)
135 int xungetc( int c, FILE * f ); ///< Unget character from stream (function)
136 
137 //#define fputc xfputc NOT_USED ///< Write character to stream (function)
138 //#define fputs xfputs NOT_USED ///< Write string to stream (function)
139 //#define putc xputc NOT_USED ///< Write character to stream (function)
140 
141 //! @}
142 
143 //! @brief Direct input/output
144 /// @{
145 size_t xfread( void * ptr, size_t size, size_t count, FILE * stream ); ///< Read block of data from stream (function)
146 size_t xfwrite( const void * ptr, size_t size, size_t count, FILE * stream ); ///< Write block of data to stream (function)
147 //! @}
148 
149 //! @brief File positioning
150 /// @{
151 void xrewind( FILE * f ); ///< Set position indicator to the beginning (function)
152 
153 //#define fgetpos xfgetpos NOT_USED ///< Get current position in stream (function)
154 //#define fseek xfseek NOT_USED ///< Reposition stream position indicator (function)
155 //#define fsetpos xfsetpos NOT_USED ///< Set position indicator of stream (function)
156 //#define ftell xftell NOT_USED ///< Get current position in stream (function)
157 //! @}
158 
159 //! @brief Error-handling
160 /// @{
161 int xfeof ( FILE * f ); ///< Check End-of-File indicator (function)
162 
163 //#define clearerr xclearerr NOT_USED ///< Clear error indicators (function)
164 //#define ferror xferror NOT_USED ///< Check error indicator (function)
165 //#define perror xperror NOT_USED ///< Print error message (function)
166 //! @}
167 
168 #endif /* XIO_H_ */