swh:1:snp:6088ab52ef49920e01e3f334cdf4d5d6c8a822b9
Raw File
Tip revision: 01e08ecda21bacf86f089fd2c733a492278de697 authored by Dmitry Yu. Naumov on 06 July 2021, 21:18:06 UTC
Merge branch 'DoxygenFixes' into 'master'
Tip revision: 01e08ec
Layer.cpp
/**
 * \file
 * \copyright
 * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
 *              http://www.opengeosys.org/project/license
 */

#include "Layer.h"

#include <algorithm>
#include <iterator>
#include <sstream>

#include "BaseLib/Logging.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<Region>(os, " "));
    return os;
}

Layer parseLayer(std::string const& line, std::vector<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(),
                         [&](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
back to top