Flow123d  release_2.2.0-41-g0958a8d
reader_instances.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file reader_instances.cc
15  * @brief
16  */
17 
18 #include "io/reader_instances.hh"
19 #include "io/msh_gmshreader.h"
20 #include "io/msh_vtkreader.hh"
21 
24  return instance;
25 }
26 
27 std::shared_ptr<BaseMeshReader> ReaderInstances::get_reader(const FilePath &file_name) {
28  ReaderTable::iterator it = reader_table_.find( string(file_name) );
29  if (it == reader_table_.end()) {
30  std::shared_ptr<BaseMeshReader> reader_ptr;
31  if ( file_name.extension() == ".msh" ) {
32  reader_ptr = std::make_shared<GmshMeshReader>(file_name);
33  } else if ( file_name.extension() == ".vtu" ) {
34  reader_ptr = std::make_shared<VtkMeshReader>(file_name);
35  } else {
36  THROW(BaseMeshReader::ExcWrongExtension()
37  << BaseMeshReader::EI_FileExtension(file_name.extension()) << BaseMeshReader::EI_MeshFile((string)file_name) );
38  }
39  reader_table_.insert( std::pair<string, std::shared_ptr<BaseMeshReader>>(string(file_name), reader_ptr) );
40  return reader_ptr;
41  } else {
42  return (*it).second;
43  }
44 }
ReaderTable reader_table_
Table of readers.
std::shared_ptr< BaseMeshReader > get_reader(const FilePath &file_name)
string extension() const
Definition: file_path.cc:198
ReaderInstances()
Constructor.
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
static ReaderInstances * instance()
Returns singleton instance.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53