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 
14 namespace Odb::Lib::FileModel::Design
15 {
16  class ODBDESIGN_EXPORT AttrListFile : public IProtoBuffable<Odb::Lib::Protobuf::AttrListFile>
17  {
18  public:
19  AttrListFile();
20 
21  typedef std::map<std::string, std::string> AttributeMap;
22 
23  std::string GetUnits() const;
24  const AttributeMap& GetAttributes() const;
25 
26  bool Parse(std::filesystem::path directory);
27 
28  // Inherited via IProtoBuffable
29  std::unique_ptr<Odb::Lib::Protobuf::AttrListFile> to_protobuf() const override;
30  void from_protobuf(const Odb::Lib::Protobuf::AttrListFile& message) override;
31 
32  private:
33  std::filesystem::path m_directory;
34  std::filesystem::path m_path;
35  std::string m_units;
36  AttributeMap m_attributesByName;
37 
38  bool attributeValueIsOptional(const std::string& attributeName) const;
39 
40  inline static const auto ATTRLIST_FILENAMES = { "attrlist" };
41  inline static const char* OPTIONAL_ATTRIBUTES[] = { "" };
42  };
43 
44 }
45 
46 #endif //ODBDESIGN_ATTRLISTFILE_H