OdbDesignLib
OdbDesign ODB++ Parsing Library
AttrListFile.h
1 //
2 // Created by nmill on 10/13/2023.
3 //
4 #ifndef ODBDESIGN_ATTRLISTFILE_H
5 #define ODBDESIGN_ATTRLISTFILE_H
6 
7 #include <string>
8 #include <map>
9 #include <filesystem>
10 #include "../../IProtoBuffable.h"
11 #include "../../ProtoBuf/attrlistfile.pb.h"
12 #include "../../odbdesign_export.h"
13 #include "../IStreamSaveable.h"
14 #include <memory>
15 
16 namespace Odb::Lib::FileModel::Design
17 {
18  class ODBDESIGN_EXPORT AttrListFile : public IProtoBuffable<Odb::Lib::Protobuf::AttrListFile>, public IStreamSaveable
19  {
20  public:
21  AttrListFile();
22 
23  typedef std::map<std::string, std::string> AttributeMap;
24 
25  std::string GetUnits() const;
26  const AttributeMap& GetAttributes() const;
27 
28  bool Parse(std::filesystem::path directory);
29  // Inherited via IStreamSaveable
30  bool Save(std::ostream& os) override;
31 
32  // Inherited via IProtoBuffable
33  std::unique_ptr<Odb::Lib::Protobuf::AttrListFile> to_protobuf() const override;
34  void from_protobuf(const Odb::Lib::Protobuf::AttrListFile& message) override;
35 
36  private:
37  std::filesystem::path m_directory;
38  std::filesystem::path m_path;
39  std::string m_units;
40  AttributeMap m_attributesByName;
41 
42  bool attributeValueIsOptional(const std::string& attributeName) const;
43 
44  inline static const auto ATTRLIST_FILENAMES = { "attrlist" };
45  inline static const char* OPTIONAL_ATTRIBUTES[] = { "" };
46  };
47 }
48 
49 #endif //ODBDESIGN_ATTRLISTFILE_H