Horizon
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 
16 namespace horizon {
17 
22 class Pool : public IPool {
23 public:
28  Pool(const std::string &base_path, bool read_only = true);
29  const class Unit *get_unit(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
30  const class Entity *get_entity(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
31  const class Symbol *get_symbol(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
32  const class Padstack *get_padstack(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
33  const class Padstack *get_well_known_padstack(const std::string &name, UUID *pool_uuid_out = nullptr) override;
34  const class Package *get_package(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
35  const class Part *get_part(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
36  const class Frame *get_frame(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
37  const class Decal *get_decal(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
38  std::set<UUID> get_alternate_packages(const UUID &uu) override;
39  std::string get_model_filename(const UUID &pkg_uuid, const UUID &model_uuid) override;
40 
41  virtual std::string get_filename(ObjectType type, const UUID &uu, UUID *pool_uuid_out = nullptr);
42  std::string get_rel_filename(ObjectType type, const UUID &uu);
43  const std::string &get_base_path() const override;
44  bool check_filename(ObjectType type, const std::string &filename, std::string *error_msg = nullptr) const;
45 
46  SQLite::Database &get_db() override
47  {
48  return db;
49  }
50 
51  class PoolParametric *get_parametric() override
52  {
53  return nullptr;
54  }
55 
56  const PoolInfo &get_pool_info() const override
57  {
58  return pool_info;
59  }
60 
71  void clear() override;
72  std::string get_tmp_filename(ObjectType type, const UUID &uu) const;
73  static int get_required_schema_version();
74  virtual ~Pool();
75  static const UUID tmp_pool_uuid;
76 
77  std::map<std::string, UUID> get_actually_included_pools(bool include_self) override;
78 
79  UUID get_installation_uuid();
80 
81  struct ItemPoolInfo {
82  UUID pool;
83  UUID last;
84  };
85  ItemPoolInfo get_pool_uuids(ObjectType ty, const UUID &uu);
86 
87 protected:
88  const std::string base_path;
89  const PoolInfo pool_info;
90 
91  std::string get_flat_filename(ObjectType type, const UUID &uu) const;
92 
93  std::map<UUID, Unit> units;
94  std::map<UUID, Entity> entities;
95  std::map<UUID, Symbol> symbols;
96  std::map<UUID, Padstack> padstacks;
97  std::map<UUID, Package> packages;
98  std::map<UUID, Part> parts;
99  std::map<UUID, Frame> frames;
100  std::map<UUID, Decal> decals;
101  std::map<std::pair<ObjectType, UUID>, UUID> pool_uuid_cache;
102  void get_pool_uuid(ObjectType type, const UUID &uu, UUID *pool_uuid_out);
103 };
104 } // namespace horizon
Definition: decal.hpp:16
Definition: entity.hpp:13
Definition: frame.hpp:21
Definition: ipool.hpp:14
Definition: package.hpp:30
Definition: padstack.hpp:21
Definition: part.hpp:14
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:65
void clear() override
Clears all lazy-loaded objects.
Definition: pool.cpp:28
Pool(const std::string &base_path, bool read_only=true)
Constructs a Pool.
Definition: pool.cpp:17
Definition: sqlite.hpp:69
Definition: symbol.hpp:72
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
A Unit is the template for a Gate inside of an Entity.
Definition: unit.hpp:58
Definition: pool.hpp:81