Horizon
component.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "nlohmann/json_fwd.hpp"
4 #include "net.hpp"
5 #include "util/uuid.hpp"
6 #include "util/uuid_path.hpp"
7 #include "util/uuid_ptr.hpp"
8 #include "util/uuid_vec.hpp"
9 #include <map>
10 #include <set>
11 
12 namespace horizon {
13 using json = nlohmann::json;
14 
15 class Connection {
16 public:
17  Connection(const json &j, class Block *block);
18  Connection(Net *n) : net(n)
19  {
20  }
21  uuid_ptr<Net> net;
22 
23  json serialize() const;
24 };
25 
39 class Component {
40 public:
41  Component(const UUID &uu, const json &j, class IPool &pool, class Block *block = nullptr);
42  Component(const UUID &uu);
43 
44  UUID get_uuid() const;
45 
46  UUID uuid;
47  const class Entity *entity = nullptr;
48  const class Part *part = nullptr;
49  std::string refdes;
50  std::string value;
51  UUID group;
52  UUID tag;
53  bool nopopulate = false;
54 
55  UUIDVec href;
56 
57  enum class NopopulateFromInstance { SET, CLEAR, UNSET };
58  NopopulateFromInstance nopopulate_from_instance = NopopulateFromInstance::UNSET;
59 
60  bool get_nopopulate() const;
61 
62  const std::string &get_prefix() const;
63 
68  std::map<UUIDPath<2>, Connection> connections;
69 
73  class AltPinInfo {
74  public:
75  AltPinInfo() = default;
76  AltPinInfo(const json &j, const Pin &pin);
77  std::set<UUID> pin_names;
78  bool use_primary_name = false;
79  bool use_custom_name = false;
80 
81  std::string custom_name;
82  Pin::Direction custom_direction = Pin::Direction::BIDIRECTIONAL;
83 
84  void update_for_index(int index, const Pin &pin);
85 
86  json serialize() const;
87  };
88  std::map<UUIDPath<2>, AltPinInfo> alt_pins;
89 
90  static Pin::Direction get_effective_direction(const Component::AltPinInfo &alt, const Pin &pin);
91  Pin::Direction get_effective_direction(const UUIDPath<2> &path) const;
92 
93  std::string replace_text(const std::string &t, bool *replaced = nullptr) const;
94 
95  json serialize() const;
96  virtual ~Component()
97  {
98  }
99 
100 private:
101  // void update_refs();
102 };
103 } // namespace horizon
A block is one level of hierarchy in the netlist.
Definition: block.hpp:29
used to select alternate pin names
Definition: component.hpp:73
A Component is an instanced Entity in a Block.
Definition: component.hpp:39
std::map< UUIDPath< 2 >, Connection > connections
which Nins are connected to which Net the UUIDPath consists of Gate and Pin UUID
Definition: component.hpp:68
Definition: component.hpp:15
Definition: entity.hpp:13
Definition: ipool.hpp:14
Definition: net.hpp:11
Definition: part.hpp:14
A Pin represents a logical pin of a Unit.
Definition: unit.hpp:16
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: uuid_ptr.hpp:8
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62