ASL
0.1.7
Advanced Simulation Library
Toggle main menu visibility
Loading...
Searching...
No Matches
src
writers
aslABDFormat.h
Go to the documentation of this file.
1
/*
2
* Advanced Simulation Library <http://asl.org.il>
3
*
4
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5
*
6
*
7
* This file is part of Advanced Simulation Library (ASL).
8
*
9
* ASL is free software: you can redistribute it and/or modify it
10
* under the terms of the GNU Affero General Public License as
11
* published by the Free Software Foundation, version 3 of the License.
12
*
13
* ASL is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
17
*
18
* You should have received a copy of the GNU Affero General Public License
19
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
20
*
21
*/
22
23
24
#ifndef ASLABDFORMAT_H
25
#define ASLABDFORMAT_H
26
27
#include <stdlib.h>
28
29
#include <iostream>
30
#include <fstream>
31
#include <string>
32
#include <memory>
33
34
#include <
data/aslDataWrapper.h
>
35
36
using namespace
std
;
37
38
namespace
asl
{
39
44
46
49
class
ABDFileIn
:
public
std::ifstream{
50
public
:
51
inline
ABDFileIn
();
52
inline
ABDFileIn
(
string
name);
53
};
54
56
59
class
ABDFileOut
:
public
std::ofstream{
60
public
:
61
inline
ABDFileOut
();
62
inline
ABDFileOut
(
string
name);
63
};
64
65
/* /// \relates ABDFileOut
66
template <typename T> inline ABDFileOut & operator <<(ABDFileOut & f, const T & a);
68
template <typename T> inline ABDFileIn & operator >>(ABDFileIn & f,T & a);
69
*/
70
72
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
int
a);
74
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
int
& a);
76
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
unsigned
int
a);
78
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
unsigned
int
& a);
80
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
float
a);
82
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
float
& a);
84
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
double
a);
86
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
double
& a);
87
88
90
template
<
typename
T>
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,pair<T*, unsigned int> a);
92
template
<
typename
T>
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,pair<T*, unsigned int> a);
93
95
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
string
&a);
97
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
string
&a);
98
100
template
<
typename
T>
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
AVec<T>
& a);
102
template
<
typename
T>
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
AVec<T>
& a);
103
104
class
Block
;
105
107
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
Block
&a);
109
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
Block
&a);
110
111
class
AbstractData
;
112
114
117
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
AbstractData
&a);
118
120
123
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
AbstractData
&a);
124
126
131
ABDFileIn
&
get
(
ABDFileIn
& f,
AbstractData
&a, std::shared_ptr<double> d);
132
134
137
void
writeABD
(
const
string
&fileName,
const
AbstractData
& data,
const
string
& name);
138
139
140
//------------------------IMPLEMENTATION------------------------------
141
142
ABDFileIn::ABDFileIn
():ifstream()
143
{};
144
ABDFileIn::ABDFileIn
(
string
name):
145
ifstream(name,ios::
in
| ios::binary)
146
{}
147
148
ABDFileOut::ABDFileOut
():ofstream()
149
{}
150
ABDFileOut::ABDFileOut
(
string
name):
151
ofstream(name,ios::out | ios::binary)
152
{}
153
154
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
int
a)
155
{
156
f.write((
char
*)&a,
sizeof
(
int
));
157
return
f;
158
}
159
160
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
int
& a)
161
{
162
f.read((
char
*)&a,
sizeof
(
int
));
163
return
f;
164
}
165
166
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
unsigned
int
a)
167
{
168
f.write((
char
*)&a,
sizeof
(
unsigned
int
));
169
return
f;
170
}
171
172
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
unsigned
int
& a)
173
{
174
f.read((
char
*)&a,
sizeof
(
unsigned
int
));
175
return
f;
176
}
177
178
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
float
a)
179
{
180
f.write((
char
*)&a,
sizeof
(
float
));
181
return
f;
182
}
183
184
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
float
& a)
185
{
186
f.read((
char
*)&a,
sizeof
(
float
));
187
return
f;
188
}
189
190
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
double
a)
191
{
192
f.write((
char
*)&a,
sizeof
(
double
));
193
return
f;
194
}
195
196
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
double
& a)
197
{
198
f.read((
char
*)&a,
sizeof
(
double
));
199
return
f;
200
}
201
202
203
template
<
typename
T>
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,pair<T*, unsigned int> a)
204
{
205
f.write((
char
*)a.first,
sizeof
(T)*a.second);
206
return
f;
207
}
208
template
<
typename
T>
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,pair<T*, unsigned int> a)
209
{
210
f.read((
char
*)a.first,
sizeof
(T)*a.second);
211
return
f;
212
}
213
214
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
string
&a){
215
unsigned
int
n=a.size();
216
f<<n<<make_pair(&a[0],n);
217
return
f;
218
}
219
220
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
string
&a){
221
unsigned
int
n;
222
f>>n; a.resize(n);
223
f>>make_pair(a.data(),n);
224
return
f;
225
}
226
227
template
<
typename
T>
inline
ABDFileOut
&
operator <<
(
ABDFileOut
& f,
const
AVec<T>
& a)
228
{
229
unsigned
int
n(a.
getSize
());
230
f<<n<<make_pair(&(a[0]),n);
231
return
f;
232
}
233
234
template
<
typename
T>
inline
ABDFileIn
&
operator >>
(
ABDFileIn
& f,
AVec<T>
& a)
235
{
236
unsigned
int
n(0);
237
f>>n;
238
a.
resize
(n);
239
f>>make_pair(&(a[0]),n);
240
return
f;
241
}
242
243
244
}
// asl
245
246
#endif
//ASLVTKFORMAT_H
247
aslDataWrapper.h
asl::ABDFileIn
ABD (ASL Binary Dump) file, input.
Definition
aslABDFormat.h:49
asl::ABDFileIn::ABDFileIn
ABDFileIn()
Definition
aslABDFormat.h:142
asl::ABDFileIn::get
ABDFileIn & get(ABDFileIn &f, AbstractData &a, std::shared_ptr< double > d)
reads data. It is assumed that the class has the propper size
asl::ABDFileOut
ABD (ASL Binary Dump) file, output.
Definition
aslABDFormat.h:59
asl::ABDFileOut::ABDFileOut
ABDFileOut()
Definition
aslABDFormat.h:148
asl::AVec
Definition
aslVectorsDynamicLength.h:40
asl::AVec::getSize
const unsigned int & getSize() const
Definition
aslVectorsDynamicLength.h:171
asl::AVec::resize
void resize(unsigned int newSize)
Definition
aslVectorsDynamicLength.h:223
asl::AbstractData
Definition
aslDataWrapper.h:53
asl::Block
Definition
aslBlocks.h:57
asl::writeABD
void writeABD(const string &fileName, const AbstractData &data, const string &name)
writes data in a file with ABD (ASL Binary Dump) format
asl
Advanced Simulation Library.
Definition
aslDataInc.h:31
asl::in
bool in(const T &xx, const T &x1, const T &x2)
Checks the belonging to a closed interval [x1,x2], .
Definition
aslUtilities.h:84
asl::operator<<
std::ostream & operator<<(std::ostream &output, const std::vector< T > &vector)
Prints elements of the vector separated by space.
Definition
aslUtilities.h:173
asl::operator>>
ABDFileIn & operator>>(ABDFileIn &f, int &a)
Definition
aslABDFormat.h:160
std
STL namespace.
Generated by
1.17.0