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 <fstream>
10 #include <map>
11 #include <set>
12 #include <vector>
13 #include "ipool.hpp"
14 
15 #include "util/sqlite.hpp"
16 
17 namespace horizon {
18 
23 class Pool : public IPool {
24 public:
29  Pool(const std::string &base_path, bool read_only = true);
30  const class Unit *get_unit(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
31  const class Entity *get_entity(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
32  const class Symbol *get_symbol(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
33  const class Padstack *get_padstack(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
34  const class Padstack *get_well_known_padstack(const std::string &name, UUID *pool_uuid_out = nullptr) override;
35  const class Package *get_package(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
36  const class Part *get_part(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
37  const class Frame *get_frame(const UUID &uu, UUID *pool_uuid_out = nullptr) override;
38  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  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 
61  void clear() override;
62  std::string get_tmp_filename(ObjectType type, const UUID &uu) const;
63  static int get_required_schema_version();
64  virtual ~Pool();
65  static const UUID tmp_pool_uuid;
66 
67 protected:
68  std::string base_path;
69  std::string get_flat_filename(ObjectType type, const UUID &uu) const;
70 
71  std::map<UUID, Unit> units;
72  std::map<UUID, Entity> entities;
73  std::map<UUID, Symbol> symbols;
74  std::map<UUID, Padstack> padstacks;
75  std::map<UUID, Package> packages;
76  std::map<UUID, Part> parts;
77  std::map<UUID, Frame> frames;
78  std::map<UUID, Decal> decals;
79  std::map<std::pair<ObjectType, UUID>, UUID> pool_uuid_cache;
80  void get_pool_uuid(ObjectType type, const UUID &uu, UUID *pool_uuid_out);
81 };
82 } // namespace horizon
horizon::Pool::db
SQLite::Database db
The database connection.
Definition: pool.hpp:55
horizon::SQLite::Database
Definition: sqlite.hpp:63
horizon::Decal
Definition: decal.hpp:16
horizon::Pool::clear
void clear() override
Clears all lazy-loaded objects.
Definition: pool.cpp:27
horizon::Entity
Definition: entity.hpp:14
horizon::Symbol
Definition: symbol.hpp:71
horizon::Padstack
Definition: padstack.hpp:21
horizon::IPool
Definition: ipool.hpp:12
horizon::Frame
Definition: frame.hpp:21
horizon::Package
Definition: package.hpp:29
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::Unit
A Unit is the template for a Gate inside of an Entity.
Definition: unit.hpp:60
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:23
horizon::Pool::Pool
Pool(const std::string &base_path, bool read_only=true)
Constructs a Pool.
Definition: pool.cpp:16
horizon::Part
Definition: part.hpp:14