OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
datastream.h
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
35 #ifndef datastream_h
36 #define datastream_h
37 
38 #include "oofemcfg.h"
39 
40 #include <sstream>
41 #include <cstdio>
42 #include <exception>
43 #include <stdexcept>
44 
45 namespace oofem {
54 class OOFEM_EXPORT DataStream
55 {
56 public:
58  virtual ~DataStream() { }
66  virtual int read(int *data, int count) = 0;
68  int read(int &data) { return this->read(&data, 1); }
70  virtual int read(unsigned long *data, int count) = 0;
71  int read(unsigned long &data) { return this->read(&data, 1); }
73  virtual int read(long *data, int count) = 0;
74  int read(long &data) { return this->read(&data, 1); }
76  virtual int read(double *data, int count) = 0;
77  int read(double &data) { return this->read(&data, 1); }
79  virtual int read(char *data, int count) = 0;
80  int read(char &data) { return this->read(&data, 1); }
82  virtual int read(bool &data) = 0;
84  int read(std :: string &data);
86 
93  virtual int write(const int *data, int count) = 0;
95  int write(int data) { return this->write(&data, 1); }
97  virtual int write(const unsigned long *data, int count) = 0;
98  int write(unsigned long data) { return this->write(&data, 1); }
100  virtual int write(const long *data, int count) = 0;
101  int write(long data) { return this->write(&data, 1); }
103  virtual int write(const double *data, int count) = 0;
104  int write(double data) { return this->write(&data, 1); }
106  virtual int write(const char *data, int count) = 0;
107  int write(char data) { return this->write(&data, 1); }
109  virtual int write(bool data) = 0;
111  int write(const std :: string &data);
113  int write(const char *data) { return this->write(std :: string(data)); }
115 
121  virtual int givePackSizeOfInt(int count) = 0;
122  virtual int givePackSizeOfDouble(int count) = 0;
123  virtual int givePackSizeOfChar(int count) = 0;
124  virtual int givePackSizeOfBool(int count) = 0;
125  virtual int givePackSizeOfLong(int count) = 0;
127 };
128 
129 
136 class OOFEM_EXPORT FileDataStream : public DataStream
137 {
138 public:
139  class CantOpen : public std::runtime_error
140  {
141  public:
142  std::string filename;
143  CantOpen(std::string file): std::runtime_error("can't open file"), filename(std::move(file)) {}
144  };
145 
146 private:
148  FILE *stream;
150  std :: string filename;
151 public:
153  FileDataStream(std :: string filename, bool write);
154 
156  virtual ~FileDataStream();
157 
158  virtual int read(int *data, int count);
159  virtual int read(unsigned long *data, int count);
160  virtual int read(long *data, int count);
161  virtual int read(double *data, int count);
162  virtual int read(char *data, int count);
163  virtual int read(bool &data);
164 
165  virtual int write(const int *data, int count);
166  virtual int write(const unsigned long *data, int count);
167  virtual int write(const long *data, int count);
168  virtual int write(const double *data, int count);
169  virtual int write(const char *data, int count);
170  virtual int write(bool data);
171 
172  virtual int givePackSizeOfInt(int count);
173  virtual int givePackSizeOfDouble(int count);
174  virtual int givePackSizeOfChar(int count);
175  virtual int givePackSizeOfBool(int count);
176  virtual int givePackSizeOfLong(int count);
177 };
178 
179 } // end namespace oofem
180 #endif // datastream_h
Implementation of FileDataStream representing DataStream interface to file i/o.
Definition: datastream.h:136
int read(int &data)
Definition: datastream.h:68
The purpose of DataStream abstract class is to allow to store/restore context to different streams...
Definition: datastream.h:54
std::string filename
Filename.
Definition: datastream.h:150
int read(char &data)
Definition: datastream.h:80
int write(double data)
Definition: datastream.h:104
int write(int data)
Definition: datastream.h:95
int read(unsigned long &data)
Definition: datastream.h:71
CantOpen(std::string file)
Definition: datastream.h:143
int write(long data)
Definition: datastream.h:101
int write(char data)
Definition: datastream.h:107
int read(long &data)
Definition: datastream.h:74
int write(const char *data)
Writes a string (wrapper needed, otherwise write(bool) is called )
Definition: datastream.h:113
int read(double &data)
Definition: datastream.h:77
int write(unsigned long data)
Definition: datastream.h:98
virtual ~DataStream()
Destructor.
Definition: datastream.h:58
the oofem namespace is to define a context or scope in which all oofem names are defined.
FILE * stream
FILE pointer of associated stream.
Definition: datastream.h:148

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:28 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011