LCOV - code coverage report
Current view: top level - OdbDesignLib/ProductModel - Package.cpp (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 79.6 % 54 43
Test Date: 2026-11-19 04:56:22 Functions: 66.7 % 12 8
Legend: Lines: hit not hit

            Line data    Source code
       1              : #include "Package.h"
       2              : #include <string>
       3              : #include "package.pb.h"
       4              : #include "Pin.h"
       5              : #include "ProtobufMapHelpers.h"
       6              : #include <memory>
       7              : #include "../Text/Utf8Sanitizer.h"
       8              : 
       9              : namespace Odb::Lib::ProductModel
      10              : {
      11        27390 :         Package::Package(const std::string& name, unsigned int index)
      12        27390 :                 : m_name(name)
      13        27390 :                 , m_index(index)
      14              :         {
      15        27390 :         }
      16              : 
      17        27390 :         Package::~Package()
      18              :         {
      19        27390 :                 m_pins.clear();
      20        27390 :                 m_pinsByName.clear();
      21        27390 :         }
      22              : 
      23        82768 :         std::string Package::GetName() const
      24              :         {
      25        82768 :                 return m_name;
      26              :         }
      27              : 
      28        76806 :         const Pin::Vector& Package::GetPins() const
      29              :         {
      30        76806 :                 return m_pins;
      31              :         }
      32              : 
      33        79812 :         std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Package> Package::to_protobuf() const
      34              :         {
      35        79812 :                 auto pPackageMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::Package>();
      36       159624 :                 pPackageMsg->set_name(Odb::Lib::Text::ToUtf8(m_name));
      37        79812 :                 pPackageMsg->set_index(m_index);
      38      2840726 :                 for (const auto& pPin : m_pins)
      39              :                 {
      40      2760914 :                         pPackageMsg->add_pins()->CopyFrom(*pPin->to_protobuf());
      41              :                 }
      42        79812 :                 FillProtobufMapWithSanitizedKeys(*pPackageMsg->mutable_pinsbyname(), m_pinsByName);
      43        79812 :                 return pPackageMsg;
      44            0 :         }
      45              : 
      46        21432 :         void Package::from_protobuf(const Odb::Lib::Protobuf::ProductModel::Package& message)
      47              :         {
      48        21432 :                 m_name = message.name();
      49        21432 :                 m_index = message.index();
      50       927718 :                 for (const auto& pinMsg : message.pins())
      51              :                 {
      52       906286 :                         auto pPin = std::make_shared<Pin>("", 0);
      53       906286 :                         pPin->from_protobuf(pinMsg);
      54       906286 :                         m_pins.push_back(pPin);
      55       906286 :                 }
      56      1834004 :                 for (const auto& kvPinMsg : message.pinsbyname())
      57              :                 {
      58       906286 :                         auto pPin = std::make_shared<Pin>("", 0);
      59       906286 :                         pPin->from_protobuf(kvPinMsg.second);
      60       906286 :                         m_pinsByName[kvPinMsg.first] = pPin;
      61       906286 :                 }
      62        21432 :         }
      63              : 
      64            0 :         unsigned int Package::GetIndex() const
      65              :         {
      66            0 :                 return m_index;
      67              :         }
      68              : 
      69        66790 :         void Package::AddPin(const std::string& name)
      70              :         {
      71        66790 :                 auto index = static_cast<unsigned int>(m_pins.size());
      72        66790 :                 auto pPin = std::make_shared<Pin>(name, index);
      73        66790 :                 m_pins.push_back(pPin);
      74        66790 :                 m_pinsByName[pPin->GetName()] = pPin;
      75        66790 :         }
      76              : 
      77            0 :         std::shared_ptr<Pin> Package::GetPin(const std::string& name) const
      78              :         {
      79            0 :                 auto findIt = m_pinsByName.find(name);
      80            0 :                 if (findIt != m_pinsByName.end())
      81              :                 {
      82            0 :                         return findIt->second;
      83              :                 }               
      84            0 :                 return nullptr;
      85              :         }
      86              : 
      87       157214 :         std::shared_ptr<Pin> Package::GetPin(unsigned int index) const
      88              :         {
      89       157214 :                 if (index < m_pins.size())
      90              :                 {
      91       157214 :                         return m_pins[index];
      92              :                 }
      93            0 :                 return nullptr;
      94              :         }
      95              : 
      96            0 :         const Pin::StringMap& Package::GetPinsByName() const
      97              :         {
      98            0 :                 return m_pinsByName;
      99              :         }
     100              : 
     101              : } // namespace Odb::Lib::ProductModel
        

Generated by: LCOV version 2.0-1