Horizon
unit.hpp
1 #pragma once
2 #include "nlohmann/json_fwd.hpp"
3 #include "util/uuid.hpp"
4 #include "common/lut.hpp"
5 #include <map>
6 #include <vector>
7 #include "util/file_version.hpp"
8 
9 namespace horizon {
10 using json = nlohmann::json;
11 
16 class Pin {
17 public:
18  enum class Direction {
19  INPUT,
20  OUTPUT,
21  BIDIRECTIONAL,
22  OPEN_COLLECTOR,
23  POWER_INPUT,
24  POWER_OUTPUT,
25  PASSIVE,
26  NOT_CONNECTED
27  };
28 
29  Pin(const UUID &uu, const json &j);
30  Pin(const UUID &uu);
31 
32  const UUID uuid;
36  std::string primary_name;
37  Direction direction = Direction::INPUT;
38  static const LutEnumStr<Pin::Direction> direction_lut;
39  static const std::vector<std::pair<Pin::Direction, std::string>> direction_names;
44  unsigned int swap_group = 0;
48  std::vector<std::string> names;
49 
50  json serialize() const;
51  UUID get_uuid() const;
52 };
58 class Unit {
59 private:
60  Unit(const UUID &uu, const json &j);
61 
62 public:
63  static Unit new_from_file(const std::string &filename);
64  static unsigned int get_app_version();
65  Unit(const UUID &uu);
66  UUID uuid;
67  std::string name;
68  std::string manufacturer;
69  std::map<UUID, Pin> pins;
70  FileVersion version;
71 
72  json serialize() const;
73  UUID get_uuid() const;
74 };
75 } // namespace horizon
Definition: file_version.hpp:9
A Pin represents a logical pin of a Unit.
Definition: unit.hpp:16
std::vector< std::string > names
The Pin's alternate names.
Definition: unit.hpp:48
unsigned int swap_group
Pins of the same swap_group can be pinswapped.
Definition: unit.hpp:44
std::string primary_name
The Pin's primary name.
Definition: unit.hpp:36
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
A Unit is the template for a Gate inside of an Entity.
Definition: unit.hpp:58
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62