OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
dynamicdatareader.C
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 #include "dynamicdatareader.h"
36 #include "inputrecord.h"
37 #include "error.h"
38 
39 #include <memory>
40 #include <fstream>
41 
42 namespace oofem {
43 DynamicDataReader :: DynamicDataReader(std :: string name) : DataReader(), name(std :: move(name))
44 {
45  this->it = recordList.end();
46 }
47 
49 {
50 }
51 
52 void
54 {
55  // Should care about the record type, but its a hassle.
56  this->recordList.emplace_back(record);
57  this->it = recordList.end();
58 }
59 
62 {
63  // Ignores recordId in favor of having a dynamic list (just incremental access). typeId could be supported, but its a hassle.
64  // The txt data reader makes the same assumptions.
65  if ( this->it == this->recordList.end() ) {
66  this->it = this->recordList.begin();
67  } else {
68  ++this->it;
69  }
70  return this->it->get();
71 }
72 
73 bool
74 DynamicDataReader :: peakNext(const std :: string &keyword)
75 {
76  std :: string nextKey;
77  auto temp = this->it;
78  temp++;
79  (*temp)->giveRecordKeywordField(nextKey);
80  return keyword.compare( nextKey ) == 0;
81 }
82 
83 void
85 {
86  this->recordList.clear();
87 }
88 
89 void
90 DynamicDataReader :: writeToFile(const char *fileName)
91 {
92  std :: ofstream fout(fileName);
93 
94  fout << this->outputFileName << '\n';
95  fout << this->description << '\n';
96  for ( auto &rec: this->recordList ) {
97  fout << rec->giveRecordAsString() << "\n";
98  }
99  fout.close();
100 }
101 } // end namespace oofem
std::vector< std::unique_ptr< InputRecord > > recordList
All record types will be appended to this list, no split in terms of InputRecordType is implemented y...
virtual bool peakNext(const std::string &keyword)
Peak in advance into the record list.
Class representing the abstraction for input data source.
Definition: datareader.h:50
void writeToFile(const char *fileName)
Writes all input records to file.
virtual InputRecord * giveInputRecord(InputRecordType, int recordId)
Returns input record corresponding to given InputRecordType value and its record_id.
virtual void finish()
Allows to detach all data connections.
std::vector< std::unique_ptr< InputRecord > >::iterator it
Keeps track of the current position in the list.
std::string description
Description line (second line in OOFEM input files).
Definition: datareader.h:56
Class representing the general Input Record.
Definition: inputrecord.h:101
InputRecordType
Determines the type of input record.
Definition: datareader.h:60
std::string outputFileName
Output file name (first line in OOFEM input files).
Definition: datareader.h:54
DynamicDataReader(std::string name)
Constructor.
the oofem namespace is to define a context or scope in which all oofem names are defined.
void insertInputRecord(InputRecordType type, InputRecord *record)
Main purpose of this class it the possibility to add new input records in code.

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