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 <map>
6#include <set>
7#include "ipool.hpp"
8#include "pool_info.hpp"
9
10#include "util/sqlite.hpp"
11
12namespace horizon {
13
18class Pool : public IPool {
19public:
24 Pool(const std::string &base_path, bool read_only = true);
25 std::shared_ptr<const class Unit> get_unit(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
26 std::shared_ptr<const class Entity> get_entity(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
27 std::shared_ptr<const class Symbol> get_symbol(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
28 std::shared_ptr<const class Padstack> get_padstack(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
29 std::shared_ptr<const class Padstack> get_well_known_padstack(const std::string &name,
30 UUID *pool_uuid_out = nullptr) override;
31 std::shared_ptr<const class Package> get_package(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
32 std::shared_ptr<const class Part> get_part(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
33 std::shared_ptr<const class Frame> get_frame(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
34 std::shared_ptr<const class Decal> get_decal(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
35 std::set<UUID> get_alternate_packages(const UUID &uu) override;
36 std::string get_model_filename(const UUID &pkg_uuid, const UUID &model_uuid) override;
37
38 virtual std::string get_filename(ObjectType type, const UUID &uu, UUID *pool_uuid_out = nullptr);
39 std::string get_rel_filename(ObjectType type, const UUID &uu);
40 const std::string &get_base_path() const override;
41 bool check_filename(ObjectType type, const std::string &filename, std::string *error_msg = nullptr) const override;
42 void check_filename_throw(ObjectType type, const std::string &filename) const override;
43
44 SQLite::Database &get_db() override
45 {
46 return db;
47 }
48
49 class PoolParametric *get_parametric() override
50 {
51 return nullptr;
52 }
53
54 const PoolInfo &get_pool_info() const override
55 {
56 return pool_info;
57 }
58
69 void clear() override;
70 std::string get_tmp_filename(ObjectType type, const UUID &uu) const;
71 static int get_required_schema_version();
72 virtual ~Pool();
73 static const UUID tmp_pool_uuid;
74
75 std::map<std::string, UUID> get_actually_included_pools(bool include_self) override;
76
77 UUID get_installation_uuid();
78
79 struct ItemPoolInfo {
80 UUID pool;
81 UUID last;
82 };
83 ItemPoolInfo get_pool_uuids(ObjectType ty, const UUID &uu);
84
85protected:
86 const std::string base_path;
87 const PoolInfo pool_info;
88
89 std::string get_flat_filename(ObjectType type, const UUID &uu) const;
90
91 std::map<UUID, std::shared_ptr<Unit>> units;
92 std::map<UUID, std::shared_ptr<Entity>> entities;
93 std::map<UUID, std::shared_ptr<Symbol>> symbols;
94 std::map<UUID, std::shared_ptr<Padstack>> padstacks;
95 std::map<UUID, std::shared_ptr<Package>> packages;
96 std::map<UUID, std::shared_ptr<Part>> parts;
97 std::map<UUID, std::shared_ptr<Frame>> frames;
98 std::map<UUID, std::shared_ptr<Decal>> decals;
99 std::map<std::pair<ObjectType, UUID>, UUID> pool_uuid_cache;
100 void get_pool_uuid(ObjectType type, const UUID &uu, UUID *pool_uuid_out);
101};
102} // namespace horizon
Definition ipool.hpp:15
Definition pool_info.hpp:11
Definition pool_parametric.hpp:10
SQLite::Database db
The database connection.
Definition pool.hpp:63
void clear() override
Clears all lazy-loaded objects.
Definition pool.cpp:30
Pool(const std::string &base_path, bool read_only=true)
Constructs a Pool.
Definition pool.cpp:19
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:79