Debian Codegraph @

src/writers/aslABDFormat.cxx

raw
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 #include "aslABDFormat.h"
25
26 #include "data/aslBlocks.h"
27 #include <acl/acl.h>
28 #include <utilities/aslSmartPtrUtils.h>
29 #include <acl/DataTypes/aclArray.h>
30
31 using namespace std;
32
33 namespace asl {
34
35 ABDFileOut & operator <<(ABDFileOut & f, const Block &b)
36 {
37 f<<b.dx<<b.getSize()<<b.position;
38 return f;
39 }
40
41 ABDFileIn & operator >>(ABDFileIn & f,Block &b)
42 {
43 double dx(0);
44 Block::V pos;
45 Block::DV size;
46 f>>dx>>size>>pos;
47
48 b.dx=dx;
49 b.position=pos;
50 b.setSize(size);
51
52 return f;
53 }
54
55 ABDFileOut & operator <<(ABDFileOut & f, const AbstractData &a)
56 {
57 unsigned int s(a.getDContainer()[0]->getSize());
58 double* d=new double[s];
59 copy(a.getDContainer()[0],d);
60 f<<std::make_pair(d,s);
61 delete[] d;
62 return f;
63 }
64
65 ABDFileIn & operator >>(ABDFileIn & f, AbstractData &a)
66 {
67 std::shared_ptr<double> d(acl::map<double>(a.getDContainer()[0]));
68 unsigned int s(a.getDContainer()[0]->getSize());
69 f>>std::make_pair(d.get(),s);
70 return f;
71 }
72
73 ABDFileIn & get(ABDFileIn & f, AbstractData &a, std::shared_ptr<double> d)
74 {
75 unsigned int s(a.getDContainer()[0]->getSize());
76 if (d.get()==0)
77 d.reset(new double[s],ArrayDeleter<double>());
78 f>>std::make_pair(d.get(),s);
79 copy(d.get(),a.getDContainer()[0]);
80 return f;
81 }
82
83
84 } //asl
85
86