Flow123d  intersections_paper-476-gbe68821
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 "mesh/reader_instances.hh"
19 #include "input/accessors.hh"
20 
21 
24  return instance;
25 }
26 
27 std::shared_ptr<GmshMeshReader> ReaderInstance::get_reader(const FilePath &file_path) {
28  return ReaderInstance::get_instance(file_path).reader_;
29 }
30 
31 std::shared_ptr<Mesh> ReaderInstance::get_mesh(const FilePath &file_path) {
32  return ReaderInstance::get_instance(file_path).mesh_;
33 }
34 
36  ReaderTable::iterator it = ReaderInstance::instance()->reader_table_.find( string(file_path) );
37  if (it == ReaderInstance::instance()->reader_table_.end()) {
38  ReaderData reader_data;
39  reader_data.reader_ = std::make_shared<GmshMeshReader>(file_path);
40  reader_data.mesh_ = std::make_shared<Mesh>( Input::Record() );
41  reader_data.reader_->read_mesh( reader_data.mesh_.get() );
42  ReaderInstance::instance()->reader_table_.insert( std::pair<string, ReaderData>(string(file_path), reader_data) );
43  return reader_data;
44  } else {
45  return (*it).second;
46  }
47 }
48 
49 
52  return instance;
53 }
54 
55 std::shared_ptr<GmshMeshReader> ReaderInstances::get_reader(const FilePath &file_path) {
56  ReaderTable::iterator it = reader_table_.find( string(file_path) );
57  if (it == reader_table_.end()) {
58  std::shared_ptr<GmshMeshReader> reader_ptr = std::make_shared<GmshMeshReader>(file_path);
59  reader_table_.insert( std::pair<string, std::shared_ptr<GmshMeshReader>>(string(file_path), reader_ptr) );
60  return reader_ptr;
61  } else {
62  return (*it).second;
63  }
64 }
std::shared_ptr< GmshMeshReader > reader_
ReaderInstance()
Constructor.
static ReaderData get_instance(const FilePath &file_path)
Returns instance of given FilePath. If reader doesn&#39;t exist, creates new ReaderData object...
Accessor to the data with type Type::Record.
Definition: accessors.hh:286
ReaderTable reader_table_
Table of readers.
static std::shared_ptr< GmshMeshReader > get_reader(const FilePath &file_path)
static std::shared_ptr< Mesh > get_mesh(const FilePath &file_path)
std::shared_ptr< Mesh > mesh_
Dedicated class for storing path to input and output files.
Definition: file_path.hh:48
std::shared_ptr< GmshMeshReader > get_reader(const FilePath &file_path)
static ReaderInstances * instance()
Returns singleton instance.
static ReaderInstance * instance()
Returns singleton instance.