Horizon
Loading...
Searching...
No Matches
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
9namespace horizon {
10using json = nlohmann::json;
11
16class Pin {
17public:
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 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;
40 static const std::map<Pin::Direction, std::string> direction_abbreviations;
45 unsigned int swap_group = 0;
50 public:
51 explicit AlternateName() = default;
52 explicit AlternateName(const std::string &name, Direction dir);
53 explicit AlternateName(const json &j);
54 std::string name;
55 Direction direction = Direction::INPUT;
56
57 json serialize() const;
58 };
59 std::map<UUID, AlternateName> names;
60
61 static UUID alternate_name_uuid_from_index(int idx);
62
63 json serialize() const;
64 UUID get_uuid() const;
65};
71class Unit {
72private:
73 Unit(const UUID &uu, const json &j);
74
75public:
76 static Unit new_from_file(const std::string &filename);
77 static unsigned int get_app_version();
78 Unit(const UUID &uu);
79 UUID uuid;
80 std::string name;
81 std::string manufacturer;
82 std::map<UUID, Pin> pins;
83 FileVersion version;
84
85 unsigned int get_required_version() const;
86
87 json serialize() const;
88 UUID get_uuid() const;
89};
90} // namespace horizon
Definition file_version.hpp:9
Definition lut.hpp:18
The Pin's alternate names.
Definition unit.hpp:49
A Pin represents a logical pin of a Unit.
Definition unit.hpp:16
unsigned int swap_group
Pins of the same swap_group can be pinswapped.
Definition unit.hpp:45
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:71
a class to store JSON values
Definition json.hpp:177
basic_json<> json
default JSON class
Definition json_fwd.hpp:62