Flow123d  release_2.2.0-914-gf1a3a4f
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 "io/msh_basereader.hh"
23 #include "mesh/mesh.h"
24 #include "system/file_path.hh"
25 
26 #include <memory>
27 
28 
29 
30 /**
31  * Auxiliary class to map filepaths to instances of readers.
32  */
33 class ReaderCache {
34 public:
35  struct ReaderData {
36  std::shared_ptr<BaseMeshReader> reader_;
37  std::shared_ptr<Mesh> mesh_;
38  };
39 
41 
42  /**
43  * Returns reader of given FilePath.
44  */
45  static std::shared_ptr<BaseMeshReader> get_reader(const FilePath &file_path);
46 
47  /**
48  * Returns mesh of given FilePath.
49  */
50  static std::shared_ptr<Mesh> get_mesh(const FilePath &file_path);
51 
52 private:
53  /// Returns singleton instance
54  static ReaderCache * instance();
55 
56  /// Constructor
58 
59  /// Returns instance of given FilePath. If reader doesn't exist, creates new ReaderData object.
60  static ReaderTable::iterator get_reader_data(const FilePath &file_path);
61 
62  /// Table of readers
63  ReaderTable reader_table_;
64 };
65 
66 
67 #endif /* READER_CACHE_HH_ */
ReaderCache()
Constructor.
Definition: reader_cache.hh:57
static ReaderCache * instance()
Returns singleton instance.
Definition: reader_cache.cc:29
std::shared_ptr< BaseMeshReader > reader_
Definition: reader_cache.hh:36
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:50
std::shared_ptr< Mesh > mesh_
Definition: reader_cache.hh:37
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:63
static std::shared_ptr< Mesh > get_mesh(const FilePath &file_path)
Definition: reader_cache.cc:38
static std::shared_ptr< BaseMeshReader > get_reader(const FilePath &file_path)
Definition: reader_cache.cc:34
std::map< string, ReaderData > ReaderTable
Definition: reader_cache.hh:40