OdbDesignLib
OdbDesign ODB++ Parsing Library
NetlistFile.h
1 #pragma once
2 
3 #include <map>
4 #include <vector>
5 #include <string>
6 #include <memory>
7 #include <filesystem>
8 #include "../../odbdesign_export.h"
9 #include "../../IProtoBuffable.h"
10 #include "../../ProtoBuf/netlistfile.pb.h"
11 #include "../ISaveable.h"
12 #include "../IStreamSaveable.h"
13 #include "EnumMap.h"
14 
15 
16 namespace Odb::Lib::FileModel::Design
17 {
18  class ODBDESIGN_EXPORT NetlistFile : public IProtoBuffable<Odb::Lib::Protobuf::NetlistFile>, public ISaveable, public IStreamSaveable
19  {
20  public:
21  struct ODBDESIGN_EXPORT NetRecord : public IProtoBuffable<Odb::Lib::Protobuf::NetlistFile::NetRecord>
22  {
23  unsigned int serialNumber;
24  std::string netName;
25 
26  // Inherited via IProtoBuffable
27  std::unique_ptr<Odb::Lib::Protobuf::NetlistFile::NetRecord> to_protobuf() const override;
28  void from_protobuf(const Odb::Lib::Protobuf::NetlistFile::NetRecord& message) override;
29 
30  typedef std::vector<std::shared_ptr<NetRecord>> Vector;
31  typedef std::map<std::string, std::shared_ptr<NetRecord>> StringMap;
32 
33  inline constexpr static const char* FIELD_TOKEN = "$";
34  };
35 
36  struct ODBDESIGN_EXPORT NetPointRecord : public IProtoBuffable<Odb::Lib::Protobuf::NetlistFile::NetPointRecord>, public IStreamSaveable
37  {
38  enum AccessSide
39  {
40  Top,
41  Down,
42  Both,
43  Inner
44  };
45 
46  unsigned int netNumber;
47  double radius;
48  double x;
49  double y;
50  AccessSide side;
51  double width;
52  double height;
53  char epoint;
54  char exp;
55  bool commentPoint;
56  double staggeredX;
57  double staggeredY;
58  double staggeredRadius;
59  double viaPoint;
60  double fiducialPoint;
61  double testPoint;
62  // ...
63  char testExecutionSide;
64 
65  // Inherited via IProtoBuffable
66  std::unique_ptr<Odb::Lib::Protobuf::NetlistFile::NetPointRecord> to_protobuf() const override;
67  void from_protobuf(const Odb::Lib::Protobuf::NetlistFile::NetPointRecord& message) override;
68 
69  typedef std::vector<std::shared_ptr<NetPointRecord>> Vector;
70 
71  inline static const Utils::EnumMap<AccessSide> accessSideMap{
72  {
73  "Top",
74  "Down",
75  "Both",
76  "Inner"
77  }
78  };
79 
80  // Inherited via IStreamSaveable
81  bool Save(std::ostream& os) override;
82 
83  }; // NetPointRecord
84 
85  enum class Staggered
86  {
87  Yes,
88  No,
89  Unknown
90  };
91 
92  inline static const Utils::EnumMap<Staggered> staggeredMap{
93  {
94  "Y",
95  "N",
96  "Unknown"
97  }
98  };
99 
100  NetlistFile(std::filesystem::path path);
101  ~NetlistFile();
102 
103  std::filesystem::path GetPath() const;
104  std::string GetName() const;
105  std::string GetUnits() const;
106 
107  bool GetOptimized() const;
108  Staggered GetStaggered() const;
109 
110  const NetRecord::Vector& GetNetRecords() const;
111  const NetRecord::StringMap& GetNetRecordsByName() const;
112  const NetPointRecord::Vector& GetNetPointRecords() const;
113 
114  bool Parse();
115  // Inherited via ISaveable
116  bool Save(const std::filesystem::path& directory) override;
117 
118  // Inherited via IProtoBuffable
119  std::unique_ptr<Odb::Lib::Protobuf::NetlistFile> to_protobuf() const override;
120  void from_protobuf(const Odb::Lib::Protobuf::NetlistFile& message) override;
121 
122  typedef std::vector<std::shared_ptr<NetlistFile>> Vector;
123  typedef std::map<std::string, std::shared_ptr<NetlistFile>> StringMap;
124 
125  private:
126  std::filesystem::path m_path;
127  std::string m_name;
128  std::string m_units;
129  bool m_optimized;
130  Staggered m_staggered;
131 
132  NetRecord::Vector m_netRecords;
133  NetRecord::StringMap m_netRecordsByName;
134  NetPointRecord::Vector m_netPointRecords;
135 
136  inline constexpr static const char HEADER_TOKEN[] = "H";
137  inline constexpr static const char STAGGERED_KEY[] = "staggered";
138 
139  // Inherited via IStreamSaveable
140  bool Save(std::ostream& os) override;
141 
142  }; // NetlistFile
143 }