1#include "SymbolsDirectory.h"
5#include "FeaturesFile.h"
6#include "AttrListFile.h"
8#include "../../Text/Utf8Sanitizer.h"
10namespace Odb::Lib::FileModel::Design
12 SymbolsDirectory::SymbolsDirectory(
const std::filesystem::path& path)
18 bool SymbolsDirectory::Parse()
21 if (!std::filesystem::exists(m_path))
return false;
22 else if (!std::filesystem::is_directory(m_path))
return false;
24 m_name = std::filesystem::path(m_path).filename().string();
26 loginfo(
"Parsing symbols directory: " + m_name +
"...");
28 if (!ParseFeaturesFile(m_path))
return false;
29 if (!ParseAttrListFile(m_path))
return false;
31 loginfo(
"Parsing symbols directory: " + m_name +
" complete");
36 std::string SymbolsDirectory::GetName()
const {
return m_name; }
37 std::filesystem::path SymbolsDirectory::GetPath()
const {
return m_path; }
39 const FeaturesFile& SymbolsDirectory::GetFeaturesFile()
const {
return m_featuresFile; }
40 const AttrListFile& SymbolsDirectory::GetAttrListFile()
const {
return m_attrListFile; }
42 std::unique_ptr<Odb::Lib::Protobuf::SymbolsDirectory> SymbolsDirectory::to_protobuf()
const
44 auto message = std::make_unique<Odb::Lib::Protobuf::SymbolsDirectory>();
45 message->set_name(Odb::Lib::Text::ToUtf8(m_name));
46 message->set_path(Odb::Lib::Text::ToUtf8(m_path.string()));
47 message->mutable_attrlistfile()->CopyFrom(*m_attrListFile.to_protobuf());
48 message->mutable_featurefile()->CopyFrom(*m_featuresFile.to_protobuf());
52 void SymbolsDirectory::from_protobuf(
const Odb::Lib::Protobuf::SymbolsDirectory& message)
54 m_name = message.name();
55 m_path = message.path();
56 m_attrListFile.from_protobuf(message.attrlistfile());
57 m_featuresFile.from_protobuf(message.featurefile());
60 bool SymbolsDirectory::ParseFeaturesFile(
const std::filesystem::path& directory)
62 return m_featuresFile.Parse(directory);
65 bool SymbolsDirectory::ParseAttrListFile(
const std::filesystem::path& directory)
67 return m_attrListFile.Parse(directory);
70 bool SymbolsDirectory::Save(
const std::filesystem::path& directory)
72 auto symbolDir = directory / m_name;
73 if (!create_directory(symbolDir))
return false;
76 std::ofstream featuresFile(symbolDir /
"features");
77 if (!featuresFile.is_open())
return false;
78 if (!m_featuresFile.Save(featuresFile))
return false;
82 std::ofstream attrlistFile(symbolDir /
"attrlist");
83 if (!attrlistFile.is_open())
return false;
84 if (!m_attrListFile.Save(attrlistFile))
return false;