Flow123d  3.9.0-97067769b
reader_cache.hh
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_cache.hh
15  * @brief
16  */
17 
18 #ifndef READER_CACHE_HH_
19 #define READER_CACHE_HH_
20 
21 
22 #include <map> // for map, map<>::value_compare
23 #include <memory> // for shared_ptr
24 #include <string> // for string
25 #include "system/file_path.hh" // for FilePath
26 #include "system/index_types.hh" // for LongIdx
27 
28 class BaseMeshReader;
29 class Mesh;
30 class EquivalentMeshMap;
31 
32 
33 
34 /**
35  * Auxiliary class to map filepaths to instances of readers.
36  */
37 class ReaderCache {
38 public:
39  struct ReaderData {
40  /// Constructor
42 
43  std::shared_ptr<BaseMeshReader> reader_;
44  std::shared_ptr<Mesh> mesh_;
45  std::shared_ptr<EquivalentMeshMap> target_mesh_element_map_;
46  };
47 
49 
50  /**
51  * Returns reader of given FilePath.
52  */
53  static std::shared_ptr<BaseMeshReader> get_reader(const FilePath &file_path);
54 
55  /**
56  * Returns mesh of given FilePath.
57  */
58  static std::shared_ptr<Mesh> get_mesh(const FilePath &file_path);
59 
60  /**
61  * Fill element id vectors of reader without checking compatibility.
62  */
63  static void get_element_ids(const FilePath &file_path, const Mesh &mesh);
64 
65  /**
66  * Returns shared vector mapping elements to target mesh.
67  *
68  * Reader and appropriate input data mesh are given by FilePath.
69  * If map is not created method check_compatible_mesh of \p computational_mesh is called.
70  */
71  static std::shared_ptr<EquivalentMeshMap> eqivalent_mesh_map(const FilePath &file_path,
72  Mesh *computational_mesh);
73 
74  static std::shared_ptr<EquivalentMeshMap> identic_mesh_map(const FilePath &file_path,
75  Mesh *computational_mesh);
76 
77 private:
78  /// Returns singleton instance
79  static ReaderCache * instance();
80 
81  /// Constructor
83 
84  /// Returns instance of given FilePath. If reader doesn't exist, creates new ReaderData object.
85  static ReaderTable::iterator get_reader_data(const FilePath &file_path);
86 
87  /// Table of readers
89 };
90 
91 
92 #endif /* READER_CACHE_HH_ */
ReaderCache::identic_mesh_map
static std::shared_ptr< EquivalentMeshMap > identic_mesh_map(const FilePath &file_path, Mesh *computational_mesh)
Definition: reader_cache.cc:94
ReaderCache::eqivalent_mesh_map
static std::shared_ptr< EquivalentMeshMap > eqivalent_mesh_map(const FilePath &file_path, Mesh *computational_mesh)
Definition: reader_cache.cc:118
ReaderCache::instance
static ReaderCache * instance()
Returns singleton instance.
Definition: reader_cache.cc:32
file_path.hh
ReaderCache::get_element_ids
static void get_element_ids(const FilePath &file_path, const Mesh &mesh)
Definition: reader_cache.cc:74
ReaderCache::ReaderCache
ReaderCache()
Constructor.
Definition: reader_cache.hh:82
FilePath
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
ReaderCache::ReaderData::ReaderData
ReaderData()
Constructor.
Definition: reader_cache.hh:41
index_types.hh
ReaderCache::ReaderData::mesh_
std::shared_ptr< Mesh > mesh_
Definition: reader_cache.hh:44
BaseMeshReader
Definition: msh_basereader.hh:58
ReaderCache::get_reader_data
static ReaderTable::iterator get_reader_data(const FilePath &file_path)
Returns instance of given FilePath. If reader doesn't exist, creates new ReaderData object.
Definition: reader_cache.cc:54
std::map< string, ReaderData >
Mesh
Definition: mesh.h:361
EquivalentMeshMap
Definition: mesh.h:79
ReaderCache::ReaderData::target_mesh_element_map_
std::shared_ptr< EquivalentMeshMap > target_mesh_element_map_
Definition: reader_cache.hh:45
ReaderCache::get_mesh
static std::shared_ptr< Mesh > get_mesh(const FilePath &file_path)
Definition: reader_cache.cc:41
ReaderCache::ReaderData
Definition: reader_cache.hh:39
ReaderCache::get_reader
static std::shared_ptr< BaseMeshReader > get_reader(const FilePath &file_path)
Definition: reader_cache.cc:37
ReaderCache::reader_table_
ReaderTable reader_table_
Table of readers.
Definition: reader_cache.hh:88
ReaderCache::ReaderData::reader_
std::shared_ptr< BaseMeshReader > reader_
Definition: reader_cache.hh:41
ReaderCache::ReaderTable
std::map< string, ReaderData > ReaderTable
Definition: reader_cache.hh:48
ReaderCache
Definition: reader_cache.hh:37