Horizon
unit.hpp
1 #pragma once
2 #include "nlohmann/json_fwd.hpp"
3 #include "util/uuid.hpp"
4 #include "util/uuid_provider.hpp"
5 #include <fstream>
6 #include <map>
7 #include <set>
8 #include <vector>
9 #include <yaml-cpp/yaml.h>
10 
11 namespace horizon {
12 using json = nlohmann::json;
13 
18 class Pin : public UUIDProvider {
19 public:
20  enum class Direction { INPUT, OUTPUT, BIDIRECTIONAL, OPEN_COLLECTOR, POWER_INPUT, POWER_OUTPUT, PASSIVE };
21 
22  Pin(const UUID &uu, const json &j);
23  Pin(const UUID &uu, const YAML::Node &n);
24  Pin(const UUID &uu);
25 
26  const UUID uuid;
30  std::string primary_name;
31  Direction direction = Direction::INPUT;
36  unsigned int swap_group = 0;
40  std::vector<std::string> names;
41 
42  json serialize() const;
43  void serialize_yaml(YAML::Emitter &em) const;
44  UUID get_uuid() const;
45 };
51 class Unit : public UUIDProvider {
52 private:
53  Unit(const UUID &uu, const json &j);
54 
55 public:
56  static Unit new_from_file(const std::string &filename);
57  Unit(const UUID &uu);
58  Unit(const UUID &uu, const YAML::Node &n);
59  UUID uuid;
60  std::string name;
61  std::string manufacturer;
62  std::map<UUID, Pin> pins;
63  json serialize() const;
64  void serialize_yaml(YAML::Emitter &em) const;
65  UUID get_uuid() const;
66 };
67 } // namespace horizon
a class to store JSON values
Definition: json.hpp:161
Interface for objects that have a UUID.
Definition: uuid_provider.hpp:9
std::vector< std::string > names
The Pin&#39;s alternate names.
Definition: unit.hpp:40
A Unit is the template for a Gate inside of an Entity.
Definition: unit.hpp:51
unsigned int swap_group
Pins of the same swap_group can be pinswapped.
Definition: unit.hpp:36
A Pin represents a logical pin of a Unit.
Definition: unit.hpp:18
std::string primary_name
The Pin&#39;s primary name.
Definition: unit.hpp:30
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: block.cpp:7
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61