Horizon
Loading...
Searching...
No Matches
pool.hpp
1#pragma once
2#include "common/common.hpp"
3#include "nlohmann/json_fwd.hpp"
4#include "util/uuid.hpp"
5#include "frame/frame.hpp"
6#include "package.hpp"
7#include "package/pad.hpp"
8#include "decal.hpp"
9#include <map>
10#include <set>
11#include "ipool.hpp"
12#include "pool_info.hpp"
13
14#include "util/sqlite.hpp"
15
16namespace horizon {
17
22class Pool : public IPool {
23public:
28 Pool(const std::string &base_path, bool read_only = true);
29 std::shared_ptr<const class Unit> get_unit(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
30 std::shared_ptr<const class Entity> get_entity(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
31 std::shared_ptr<const class Symbol> get_symbol(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
32 std::shared_ptr<const class Padstack> get_padstack(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
33 std::shared_ptr<const class Padstack> get_well_known_padstack(const std::string &name,
34 UUID *pool_uuid_out = nullptr) override;
35 std::shared_ptr<const class Package> get_package(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
36 std::shared_ptr<const class Part> get_part(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
37 std::shared_ptr<const class Frame> get_frame(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
38 std::shared_ptr<const class Decal> get_decal(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
39 std::set<UUID> get_alternate_packages(const UUID &uu) override;
40 std::string get_model_filename(const UUID &pkg_uuid, const UUID &model_uuid) override;
41
42 virtual std::string get_filename(ObjectType type, const UUID &uu, UUID *pool_uuid_out = nullptr);
43 std::string get_rel_filename(ObjectType type, const UUID &uu);
44 const std::string &get_base_path() const override;
45 bool check_filename(ObjectType type, const std::string &filename, std::string *error_msg = nullptr) const override;
46 void check_filename_throw(ObjectType type, const std::string &filename) const override;
47
48 SQLite::Database &get_db() override
49 {
50 return db;
51 }
52
53 class PoolParametric *get_parametric() override
54 {
55 return nullptr;
56 }
57
58 const PoolInfo &get_pool_info() const override
59 {
60 return pool_info;
61 }
62
73 void clear() override;
74 std::string get_tmp_filename(ObjectType type, const UUID &uu) const;
75 static int get_required_schema_version();
76 virtual ~Pool();
77 static const UUID tmp_pool_uuid;
78
79 std::map<std::string, UUID> get_actually_included_pools(bool include_self) override;
80
81 UUID get_installation_uuid();
82
83 struct ItemPoolInfo {
84 UUID pool;
85 UUID last;
86 };
87 ItemPoolInfo get_pool_uuids(ObjectType ty, const UUID &uu);
88
89protected:
90 const std::string base_path;
91 const PoolInfo pool_info;
92
93 std::string get_flat_filename(ObjectType type, const UUID &uu) const;
94
95 std::map<UUID, std::shared_ptr<Unit>> units;
96 std::map<UUID, std::shared_ptr<Entity>> entities;
97 std::map<UUID, std::shared_ptr<Symbol>> symbols;
98 std::map<UUID, std::shared_ptr<Padstack>> padstacks;
99 std::map<UUID, std::shared_ptr<Package>> packages;
100 std::map<UUID, std::shared_ptr<Part>> parts;
101 std::map<UUID, std::shared_ptr<Frame>> frames;
102 std::map<UUID, std::shared_ptr<Decal>> decals;
103 std::map<std::pair<ObjectType, UUID>, UUID> pool_uuid_cache;
104 void get_pool_uuid(ObjectType type, const UUID &uu, UUID *pool_uuid_out);
105};
106} // namespace horizon
Definition ipool.hpp:15
Definition pool_info.hpp:11
Definition pool_parametric.hpp:10
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition pool.hpp:22
SQLite::Database db
The database connection.
Definition pool.hpp:67
void clear() override
Clears all lazy-loaded objects.
Definition pool.cpp:28
Definition sqlite.hpp:72
This class encapsulates a UUID and allows it to be uses as a value type.
Definition uuid.hpp:16
Definition pool.hpp:83