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_EDITOR_LIBRARYELEMENTCACHE_H
21 #define LIBREPCB_EDITOR_LIBRARYELEMENTCACHE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
28 
29 #include <QtCore>
30 
31 #include <memory>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 class Component;
39 class ComponentCategory;
40 class Device;
41 class Package;
42 class PackageCategory;
43 class Symbol;
44 class WorkspaceLibraryDb;
45 
46 namespace editor {
47 
48 /*******************************************************************************
49  * Class LibraryElementCache
50  ******************************************************************************/
51 
55 class LibraryElementCache final {
56  Q_DECLARE_TR_FUNCTIONS(LibraryElementCache)
57 
58 public:
59  // Constructors / Destructor
60  LibraryElementCache() = delete;
61  LibraryElementCache(const LibraryElementCache& other) = delete;
62  explicit LibraryElementCache(const WorkspaceLibraryDb& db) noexcept;
63  ~LibraryElementCache() noexcept;
64 
65  // Getters
66  std::shared_ptr<const ComponentCategory> getComponentCategory(
67  const Uuid& uuid) const noexcept;
68  std::shared_ptr<const PackageCategory> getPackageCategory(
69  const Uuid& uuid) const noexcept;
70  std::shared_ptr<const Symbol> getSymbol(const Uuid& uuid) const noexcept;
71  std::shared_ptr<const Package> getPackage(const Uuid& uuid) const noexcept;
72  std::shared_ptr<const Component> getComponent(
73  const Uuid& uuid) const noexcept;
74  std::shared_ptr<const Device> getDevice(const Uuid& uuid) const noexcept;
75 
76  // Operator Overloadings
78 
79 private: // Methods
80  template <typename T>
81  std::shared_ptr<const T> getElement(
82  QHash<Uuid, std::shared_ptr<const T>>& container,
83  const Uuid& uuid) const noexcept;
84 
85 private: // Data
86  QPointer<const WorkspaceLibraryDb> mDb;
87  mutable QHash<Uuid, std::shared_ptr<const ComponentCategory>> mCmpCat;
88  mutable QHash<Uuid, std::shared_ptr<const PackageCategory>> mPkgCat;
89  mutable QHash<Uuid, std::shared_ptr<const Symbol>> mSym;
90  mutable QHash<Uuid, std::shared_ptr<const Package>> mPkg;
91  mutable QHash<Uuid, std::shared_ptr<const Component>> mCmp;
92  mutable QHash<Uuid, std::shared_ptr<const Device>> mDev;
93 };
94 
95 /*******************************************************************************
96  * End of File
97  ******************************************************************************/
98 
99 } // namespace editor
100 } // namespace librepcb
101 
102 #endif
std::shared_ptr< const Device > getDevice(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:84
std::shared_ptr< const Component > getComponent(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:79
QHash< Uuid, std::shared_ptr< const Component > > mCmp
Definition: libraryelementcache.h:91
Definition: occmodel.cpp:77
std::shared_ptr< const ComponentCategory > getComponentCategory(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:60
QHash< Uuid, std::shared_ptr< const ComponentCategory > > mCmpCat
Definition: libraryelementcache.h:87
std::shared_ptr< const PackageCategory > getPackageCategory(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:64
Cache for fast access to library elements.
Definition: libraryelementcache.h:55
std::shared_ptr< const Package > getPackage(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:74
std::shared_ptr< const T > getElement(QHash< Uuid, std::shared_ptr< const T >> &container, const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:94
LibraryElementCache & operator=(const LibraryElementCache &rhs)=delete
QHash< Uuid, std::shared_ptr< const Symbol > > mSym
Definition: libraryelementcache.h:89
QHash< Uuid, std::shared_ptr< const PackageCategory > > mPkgCat
Definition: libraryelementcache.h:88
std::shared_ptr< const Symbol > getSymbol(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:69
QPointer< const WorkspaceLibraryDb > mDb
Definition: libraryelementcache.h:86
QHash< Uuid, std::shared_ptr< const Package > > mPkg
Definition: libraryelementcache.h:90
QHash< Uuid, std::shared_ptr< const Device > > mDev
Definition: libraryelementcache.h:92
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:57
~LibraryElementCache() noexcept
Definition: libraryelementcache.cpp:52