VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
UbFileOutput.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef UBFILEOUTPUT_H
35#define UBFILEOUTPUT_H
36
37#include <fstream>
38#include <iomanip>
39#include <iostream>
40#include <string>
41
43
44/*=========================================================================*/
45/* UbFileOutput */
46/* */
54/*
55usage: ...
56*/
57
59{
60public:
63
64public:
66 UbFileOutput(const std::string &filename) : filename(filename) {}
67 virtual ~UbFileOutput() { outfile.flush(); }
68
69 virtual bool open(const std::string &filename, CREATEOPTION opt = OUTFILE) = 0;
70
71 virtual bool operator!() { return !(outfile); }
72 virtual bool isOpen() { return !(!(outfile)); }
73
74 virtual void flush() { outfile.flush(); }
75 virtual void close() { outfile.close(); }
76
77 virtual void writeInteger(const int &value, const int &width = 0) = 0;
78 virtual void writeDouble(const double &value, const int &width = 0) = 0;
79 virtual void writeFloat(const float &value, const int &width = 0) = 0;
80 virtual void writeBool(const bool &value, const int &width = 0) = 0;
81 virtual void writeSize_t(const std::size_t &value, const int &width = 0) = 0;
82 virtual void writeChar(const char &value, const int &width = 0) = 0;
83 virtual void writeString(const std::string &value, const int &width = 0) = 0;
84 virtual void writeStringOnly(const std::string &value) = 0;
85 virtual void writeLine(const std::string &value, const int &width = 0) = 0;
86 virtual void writeLine() = 0;
87
88 virtual void writeCommentLine(const std::string &line) = 0;
89 virtual void writeCommentLine(char indicator, const std::string &line) = 0;
90 virtual void writeCopyOfFile(const std::string &filename) = 0;
91
92 virtual void setCommentIndicator(char commentindicator) { this->commentindicator = commentindicator; }
93
94 virtual void setPrecision(const int &precision) = 0;
95 virtual int getPrecision() = 0;
96
97 // returns "ASCII", "BINARY"
98 virtual FILETYPE getFileType() = 0;
99
100 // returns file extension:
101 // e.g. "./../test/ich.inp" -> "inp", "./../test/ich" -> ""
102 virtual std::string getFileExtension()
103 {
104 std::size_t pos1 = filename.rfind("/");
105 if (pos1 == std::string::npos)
106 pos1 = 0;
107 std::size_t pos2 = filename.rfind(".");
108 if (pos2 != std::string::npos && pos2 > pos1)
109 return filename.substr(pos2 + 1);
110
111 return "";
112 }
113
114 virtual std::string getFileName() { return this->filename; }
115
116protected:
117 std::ofstream outfile;
118 std::string filename;
119 char commentindicator{ 'C' };
120};
121
122#endif // UBFILEOUTPUT_H
123
virtual std::string getFileExtension()
std::ofstream outfile
virtual void writeCommentLine(char indicator, const std::string &line)=0
virtual void setPrecision(const int &precision)=0
virtual void writeCopyOfFile(const std::string &filename)=0
virtual bool operator!()
virtual bool open(const std::string &filename, CREATEOPTION opt=OUTFILE)=0
virtual int getPrecision()=0
virtual void writeDouble(const double &value, const int &width=0)=0
virtual void setCommentIndicator(char commentindicator)
virtual FILETYPE getFileType()=0
virtual ~UbFileOutput()
virtual void writeChar(const char &value, const int &width=0)=0
virtual std::string getFileName()
virtual void flush()
virtual void writeBool(const bool &value, const int &width=0)=0
virtual void writeLine(const std::string &value, const int &width=0)=0
UbFileOutput(const std::string &filename)
virtual bool isOpen()
virtual void writeLine()=0
char commentindicator
virtual void writeInteger(const int &value, const int &width=0)=0
virtual void writeString(const std::string &value, const int &width=0)=0
virtual void writeStringOnly(const std::string &value)=0
virtual void writeCommentLine(const std::string &line)=0
virtual void writeSize_t(const std::size_t &value, const int &width=0)=0
virtual void close()
std::string filename
virtual void writeFloat(const float &value, const int &width=0)=0
std::shared_ptr< T > SPtr