Stride Reference Manual  - generated for commit 9643b11
GeoGridReaderFactory.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2018, Jan Broeckhove and Bistromatics group.
14  */
15 
16 #include "GeoGridReaderFactory.h"
17 
18 //#include "GeoGridJSONReader.h"
19 #include "GeoGridProtoReader.h"
20 #include "GeoGridReader.h"
21 #include "util/Exception.h"
22 
23 #include <fstream>
24 
25 #ifdef BOOST_FOUND
26 #include <boost/filesystem.hpp>
27 #include <boost/filesystem/path.hpp>
28 namespace filesys = boost::filesystem;
29 #else
30 #include <filesystem>
31 namespace filesys = std::filesystem;
32 #endif
33 
34 namespace geopop {
35 
36 std::shared_ptr<GeoGridReader> GeoGridReaderFactory::CreateReader(const std::string& filename,
37  stride::Population* pop) const
38 {
39  const filesys::path path(filename);
40  if (!filesys::exists(path)) {
41  throw stride::util::Exception("GeoGridReaderFactory::CreateReader> File not found: " + path.string());
42  }
43 
44  /*if (path.extension().string() == ".json") {
45  //return std::make_shared<GeoGridJSONReader>(std::make_unique<std::ifstream>(path.string()), pop);
46  } else */
47  if (path.extension().string() == ".proto") {
48  return std::make_shared<GeoGridProtoReader>(std::make_unique<std::ifstream>(path.string()), pop);
49  } else {
50  throw stride::util::Exception("GeoGridReaderFactory::CreateReader> Unsupported file extension: " +
51  path.extension().string());
52  }
53 }
54 
55 } // namespace geopop
std::shared_ptr< GeoGridReader > CreateReader(const std::string &filename, stride::Population *pop) const
Create a GeoGridReader based on the provided extension in the filename.
Basic exception class: needed to prevent clang-tidy warning "thrown exception type is not nothrow cop...
Definition: Exception.h:28
Key Data structure: container for (a) all individuals in the population (b) the ContactPoolSys wchich...
Definition: Population.h:47
Namespace for the geographic and demograhic classes.
Definition: Coordinate.h:21