Horizon
blocks.hpp
1 #pragma once
2 #include "nlohmann/json_fwd.hpp"
3 #include "block/block.hpp"
4 #include "iblock_provider.hpp"
5 #include "util/file_version.hpp"
6 
7 namespace horizon {
8 using json = nlohmann::json;
9 
10 
11 class BlocksBase {
12 public:
13  class BlockItemInfo {
14  public:
15  BlockItemInfo(const UUID &uu, const json &j);
16  UUID uuid;
17  std::string block_filename;
18  std::string symbol_filename;
19  std::string schematic_filename;
20 
21  json serialize() const;
22 
23  protected:
24  BlockItemInfo(const UUID &uu, const std::string &b, const std::string &y, const std::string &c);
25  };
26 
27  class BlockItem : public BlockItemInfo {
28  public:
29  BlockItem(const BlockItemInfo &inf, const std::string &base_path, IPool &pool, class IBlockProvider &blocks);
30 
31  // so we can use load_and_log
32  BlockItem(const UUID &uu, const BlockItemInfo &inf, const std::string &base_path, IPool &pool,
33  class IBlockProvider &blocks);
34 
35  void update_refs(IBlockProvider &blocks);
36 
37  Block block;
38 
39  protected:
40  BlockItem(const UUID &uu, const std::string &b, const std::string &y, const std::string &c);
41  BlockItem(const BlockItemInfo &inf, const json &j, IPool &pool, class IBlockProvider &blocks);
42  };
43 
44  static std::map<std::string, std::string> peek_project_meta(const std::string &filename);
45  static std::vector<std::string> peek_filenames(const std::string &filename);
46 
47  std::string base_path;
48  UUID top_block;
49 
50  FileVersion version;
51  static unsigned int get_app_version();
52 
53 protected:
54  BlocksBase();
55  BlocksBase(const BlocksBase &other);
56  BlocksBase(const json &j, const std::string &base_path);
57 
58  std::vector<BlockItemInfo> blocks_sorted_from_json(const json &j) const;
59  json serialize_base() const;
60 };
61 
62 class Blocks : public BlocksBase, public IBlockProvider {
63 public:
64  Blocks(const json &j, const std::string &base_path, IPool &pool);
65  static Blocks new_from_file(const std::string &filename, IPool &pool);
66  Blocks(const Blocks &other);
67 
68  std::map<UUID, BlockItem> blocks;
69 
70  BlockItem &get_top_block_item();
71  const BlockItem &get_top_block_item() const;
72 
73  Block &get_block(const UUID &uu) override;
74  std::map<UUID, Block *> get_blocks() override;
75  Block &get_top_block() override;
76  json serialize() const;
77 };
78 
79 } // namespace horizon
A block is one level of hierarchy in the netlist.
Definition: block.hpp:29
Definition: blocks.hpp:13
Definition: blocks.hpp:27
Definition: blocks.hpp:11
Definition: blocks.hpp:62
Definition: file_version.hpp:9
Definition: iblock_provider.hpp:5
Definition: ipool.hpp:14
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62