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 <fstream>
9 #include <map>
10 #include <set>
11 #include <vector>
12 
13 #include "util/sqlite.hpp"
14 
15 namespace horizon {
16 
21 class Pool {
22 public:
27  Pool(const std::string &base_path, bool read_only = true);
28  const class Unit *get_unit(const UUID &uu, UUID *pool_uuid_out = nullptr);
29  const class Entity *get_entity(const UUID &uu, UUID *pool_uuid_out = nullptr);
30  const class Symbol *get_symbol(const UUID &uu, UUID *pool_uuid_out = nullptr);
31  const class Padstack *get_padstack(const UUID &uu, UUID *pool_uuid_out = nullptr);
32  const class Padstack *get_well_known_padstack(const std::string &name, UUID *pool_uuid_out = nullptr);
33  const class Package *get_package(const UUID &uu, UUID *pool_uuid_out = nullptr);
34  const class Part *get_part(const UUID &uu, UUID *pool_uuid_out = nullptr);
35  const class Frame *get_frame(const UUID &uu, UUID *pool_uuid_out = nullptr);
36  std::set<UUID> get_alternate_packages(const UUID &uu);
37  virtual std::string get_model_filename(const UUID &pkg_uuid, const UUID &model_uuid);
38 
39  virtual std::string get_filename(ObjectType type, const UUID &uu, UUID *pool_uuid_out = nullptr);
40  const std::string &get_base_path() const;
51  void clear();
52  std::string get_tmp_filename(ObjectType type, const UUID &uu) const;
53  static int get_required_schema_version();
54  virtual ~Pool();
55 
56 protected:
57  std::string base_path;
58  std::string get_flat_filename(ObjectType type, const UUID &uu) const;
59 
60  std::map<UUID, Unit> units;
61  std::map<UUID, Entity> entities;
62  std::map<UUID, Symbol> symbols;
63  std::map<UUID, Padstack> padstacks;
64  std::map<UUID, Package> packages;
65  std::map<UUID, Part> parts;
66  std::map<UUID, Frame> frames;
67  std::map<std::pair<ObjectType, UUID>, UUID> pool_uuid_cache;
68  void get_pool_uuid(ObjectType type, const UUID &uu, UUID *pool_uuid_out);
69 };
70 } // namespace horizon
horizon::Pool::db
SQLite::Database db
The database connection.
Definition: pool.hpp:45
horizon::Entity
Definition: entity.hpp:13
horizon::Symbol
Definition: symbol.hpp:74
horizon::Padstack
Definition: padstack.hpp:21
horizon::Frame
Definition: frame.hpp:21
horizon::Pool::clear
void clear()
Clears all lazy-loaded objects.
Definition: pool.cpp:25
horizon::Package
Definition: package.hpp:28
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:63
horizon::Pool
Stores objects (Unit, Entity, Symbol, Part, etc.) from the pool.
Definition: pool.hpp:21
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:13
SQLite::Database
Definition: sqlite.hpp:63