OGS
Layer.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "Layer.h"
5
6#include <algorithm>
7#include <iterator>
8#include <sstream>
9
10#include "BaseLib/Logging.h"
11
12namespace FileIO
13{
14namespace Gocad
15{
16std::ostream& operator<<(std::ostream& os, Layer const& l)
17{
18 std::copy(l.regions.begin(), l.regions.end(),
19 std::ostream_iterator<Region>(os, " "));
20 return os;
21}
22
23Layer parseLayer(std::string const& line, std::vector<Region> const& regions)
24{
25 std::istringstream iss(line);
26 std::istream_iterator<std::string> it(iss);
27 // Check first word is MODEL_LAYER.
28 if (*it != std::string("MODEL_LAYER"))
29 {
30 ERR("Expected MODEL_LAYER keyword but '{:s}' found.\n", it->c_str());
31 throw std::runtime_error(
32 "In parseRegion() expected MODEL_LAYER keyword not found.\n");
33 }
34 ++it;
35
36 Layer l;
37 while (it != std::istream_iterator<std::string>() && *it != "END")
38 {
39 auto const& region_it =
40 std::find_if(regions.begin(), regions.end(),
41 [&](Region const& r) { return r.name == *it; });
42 if (region_it != regions.end())
43 {
44 l.regions.push_back(*region_it);
45 }
46 ++it;
47 }
48
49 return l;
50}
51
52} // end namespace Gocad
53} // end namespace FileIO
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::ostream & operator<<(std::ostream &os, CoordinateSystem const &c)
Layer parseLayer(std::string const &line, std::vector< Region > const &regions)
Definition Layer.cpp:23
std::vector< Region > regions
Definition Layer.h:19