LCOV - code coverage report
Current view: top level - OdbDesignLib/ProductModel - Component.cpp (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 94.6 % 56 53
Test Date: 2026-11-21 03:51:50 Functions: 92.3 % 13 12
Legend: Lines: hit not hit

            Line data    Source code
       1              : #include "Component.h"
       2              : #include "component.pb.h"
       3              : #include "enums.pb.h"
       4              : #include <string>
       5              : #include <memory>
       6              : #include "../enums.h"
       7              : #include "Part.h"
       8              : #include "Package.h"
       9              : #include "../Text/Utf8Sanitizer.h"
      10              : 
      11              : 
      12              : namespace Odb::Lib::ProductModel
      13              : {
      14        16140 :         Component::Component()
      15        16140 :                 : m_refDes("")
      16        32280 :                 , m_partName("")
      17        16140 :                 , m_pPackage(nullptr)
      18        16140 :                 , m_index(static_cast<unsigned>(-1))
      19        16140 :                 , m_side(BoardSide::BsNone)
      20        32280 :                 , m_pPart(nullptr)
      21              :         {
      22        16140 :         }
      23              : 
      24        49854 :         Component::Component(const std::string& refDes, const std::string& partName, std::shared_ptr<Package> pPackage, unsigned int index, BoardSide side, std::shared_ptr<Part> pPart, std::optional<unsigned int> id)
      25        49854 :                 : m_refDes(refDes)
      26        49854 :                 , m_partName(partName)
      27        49854 :                 , m_pPackage(pPackage)
      28        49854 :                 , m_index(index)
      29        49854 :                 , m_side(side)
      30        49854 :                 , m_pPart(pPart)
      31        99708 :                 , m_id(std::move(id))
      32              :         {
      33        49854 :         }
      34              : 
      35        65996 :         Component::~Component()
      36              :         {
      37        65996 :         }
      38              : 
      39       572133 :         std::string Component::GetRefDes() const
      40              :         {
      41       572133 :                 return m_refDes;
      42              :         }
      43              : 
      44            0 :         std::string Component::GetPartName() const
      45              :         {
      46            0 :                 return m_partName;
      47              :         }
      48              : 
      49       225892 :         std::shared_ptr<Package> Component::GetPackage() const
      50              :         {
      51       225892 :                 return m_pPackage;
      52              :         }
      53              : 
      54            4 :         unsigned int Component::GetIndex() const
      55              :         {
      56            4 :                 return m_index;
      57              :         }
      58              : 
      59        68678 :         BoardSide Component::GetSide() const
      60              :         {
      61        68678 :                 return m_side;
      62              :         }
      63              : 
      64            4 :         std::shared_ptr<Part> Component::GetPart() const
      65              :         {
      66            4 :                 return m_pPart;
      67              :         }
      68              : 
      69        68674 :         std::optional<unsigned int> Component::GetId() const
      70              :         {
      71        68674 :                 return m_id;
      72              :         }
      73              : 
      74        77790 :         std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Component> Component::to_protobuf() const
      75              :         {
      76        77790 :                 auto pComponentMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::Component>();
      77       155580 :                 pComponentMsg->set_refdes(Odb::Lib::Text::ToUtf8(m_refDes));
      78       155580 :                 pComponentMsg->set_partname(Odb::Lib::Text::ToUtf8(m_partName));
      79        77790 :                 pComponentMsg->set_index(m_index);
      80        77790 :                 pComponentMsg->set_side(static_cast<Odb::Lib::Protobuf::BoardSide>(m_side));
      81        77790 :                 pComponentMsg->mutable_package()->CopyFrom(*m_pPackage->to_protobuf());                
      82        77790 :                 pComponentMsg->mutable_part()->CopyFrom(*m_pPart->to_protobuf());
      83        77790 :                 if (m_id.has_value())
      84              :                 {
      85        77790 :                         pComponentMsg->set_id(*m_id);
      86              :                 }
      87        77790 :                 return pComponentMsg;
      88            0 :         }
      89              : 
      90        20776 :         void Component::from_protobuf(const Odb::Lib::Protobuf::ProductModel::Component& message)
      91              :         {
      92        20776 :                 m_refDes = message.refdes();
      93        20776 :                 m_partName = message.partname();
      94        20776 :                 m_index = message.index();
      95        20776 :                 m_side = static_cast<BoardSide>(message.side());
      96        20776 :                 m_id = message.has_id() ? std::optional<unsigned int>(message.id()) : std::nullopt;
      97        20776 :                 m_pPackage = std::make_shared<Package>("", -1);
      98        20776 :                 m_pPackage->from_protobuf(message.package());
      99        20776 :                 m_pPart = std::make_shared<Part>("");
     100        20776 :                 m_pPart->from_protobuf(message.part());
     101        20776 :         }
     102              : 
     103              :         //Component* Component::MakeEmpty()
     104              :         //{
     105              :         //      return new Component();
     106              :         //}
     107              : 
     108              : } // namespace Odb::Lib::ProductModel
        

Generated by: LCOV version 2.0-1