dune-grid
2.11
Toggle main menu visibility
Loading...
Searching...
No Matches
dune
grid
io
file
gmsh
utility
version.hh
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4
#ifndef DUNE_GRID_IO_FILE_GMSH_UTILITY_VERSION_HH
5
#define DUNE_GRID_IO_FILE_GMSH_UTILITY_VERSION_HH
6
7
#include <iostream>
8
#include <fstream>
9
#include <string>
10
#include <vector>
11
12
#include <dune/common/exceptions.hh>
13
#include "
string.hh
"
14
15
namespace
Dune::Impl::Gmsh
16
{
18
inline
std::vector<int> fileVersion(std::string filename)
19
{
20
std::ifstream file(filename, std::ios_base::in);
21
std::string section;
22
file >> section;
23
24
if
(section !=
"$MeshFormat"
)
25
DUNE_THROW(Dune::IOError,
"Invalid header of msh file."
);
26
27
std::string version;
28
int
file_type = -1;
29
int
data_size = -1;
30
file >> version >> file_type >> data_size;
31
32
if
(std::stod(version) <= 0.0)
33
DUNE_THROW(Dune::IOError,
"Invalid version number in msh file."
);
34
35
if
(file_type != 0 and file_type != 1)
36
DUNE_THROW(Dune::IOError,
"Invalid file-type: 0 for ASCII mode, 1 for binary mode."
);
37
38
if
(data_size < 4 || data_size > 16)
39
DUNE_THROW(Dune::IOError,
"Invalid data-size range: should be in {4, 16}"
);
40
41
std::vector<int> version_tuple;
42
split(version.begin(), version.end(),
'.'
, [&](
auto
first,
auto
last) {
43
version_tuple.push_back(std::stoi(std::string{first,last}));
44
});
45
46
return
version_tuple;
47
}
48
}
49
50
#endif
string.hh
Generated by
1.17.0