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 "common/lut.hpp"
6 #include <fstream>
7 #include <map>
8 #include <set>
9 #include <vector>
10 #include <yaml-cpp/yaml.h>
11 
12 namespace horizon {
13 using json = nlohmann::json;
14 
19 class Pin : public UUIDProvider {
20 public:
21  enum class Direction {
22  INPUT,
23  OUTPUT,
24  BIDIRECTIONAL,
25  OPEN_COLLECTOR,
26  POWER_INPUT,
27  POWER_OUTPUT,
28  PASSIVE,
29  NOT_CONNECTED
30  };
31 
32  Pin(const UUID &uu, const json &j);
33  Pin(const UUID &uu, const YAML::Node &n);
34  Pin(const UUID &uu);
35 
36  const UUID uuid;
40  std::string primary_name;
41  Direction direction = Direction::INPUT;
42  static const LutEnumStr<Pin::Direction> direction_lut;
43  static const std::vector<std::pair<Pin::Direction, std::string>> direction_names;
48  unsigned int swap_group = 0;
52  std::vector<std::string> names;
53 
54  json serialize() const;
55  void serialize_yaml(YAML::Emitter &em) const;
56  UUID get_uuid() const;
57 };
63 class Unit : public UUIDProvider {
64 private:
65  Unit(const UUID &uu, const json &j);
66 
67 public:
68  static Unit new_from_file(const std::string &filename);
69  Unit(const UUID &uu);
70  Unit(const UUID &uu, const YAML::Node &n);
71  UUID uuid;
72  std::string name;
73  std::string manufacturer;
74  std::map<UUID, Pin> pins;
75  json serialize() const;
76  void serialize_yaml(YAML::Emitter &em) const;
77  UUID get_uuid() const;
78 };
79 } // namespace horizon
horizon::Pin::names
std::vector< std::string > names
The Pin's alternate names.
Definition: unit.hpp:52
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::Pin::primary_name
std::string primary_name
The Pin's primary name.
Definition: unit.hpp:40
horizon::Pin
A Pin represents a logical pin of a Unit.
Definition: unit.hpp:19
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:161
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::Pin::swap_group
unsigned int swap_group
Pins of the same swap_group can be pinswapped.
Definition: unit.hpp:48
horizon::UUIDProvider
Interface for objects that have a UUID.
Definition: uuid_provider.hpp:9
horizon::LutEnumStr< Pin::Direction >