LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 Organization;
42class Package;
43class PackageCategory;
44class Symbol;
45class WorkspaceLibraryDb;
46
47namespace editor {
48
49/*******************************************************************************
50 * Class LibraryElementCache
51 ******************************************************************************/
52
56class LibraryElementCache final : public QObject {
57 Q_OBJECT
58
59public:
60 // Constructors / Destructor
63 explicit LibraryElementCache(const WorkspaceLibraryDb& db,
64 QObject* parent = nullptr) noexcept;
65 ~LibraryElementCache() noexcept;
66
67 // General Methods
68 void reset() noexcept;
70 const Uuid& uuid, bool throwIfNotFound) const;
71 std::shared_ptr<const PackageCategory> getPackageCategory(
72 const Uuid& uuid, bool throwIfNotFound) const;
73 std::shared_ptr<const Symbol> getSymbol(const Uuid& uuid,
74 bool throwIfNotFound) const;
75 std::shared_ptr<const Package> getPackage(const Uuid& uuid,
76 bool throwIfNotFound) const;
77 std::shared_ptr<const Component> getComponent(const Uuid& uuid,
78 bool throwIfNotFound) const;
79 std::shared_ptr<const Device> getDevice(const Uuid& uuid,
80 bool throwIfNotFound) const;
81 std::shared_ptr<const Organization> getOrganization(
82 const Uuid& uuid, bool throwIfNotFound) const;
83
84 // Operator Overloadings
85 LibraryElementCache& operator=(const LibraryElementCache& rhs) = delete;
86
87signals:
90
91private: // Methods
92 template <typename T>
93 std::shared_ptr<const T> getElement(
94 QHash<Uuid, std::shared_ptr<const T>>& container, const Uuid& uuid,
95 bool throwIfNotFound) const;
96
97private: // Data
98 QPointer<const WorkspaceLibraryDb> mDb;
99 mutable QHash<Uuid, std::shared_ptr<const ComponentCategory>> mCmpCat;
100 mutable QHash<Uuid, std::shared_ptr<const PackageCategory>> mPkgCat;
101 mutable QHash<Uuid, std::shared_ptr<const Symbol>> mSym;
102 mutable QHash<Uuid, std::shared_ptr<const Package>> mPkg;
103 mutable QHash<Uuid, std::shared_ptr<const Component>> mCmp;
104 mutable QHash<Uuid, std::shared_ptr<const Device>> mDev;
105 mutable QHash<Uuid, std::shared_ptr<const Organization>> mOrg;
106};
107
108/*******************************************************************************
109 * End of File
110 ******************************************************************************/
111
112} // namespace editor
113} // namespace librepcb
114
115#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 Organization class represents a PCB manufacturer, assembly house etc.
Definition organization.h:47
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:56
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
The WorkspaceLibraryDb class.
Definition workspacelibrarydb.h:59
Cache for fast access to library elements.
Definition libraryelementcache.h:56
std::shared_ptr< const PackageCategory > getPackageCategory(const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:98
QHash< Uuid, std::shared_ptr< const ComponentCategory > > mCmpCat
Definition libraryelementcache.h:99
QPointer< const WorkspaceLibraryDb > mDb
Definition libraryelementcache.h:98
std::shared_ptr< const T > getElement(QHash< Uuid, std::shared_ptr< const T > > &container, const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:133
std::shared_ptr< const Symbol > getSymbol(const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:103
void reset() noexcept
Definition libraryelementcache.cpp:80
std::shared_ptr< const Component > getComponent(const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:113
QHash< Uuid, std::shared_ptr< const Package > > mPkg
Definition libraryelementcache.h:102
LibraryElementCache(const LibraryElementCache &other)=delete
std::shared_ptr< const Device > getDevice(const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:118
QHash< Uuid, std::shared_ptr< const Device > > mDev
Definition libraryelementcache.h:104
QHash< Uuid, std::shared_ptr< const Symbol > > mSym
Definition libraryelementcache.h:101
std::shared_ptr< const ComponentCategory > getComponentCategory(const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:93
QHash< Uuid, std::shared_ptr< const Component > > mCmp
Definition libraryelementcache.h:103
QHash< Uuid, std::shared_ptr< const PackageCategory > > mPkgCat
Definition libraryelementcache.h:100
std::shared_ptr< const Package > getPackage(const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:108
QHash< Uuid, std::shared_ptr< const Organization > > mOrg
Definition libraryelementcache.h:105
std::shared_ptr< const Organization > getOrganization(const Uuid &uuid, bool throwIfNotFound) const
Definition libraryelementcache.cpp:123
Definition occmodel.cpp:77
Definition uuid.h:186