Flow123d  release_3.0.0-968-gc359144
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 
27 class BaseMeshReader;
28 class Mesh;
29 
30 
31 
32 /**
33  * Auxiliary class to map filepaths to instances of readers.
34  */
35 class ReaderCache {
36 public:
37  struct ReaderData {
38  std::shared_ptr<BaseMeshReader> reader_;
39  std::shared_ptr<Mesh> mesh_;
40  };
41 
43 
44  /**
45  * Returns reader of given FilePath.
46  */
47  static std::shared_ptr<BaseMeshReader> get_reader(const FilePath &file_path);
48 
49  /**
50  * Returns mesh of given FilePath.
51  */
52  static std::shared_ptr<Mesh> get_mesh(const FilePath &file_path);
53 
54  /**
55  * Check if nodes and elements of reader mesh are compatible with \p mesh and fill element id vectors of reader.
56  */
57  static bool check_compatible_mesh(const FilePath &file_path, Mesh &mesh);
58 
59  /**
60  * Fill element id vectors of reader without checking compatibility.
61  */
62  static void get_element_ids(const FilePath &file_path, const Mesh &mesh);
63 
64 private:
65  /// Returns singleton instance
66  static ReaderCache * instance();
67 
68  /// Constructor
70 
71  /// Returns instance of given FilePath. If reader doesn't exist, creates new ReaderData object.
72  static ReaderTable::iterator get_reader_data(const FilePath &file_path);
73 
74  /// Table of readers
75  ReaderTable reader_table_;
76 };
77 
78 
79 #endif /* READER_CACHE_HH_ */
static void get_element_ids(const FilePath &file_path, const Mesh &mesh)
Definition: reader_cache.cc:80
Definition: mesh.h:76
ReaderCache()
Constructor.
Definition: reader_cache.hh:69
static ReaderCache * instance()
Returns singleton instance.
Definition: reader_cache.cc:31
std::shared_ptr< BaseMeshReader > reader_
Definition: reader_cache.hh:38
static bool check_compatible_mesh(const FilePath &file_path, Mesh &mesh)
Definition: reader_cache.cc:73
static ReaderTable::iterator get_reader_data(const FilePath &file_path)
Returns instance of given FilePath. If reader doesn&#39;t exist, creates new ReaderData object...
Definition: reader_cache.cc:53
std::shared_ptr< Mesh > mesh_
Definition: reader_cache.hh:39
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
ReaderTable reader_table_
Table of readers.
Definition: reader_cache.hh:75
static std::shared_ptr< Mesh > get_mesh(const FilePath &file_path)
Definition: reader_cache.cc:40
static std::shared_ptr< BaseMeshReader > get_reader(const FilePath &file_path)
Definition: reader_cache.cc:36
std::map< string, ReaderData > ReaderTable
Definition: reader_cache.hh:42