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 ******************************************************************************/
36namespace librepcb {
37
38class Component;
39class ComponentCategory;
40class Device;
41class Package;
42class PackageCategory;
43class Symbol;
44class WorkspaceLibraryDb;
45
46namespace editor {
47
48/*******************************************************************************
49 * Class LibraryElementCache
50 ******************************************************************************/
51
56 Q_DECLARE_TR_FUNCTIONS(LibraryElementCache)
57
58public:
59 // Constructors / Destructor
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
77 LibraryElementCache& operator=(const LibraryElementCache& rhs) = delete;
78
79private: // 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
85private: // 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
The ComponentCategory class.
Definition: componentcategory.h:44
The Component class represents a "generic" device in the library.
Definition: component.h:73
The Device class represents an instance of a component (a "real" component)
Definition: device.h:55
The PackageCategory class.
Definition: packagecategory.h:44
The Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
The Symbol class represents the part of a component which is added to schematics.
Definition: symbol.h:55
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:58
Cache for fast access to library elements.
Definition: libraryelementcache.h:55
QHash< Uuid, std::shared_ptr< const ComponentCategory > > mCmpCat
Definition: libraryelementcache.h:87
QPointer< const WorkspaceLibraryDb > mDb
Definition: libraryelementcache.h:86
std::shared_ptr< const Symbol > getSymbol(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:69
std::shared_ptr< const Device > getDevice(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:84
QHash< Uuid, std::shared_ptr< const Package > > mPkg
Definition: libraryelementcache.h:90
LibraryElementCache(const LibraryElementCache &other)=delete
QHash< Uuid, std::shared_ptr< const Device > > mDev
Definition: libraryelementcache.h:92
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
QHash< Uuid, std::shared_ptr< const Symbol > > mSym
Definition: libraryelementcache.h:89
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
QHash< Uuid, std::shared_ptr< const PackageCategory > > mPkgCat
Definition: libraryelementcache.h:88
std::shared_ptr< const PackageCategory > getPackageCategory(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:64
std::shared_ptr< const ComponentCategory > getComponentCategory(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:60
~LibraryElementCache() noexcept
Definition: libraryelementcache.cpp:52
Definition: occmodel.cpp:77