From f72bebc2fb63cee057cd73fb8e6a3ff102305781 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Fri, 11 Jan 2019 13:14:23 +0100 Subject: [PATCH] [GO2OGS] Impl. of Layer. --- Applications/FileIO/GocadIO/Layer.cpp | 61 +++++++++++++++++++++++++++ Applications/FileIO/GocadIO/Layer.h | 38 +++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 Applications/FileIO/GocadIO/Layer.cpp create mode 100644 Applications/FileIO/GocadIO/Layer.h diff --git a/Applications/FileIO/GocadIO/Layer.cpp b/Applications/FileIO/GocadIO/Layer.cpp new file mode 100644 index 00000000000..bc988f9707a --- /dev/null +++ b/Applications/FileIO/GocadIO/Layer.cpp @@ -0,0 +1,61 @@ +/** + * + * @copyright + * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/LICENSE.txt + */ + +#include <algorithm> +#include <iterator> +#include <sstream> + +#include <logog/include/logog.hpp> + +#include "Layer.h" + +namespace FileIO +{ +namespace Gocad +{ + +std::ostream& operator<<(std::ostream& os, Layer const& l) +{ + std::copy(l.regions.begin(), l.regions.end(), + std::ostream_iterator<Gocad::Region>(os, " ")); + return os; +} + + +Layer parseLayer(std::string const& line, std::vector<Gocad::Region> const& regions) +{ + std::istringstream iss(line); + std::istream_iterator<std::string> it(iss); + // Check first word is MODEL_LAYER. + if (*it != std::string("MODEL_LAYER")) + { + ERR("Expected MODEL_LAYER keyword but '%s' found.\n", it->c_str()); + throw std::runtime_error( + "In parseRegion() expected MODEL_LAYER keyword not found.\n"); + } + ++it; + + Layer l; + while (it != std::istream_iterator<std::string>() && *it != "END") + { + auto const& region_it = + std::find_if(regions.begin(), regions.end(), + [&](Gocad::Region const& r) { return r.name == *it; }); + if (region_it != regions.end()) + { + l.regions.push_back(*region_it); + } + ++it; + } + + return l; +} + +} // end namespace Gocad +} // end namespace FileIO diff --git a/Applications/FileIO/GocadIO/Layer.h b/Applications/FileIO/GocadIO/Layer.h new file mode 100644 index 00000000000..2fa2b0e2ba8 --- /dev/null +++ b/Applications/FileIO/GocadIO/Layer.h @@ -0,0 +1,38 @@ +/** + * + * @copyright + * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/LICENSE.txt + */ + +#pragma once + +#include <string> +#include <vector> + +#include "Region.h" + +namespace FileIO +{ +namespace Gocad +{ +// Each model layer own several regions. +struct Layer final +{ + std::vector<Region> regions; + + bool hasRegion(Region const& r) const + { + return (std::find(regions.begin(), regions.end(), r) != regions.end()); + } +}; + +std::ostream& operator<<(std::ostream& os, Layer const& l); + +Layer parseLayer(std::string const& line, + std::vector<Gocad::Region> const& regions); + +} // end namespace Gocad +} // end namespace FileIO -- GitLab