OOFEM 3.0
Loading...
Searching...
No Matches
datareader.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 - 2025 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 "datareader.h"
36
37
38namespace oofem{
39
40InputRecord *DataReader::giveChildRecord( const std::shared_ptr<InputRecord> &ir, InputFieldType ift, const std::string &name, InputRecordType irType, bool optional )
41{
42 if ( ir->hasChild( ift, name, optional ) ) return &( this->giveInputRecord( irType, /*recordId*/ 1 ) );
43 return nullptr;
44};
45
46DataReader::GroupRecords DataReader::giveGroupRecords( const std::shared_ptr<InputRecord> &ir, InputFieldType ift, const std::string &name, InputRecordType irType, bool optional )
47{
48 return GroupRecords( *this, name, irType, ir->giveGroupCount( ift, name, optional ) );
49}
50
51DataReader::GroupRecords DataReader::giveGroupRecords(const std::string& name, InputRecordType irType, int numRequired)
52{
53 int count=giveGroupCount(name);
54 if(count>=0 && numRequired>=0 && count!=numRequired) OOFEM_ERROR("Mismatch in %s: %d records of type '%s' required, %d found.",giveReferenceName().c_str(),numRequired,name.c_str(),count);
55 return GroupRecords(*this,name,irType,numRequired>=0?numRequired:count);
56}
57
58DataReader::GroupRecords::Iterator::Iterator( DataReader &dr_, const std::string &group_, InputRecordType irType_, int size_, int index_ ) :
59 dr( dr_ ), group( group_ ), irType( irType_ ), size( size_ ), index( index_ )
60{
61 /* read the first line for begin(), unless there are no lines to read at all */
62 if ( index == 0 && size_ > 0 ) {
63 if ( !this->group.empty() ) {
64 entered = true;
65 dr.enterGroup( this->group );
66 }
67 irPtr = &dr.giveInputRecord( irType, /*recordId*/ 1 );
68 if ( irPtr ) dr.enterRecord( irPtr );
69 }
70 #if 0
71 // open 0-sized group to mark it as processed
72 if(index==0 && size_==0 && !this->group.empty() && dr.hasGroup(this->group)){ dr.enterGroup(this->group); dr.leaveGroup(this->group); }
73 #endif
74};
75
76
78{
79 if ( irPtr ) dr.leaveRecord( irPtr );
80 index++;
81 /* don't read past the last line, assign nullptr instead */
82 if ( index >= size ) {
83 irPtr = nullptr;
84 if ( entered ) dr.leaveGroup( this->group );
85 } else {
86 irPtr = &dr.giveInputRecord( irType, /*recordId*/ index + 1 );
87 if ( irPtr ) dr.enterRecord( irPtr );
88 }
89 return *this;
90}
91
92
93DataReader::GroupRecords::GroupRecords( DataReader &dr_, const std::string &group_, InputRecordType irType_, int size ) :
94 dr( dr_ ), group( group_ ), irType( irType_ ), size_( size ){};
95
96
97
98}; // namespace oofem
Iterator(DataReader &dr_, const std::string &group_, InputRecordType irType_, int size_, int index_)
Definition datareader.C:58
Internal range-like class, return type for giveGroupRecords methods.
Definition datareader.h:137
GroupRecords(DataReader &dr_, const std::string &group_, InputRecordType irType_, int size)
Definition datareader.C:93
virtual std::string giveReferenceName() const =0
Gives the reference file name (e.g. file name).
InputRecordType
Determines the type of input record.
Definition datareader.h:64
virtual InputRecord & giveInputRecord(InputRecordType irType, int recordId)=0
GroupRecords giveGroupRecords(const std::shared_ptr< InputRecord > &ir, InputFieldType ift, const std::string &name, InputRecordType irType, bool optional)
Definition datareader.C:46
virtual int giveGroupCount(const std::string &name)
Definition datareader.h:170
InputRecord * giveChildRecord(const std::shared_ptr< InputRecord > &ir, InputFieldType ift, const std::string &name, InputRecordType irType, bool optional)
Return pointer to subrecord of given type (must be exactly one); if not present, returns nullptr.
Definition datareader.C:40
#define OOFEM_ERROR(...)
Definition error.h:79
const char * InputFieldType
Identifier of fields in input records.
Definition inputrecord.h:59

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011