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 { INPUT, OUTPUT, BIDIRECTIONAL, OPEN_COLLECTOR, POWER_INPUT, POWER_OUTPUT, PASSIVE };
22 
23  Pin(const UUID &uu, const json &j);
24  Pin(const UUID &uu, const YAML::Node &n);
25  Pin(const UUID &uu);
26 
27  const UUID uuid;
31  std::string primary_name;
32  Direction direction = Direction::INPUT;
33  static const LutEnumStr<Pin::Direction> direction_lut;
38  unsigned int swap_group = 0;
42  std::vector<std::string> names;
43 
44  json serialize() const;
45  void serialize_yaml(YAML::Emitter &em) const;
46  UUID get_uuid() const;
47 };
53 class Unit : public UUIDProvider {
54 private:
55  Unit(const UUID &uu, const json &j);
56 
57 public:
58  static Unit new_from_file(const std::string &filename);
59  Unit(const UUID &uu);
60  Unit(const UUID &uu, const YAML::Node &n);
61  UUID uuid;
62  std::string name;
63  std::string manufacturer;
64  std::map<UUID, Pin> pins;
65  json serialize() const;
66  void serialize_yaml(YAML::Emitter &em) const;
67  UUID get_uuid() const;
68 };
69 } // 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:42
A Unit is the template for a Gate inside of an Entity.
Definition: unit.hpp:53
unsigned int swap_group
Pins of the same swap_group can be pinswapped.
Definition: unit.hpp:38
A Pin represents a logical pin of a Unit.
Definition: unit.hpp:19
std::string primary_name
The Pin&#39;s primary name.
Definition: unit.hpp:31
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: block.cpp:9
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61