Loading...
Searching...
No Matches
fileHandler.cpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#include <iostream>
26#include <iomanip>
27#include <fstream>
28#include <sstream>
29
30#include"bitpit_common.hpp"
31
32#include"fileHandler.hpp"
33
34namespace bitpit{
35
42 : directory("./"), name("file"), appendix("dat"),
43 series(false), counter(0),
44 parallel(false), block(0) {
45}
46
55FileHandler::FileHandler(const std::string &dir_, const std::string &name_, const std::string &app_)
56 : directory(dir_), name(name_), appendix(app_),
57 series(false), counter(0),
58 parallel(false), block(0) {
59}
60
66
67 (*this) = other ;
68
69}
70
75
76 directory = other.directory ;
77 name = other.name ;
78 appendix = other.appendix ;
79 series = other.series ;
80 counter = other.counter ;
81 parallel = other.parallel ;
82 block = other.block ;
83
84
85 return *this ;
86}
87
92bool FileHandler::exists() const {
93 std::ifstream f( getPath() );
94 return f.good() ;
95}
96
101std::string FileHandler::getPath() const {
102 std::stringstream filename ;
103
104 if (!directory.empty()) filename << directory << "/";
105 filename << name;
106 if(parallel) filename <<".b"<< bitpit::utils::string::zeroPadNumber(4, block) ;
107 if(series) filename <<"." << bitpit::utils::string::zeroPadNumber(4, counter) ;
108 filename <<"."<< appendix ;
109
110 return filename.str() ;
111
112}
113
118const std::string & FileHandler::getDirectory() const {
119
120 return directory;
121}
122
127const std::string & FileHandler::getName() const {
128
129 return name;
130}
131
136const std::string & FileHandler::getAppendix() const {
137
138 return appendix;
139}
140
145void FileHandler::setDirectory(const std::string &d_){
146 directory=d_;
147 return;
148}
149
154void FileHandler::setName(const std::string &n_){
155 name=n_;
156 return;
157}
158
163void FileHandler::setAppendix(const std::string &a_){
164 appendix=a_;
165 return;
166}
167
173 return series;
174}
175
181 series=s_;
182 return;
183}
184
192 if (series) {
193 return counter;
194 } else {
195 return INVALID_COUNTER;
196 }
197}
198
204 counter=c_;
205 return;
206}
207
212 counter++;
213 return;
214}
215
221 return parallel;
222}
223
229 parallel=p_;
230 return;
231}
232
238 return block;
239}
240
246 block=b_;
247 return;
248}
249
250}
Creates file names and checks status.
std::string getPath() const
void setParallel(bool p_)
static BITPIT_PUBLIC_API const int INVALID_COUNTER
bool isSeries() const
bool isParallel() const
const std::string & getDirectory() const
void setDirectory(const std::string &d_)
const std::string & getAppendix() const
void setName(const std::string &n_)
FileHandler & operator=(const FileHandler &other)
bool exists() const
void setCounter(int c_)
const std::string & getName() const
void setBlock(int b_)
void setSeries(bool s_)
void setAppendix(const std::string &a_)
std::string zeroPadNumber(int nchars, int num)
--- layout: doxygen_footer ---