LCOV - code coverage report
Current view: top level - OdbDesignLib/FileModel/Design - SymbolsDirectory.cpp (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 68.8 % 48 33
Test Date: 2026-11-21 03:51:50 Functions: 81.8 % 11 9
Legend: Lines: hit not hit

            Line data    Source code
       1              : #include "SymbolsDirectory.h"
       2              : #include "Logger.h"
       3              : #include <filesystem>
       4              : #include <string>
       5              : #include "FeaturesFile.h"
       6              : #include "AttrListFile.h"
       7              : #include <memory>
       8              : #include "../../Text/Utf8Sanitizer.h"
       9              : 
      10              : namespace Odb::Lib::FileModel::Design
      11              : {
      12         6377 :         SymbolsDirectory::SymbolsDirectory(const std::filesystem::path& path)
      13         6377 :                 : m_name("")
      14        12754 :                 , m_path(path)
      15              :         {
      16         6377 :         }
      17              : 
      18         6017 :         bool SymbolsDirectory::Parse()
      19              :         {
      20              : 
      21         6017 :                 if (!std::filesystem::exists(m_path)) return false;
      22         6017 :                 else if (!std::filesystem::is_directory(m_path)) return false;
      23              : 
      24         6017 :                 m_name = std::filesystem::path(m_path).filename().string();
      25              : 
      26        12034 :                 loginfo("Parsing symbols directory: " + m_name + "...");
      27              : 
      28         6017 :                 if (!ParseFeaturesFile(m_path)) return false;
      29         6017 :                 if (!ParseAttrListFile(m_path)) return false;
      30              : 
      31        12034 :                 loginfo("Parsing symbols directory: " + m_name + " complete");
      32              : 
      33         6017 :                 return true;
      34              :         }
      35              : 
      36         6017 :         std::string SymbolsDirectory::GetName() const { return m_name; }
      37            0 :         std::filesystem::path SymbolsDirectory::GetPath() const { return m_path; }
      38              : 
      39         4476 :         const FeaturesFile& SymbolsDirectory::GetFeaturesFile() const { return m_featuresFile; }
      40         4476 :         const AttrListFile& SymbolsDirectory::GetAttrListFile() const { return m_attrListFile; }
      41              : 
      42         4988 :         std::unique_ptr<Odb::Lib::Protobuf::SymbolsDirectory> SymbolsDirectory::to_protobuf() const
      43              :         {
      44         4988 :                 auto message = std::make_unique<Odb::Lib::Protobuf::SymbolsDirectory>();
      45         9976 :                 message->set_name(Odb::Lib::Text::ToUtf8(m_name));
      46         9976 :                 message->set_path(Odb::Lib::Text::ToUtf8(m_path.string()));
      47         4988 :                 message->mutable_attrlistfile()->CopyFrom(*m_attrListFile.to_protobuf());
      48         4988 :                 message->mutable_featurefile()->CopyFrom(*m_featuresFile.to_protobuf());
      49         4988 :                 return message;
      50            0 :         }
      51              : 
      52          360 :         void SymbolsDirectory::from_protobuf(const Odb::Lib::Protobuf::SymbolsDirectory& message)
      53              :         {
      54          360 :                 m_name = message.name();
      55          360 :                 m_path = message.path();
      56          360 :                 m_attrListFile.from_protobuf(message.attrlistfile());
      57          360 :                 m_featuresFile.from_protobuf(message.featurefile());
      58          360 :         }
      59              :         
      60         6017 :         bool SymbolsDirectory::ParseFeaturesFile(const std::filesystem::path& directory)
      61              :         {
      62        18051 :                 return m_featuresFile.Parse(directory);
      63              :         }
      64              : 
      65         6017 :         bool SymbolsDirectory::ParseAttrListFile(const std::filesystem::path& directory)
      66              :         {
      67         6017 :                 return m_attrListFile.Parse(directory);
      68              :         }
      69              : 
      70            0 :         bool SymbolsDirectory::Save(const std::filesystem::path& directory)
      71              :         {
      72            0 :                 auto symbolDir = directory / m_name;
      73            0 :                 if (!create_directory(symbolDir)) return false;
      74              : 
      75              :                 //FeaturesFile m_featuresFile;
      76            0 :                 std::ofstream featuresFile(symbolDir / "features");
      77            0 :                 if (!featuresFile.is_open()) return false;
      78            0 :                 if (!m_featuresFile.Save(featuresFile)) return false;
      79            0 :                 featuresFile.close();
      80              : 
      81              :                 //AttrListFile m_attrListFile;
      82            0 :                 std::ofstream attrlistFile(symbolDir / "attrlist");
      83            0 :                 if (!attrlistFile.is_open()) return false;
      84            0 :                 if (!m_attrListFile.Save(attrlistFile)) return false;
      85            0 :                 attrlistFile.close();
      86              : 
      87            0 :                 return true;
      88            0 :         }
      89              : }
        

Generated by: LCOV version 2.0-1