LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_LIBRARYELEMENTCACHE_H
21 #define LIBREPCB_LIBRARY_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 /*******************************************************************************
52  * Class LibraryElementCache
53  ******************************************************************************/
54 
58 class LibraryElementCache final {
59  Q_DECLARE_TR_FUNCTIONS(LibraryElementCache)
60 
61 public:
62  // Constructors / Destructor
63  LibraryElementCache() = delete;
64  LibraryElementCache(const LibraryElementCache& other) = delete;
65  explicit LibraryElementCache(
66  const workspace::WorkspaceLibraryDb& db) noexcept;
67  ~LibraryElementCache() noexcept;
68 
69  // Getters
70  std::shared_ptr<const ComponentCategory> getComponentCategory(
71  const Uuid& uuid) const noexcept;
72  std::shared_ptr<const PackageCategory> getPackageCategory(
73  const Uuid& uuid) const noexcept;
74  std::shared_ptr<const Symbol> getSymbol(const Uuid& uuid) const noexcept;
75  std::shared_ptr<const Package> getPackage(const Uuid& uuid) const noexcept;
76  std::shared_ptr<const Component> getComponent(const Uuid& uuid) const
77  noexcept;
78  std::shared_ptr<const Device> getDevice(const Uuid& uuid) const noexcept;
79 
80  // Operator Overloadings
82 
83 private: // Methods
84  template <typename T>
85  std::shared_ptr<const T> getElement(
86  FilePath (workspace::WorkspaceLibraryDb::*getter)(const Uuid&) const,
87  QHash<Uuid, std::shared_ptr<const T>>& container, const Uuid& uuid) const
88  noexcept;
89 
90 private: // Data
91  QPointer<const workspace::WorkspaceLibraryDb> mDb;
92  mutable QHash<Uuid, std::shared_ptr<const ComponentCategory>> mCmpCat;
93  mutable QHash<Uuid, std::shared_ptr<const PackageCategory>> mPkgCat;
94  mutable QHash<Uuid, std::shared_ptr<const Symbol>> mSym;
95  mutable QHash<Uuid, std::shared_ptr<const Package>> mPkg;
96  mutable QHash<Uuid, std::shared_ptr<const Component>> mCmp;
97  mutable QHash<Uuid, std::shared_ptr<const Device>> mDev;
98 };
99 
100 /*******************************************************************************
101  * End of File
102  ******************************************************************************/
103 
104 } // namespace library
105 } // namespace librepcb
106 
107 #endif // LIBREPCB_LIBRARY_LIBRARYELEMENTCACHE_H
QHash< Uuid, std::shared_ptr< const Device > > mDev
Definition: libraryelementcache.h:97
The ComponentCategory class.
Definition: componentcategory.h:43
std::shared_ptr< const PackageCategory > getPackageCategory(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:60
std::shared_ptr< const Component > getComponent(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:78
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:56
The Device class represents an instance of a component (a "real" component)
Definition: device.h:54
QHash< Uuid, std::shared_ptr< const Symbol > > mSym
Definition: libraryelementcache.h:94
QHash< Uuid, std::shared_ptr< const Package > > mPkg
Definition: libraryelementcache.h:95
QHash< Uuid, std::shared_ptr< const ComponentCategory > > mCmpCat
Definition: libraryelementcache.h:92
QHash< Uuid, std::shared_ptr< const PackageCategory > > mPkgCat
Definition: libraryelementcache.h:93
Cache for fast access to library elements.
Definition: libraryelementcache.h:58
The Symbol class represents the part of a component which is added to schematics. ...
Definition: symbol.h:57
std::shared_ptr< const Device > getDevice(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:84
LibraryElementCache & operator=(const LibraryElementCache &rhs)=delete
QPointer< const workspace::WorkspaceLibraryDb > mDb
Definition: libraryelementcache.h:91
std::shared_ptr< const ComponentCategory > getComponentCategory(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:55
~LibraryElementCache() noexcept
Definition: libraryelementcache.cpp:47
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
QHash< Uuid, std::shared_ptr< const Component > > mCmp
Definition: libraryelementcache.h:96
std::shared_ptr< const Symbol > getSymbol(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:66
std::shared_ptr< const T > getElement(FilePath(workspace::WorkspaceLibraryDb::*getter)(const Uuid &) const, QHash< Uuid, std::shared_ptr< const T >> &container, const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:95
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
The PackageCategory class.
Definition: packagecategory.h:43
The Component class represents a "generic" device in the library.
Definition: component.h:73
std::shared_ptr< const Package > getPackage(const Uuid &uuid) const noexcept
Definition: libraryelementcache.cpp:72