LibrePCB Developers Documentation
libraryelementcache.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_LIBRARY_EDITOR_LIBRARYELEMENTCACHE_H
21 #define LIBREPCB_LIBRARY_EDITOR_LIBRARYELEMENTCACHE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 #include <librepcb/common/uuid.h>
28 
29 #include <QtCore>
30 
31 #include <memory>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 namespace workspace {
39 class WorkspaceLibraryDb;
40 }
41 
42 namespace library {
43 
44 class ComponentCategory;
45 class PackageCategory;
46 class Symbol;
47 class Package;
48 class Component;
49 class Device;
50 
51 namespace editor {
52 
53 /*******************************************************************************
54  * Class LibraryElementCache
55  ******************************************************************************/
56 
60 class LibraryElementCache final {
61  Q_DECLARE_TR_FUNCTIONS(LibraryElementCache)
62 
63 public:
64  // Constructors / Destructor
65  LibraryElementCache() = delete;
66  LibraryElementCache(const LibraryElementCache& other) = delete;
67  explicit LibraryElementCache(
68  const workspace::WorkspaceLibraryDb& db) noexcept;
69  ~LibraryElementCache() noexcept;
70 
71  // Getters
72  std::shared_ptr<const ComponentCategory> getComponentCategory(
73  const Uuid& uuid) const noexcept;
74  std::shared_ptr<const PackageCategory> getPackageCategory(
75  const Uuid& uuid) const noexcept;
76  std::shared_ptr<const Symbol> getSymbol(const Uuid& uuid) const noexcept;
77  std::shared_ptr<const Package> getPackage(const Uuid& uuid) const noexcept;
78  std::shared_ptr<const Component> getComponent(const Uuid& uuid) const
79  noexcept;
80  std::shared_ptr<const Device> getDevice(const Uuid& uuid) const noexcept;
81 
82  // Operator Overloadings
83  LibraryElementCache& operator=(const LibraryElementCache& rhs) = delete;
84 
85 private: // Methods
86  template <typename T>
87  std::shared_ptr<const T> getElement(
88  FilePath (workspace::WorkspaceLibraryDb::*getter)(const Uuid&) const,
89  QHash<Uuid, std::shared_ptr<const T>>& container, const Uuid& uuid) const
90  noexcept;
91 
92 private: // Data
93  QPointer<const workspace::WorkspaceLibraryDb> mDb;
94  mutable QHash<Uuid, std::shared_ptr<const ComponentCategory>> mCmpCat;
95  mutable QHash<Uuid, std::shared_ptr<const PackageCategory>> mPkgCat;
96  mutable QHash<Uuid, std::shared_ptr<const Symbol>> mSym;
97  mutable QHash<Uuid, std::shared_ptr<const Package>> mPkg;
98  mutable QHash<Uuid, std::shared_ptr<const Component>> mCmp;
99  mutable QHash<Uuid, std::shared_ptr<const Device>> mDev;
100 };
101 
102 /*******************************************************************************
103  * End of File
104  ******************************************************************************/
105 
106 } // namespace editor
107 } // namespace library
108 } // namespace librepcb
109 
110 #endif
Definition: airwiresbuilder.cpp:32
QHash< Uuid, std::shared_ptr< const Device > > mDev
Definition: libraryelementcache.h:99
QHash< Uuid, std::shared_ptr< const PackageCategory > > mPkgCat
Definition: libraryelementcache.h:95
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QHash< Uuid, std::shared_ptr< const Symbol > > mSym
Definition: libraryelementcache.h:96
QHash< Uuid, std::shared_ptr< const Component > > mCmp
Definition: libraryelementcache.h:98
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:52
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
QHash< Uuid, std::shared_ptr< const ComponentCategory > > mCmpCat
Definition: libraryelementcache.h:94
QHash< Uuid, std::shared_ptr< const Package > > mPkg
Definition: libraryelementcache.h:97
QPointer< const workspace::WorkspaceLibraryDb > mDb
Definition: libraryelementcache.h:93
Cache for fast access to library elements.
Definition: libraryelementcache.h:60