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