VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
UbFileOutputBinary.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 UBFILEOUTPUTBINARY_H
35#define UBFILEOUTPUTBINARY_H
36
37#include <fstream>
38#include <iomanip>
39#include <iostream>
40
43
44/*=========================================================================*/
45/* UbFileOutputBinary */
46/* */
54/*
55usage: ...
56*/
57
59{
60public:
62 UbFileOutputBinary(const std::string &filename, const bool &createPath = true);
64
65 bool open(const std::string &filename, UbFileOutput::CREATEOPTION opt = OUTFILE) override;
66
67 void writeInteger(const int &value, const int &width = 0) override;
68 void writeDouble(const double &value, const int &width = 0) override;
69 void writeFloat(const float &value, const int &width = 0) override;
70 void writeBool(const bool &value, const int &width = 0) override;
71 void writeChar(const char &value, const int &width = 0) override;
72 void writeSize_t(const std::size_t &value, const int &width = 0) override;
73 void writeString(const std::string &value, const int &width = 0) override;
74 void writeStringOnly(const std::string &value) override;
75 void writeLine(const std::string &value, const int &width = 0) override;
76 void writeLine() override;
77 void writeCommentLine(const std::string &line) override;
78 void writeCommentLine(char indicator, const std::string &line) override;
79 void writeCopyOfFile(const std::string &filename) override;
80
81 void setPrecision(const int &precision) override;
82 int getPrecision() override;
83
84 FILETYPE getFileType() override { return BINARY; }
85
86 template <typename T>
87 friend inline UbFileOutputBinary &operator<<(UbFileOutputBinary &file, const T &data)
88 {
89 file.outfile.write((char *)&data, sizeof(T));
90 return file;
91 }
92
93 template <typename T>
94 void writeVector(std::vector<T> &v)
95 {
96 size_t size = v.size();
97 if (size > 0) {
98 outfile.write((char *)&v[0], sizeof(T) * size);
99 }
100 }
101};
102
103#endif
104
void writeCommentLine(const std::string &line) override
void writeVector(std::vector< T > &v)
UbFileOutputBinary(const std::string &filename, const bool &createPath=true)
FILETYPE getFileType() override
friend UbFileOutputBinary & operator<<(UbFileOutputBinary &file, const T &data)
void writeCommentLine(char indicator, const std::string &line) override
UbFileOutputBinary(const std::string &filename, UbFileOutput::CREATEOPTION opt, const bool &createPath)
std::ofstream outfile
std::string filename
std::shared_ptr< T > SPtr
void writeStringOnly(const std::string &value) override
void writeSize_t(const std::size_t &value, const int &width=0) override
void writeString(const std::string &value, const int &width=0) override
void writeDouble(const double &value, const int &width=0) override
void writeBool(const bool &value, const int &width=0) override
void writeFloat(const float &value, const int &width=0) override
void writeInteger(const int &value, const int &width=0) override
void writeChar(const char &value, const int &width=0) override
bool open(const std::string &filename, UbFileOutput::CREATEOPTION opt=OUTFILE) override
void setPrecision(const int &precision) override
void writeCopyOfFile(const std::string &filename) override