1 #include "SymbolsDirectory.h"
5 #include "FeaturesFile.h"
6 #include "AttrListFile.h"
9 namespace Odb::Lib::FileModel::Design
11 SymbolsDirectory::SymbolsDirectory(
const std::filesystem::path& path)
17 bool SymbolsDirectory::Parse()
20 if (!std::filesystem::exists(m_path))
return false;
21 else if (!std::filesystem::is_directory(m_path))
return false;
23 m_name = std::filesystem::path(m_path).filename().string();
25 loginfo(
"Parsing symbols directory: " + m_name +
"...");
27 if (!ParseFeaturesFile(m_path))
return false;
28 if (!ParseAttrListFile(m_path))
return false;
30 loginfo(
"Parsing symbols directory: " + m_name +
" complete");
35 std::string SymbolsDirectory::GetName()
const {
return m_name; }
36 std::filesystem::path SymbolsDirectory::GetPath()
const {
return m_path; }
38 const FeaturesFile& SymbolsDirectory::GetFeaturesFile()
const {
return m_featuresFile; }
39 const AttrListFile& SymbolsDirectory::GetAttrListFile()
const {
return m_attrListFile; }
41 std::unique_ptr<Odb::Lib::Protobuf::SymbolsDirectory> SymbolsDirectory::to_protobuf()
const
43 auto message = std::make_unique<Odb::Lib::Protobuf::SymbolsDirectory>();
44 message->set_name(m_name);
45 message->set_path(m_path.string());
46 message->mutable_attrlistfile()->CopyFrom(*m_attrListFile.to_protobuf());
47 message->mutable_featurefile()->CopyFrom(*m_featuresFile.to_protobuf());
51 void SymbolsDirectory::from_protobuf(
const Odb::Lib::Protobuf::SymbolsDirectory& message)
53 m_name = message.name();
54 m_path = message.path();
55 m_attrListFile.from_protobuf(message.attrlistfile());
56 m_featuresFile.from_protobuf(message.featurefile());
59 bool SymbolsDirectory::ParseFeaturesFile(
const std::filesystem::path& directory)
61 return m_featuresFile.Parse(directory);
64 bool SymbolsDirectory::ParseAttrListFile(
const std::filesystem::path& directory)
66 return m_attrListFile.Parse(directory);
69 bool SymbolsDirectory::Save(
const std::filesystem::path& directory)
71 auto symbolDir = directory / m_name;
72 if (!create_directory(symbolDir))
return false;
75 std::ofstream featuresFile(symbolDir /
"features");
76 if (!featuresFile.is_open())
return false;
77 if (!m_featuresFile.Save(featuresFile))
return false;
81 std::ofstream attrlistFile(symbolDir /
"attrlist");
82 if (!attrlistFile.is_open())
return false;
83 if (!m_attrListFile.Save(attrlistFile))
return false;