LCOV - code coverage report
Current view: top level - nntrainer/graph - connection.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 7 7
Test Date: 2025-12-14 20:38:17 Functions: 100.0 % 1 1

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
       4              :  *
       5              :  * @file        connection.h
       6              :  * @date        23 Nov 2020
       7              :  * @see         https://github.com/nnstreamer/nntrainer
       8              :  * @author      Jihoon Lee <jhoon.it.lee@samsung.com>
       9              :  * @bug         No known bugs except for NYI items
      10              :  * @brief       Connection class and related utility functions
      11              :  */
      12              : #ifndef __CONNECTION_H__
      13              : #define __CONNECTION_H__
      14              : 
      15              : #include <string>
      16              : #include <utility>
      17              : 
      18              : namespace nntrainer {
      19              : /**
      20              :  * @brief RAII class to define a connection
      21              :  * @note connection is a light weight class wraps around connection information
      22              :  *
      23              :  */
      24        38212 : class Connection {
      25              : public:
      26              :   /**
      27              :    * @brief Construct a new Connection object
      28              :    *
      29              :    * @param layer_name layer identifier
      30              :    * @param idx index denotes nth tensor in a layer
      31              :    */
      32              :   Connection(const std::string &layer_name, unsigned int idx);
      33              : 
      34              :   /**
      35              :    * @brief Construct a new Connection object from string representation
      36              :    * string representation is format of {layer_name, idx};
      37              :    *
      38              :    * @param str_repr string format of {layer_name}({idx})
      39              :    */
      40              :   explicit Connection(const std::string &str_repr);
      41              : 
      42              :   /**
      43              :    * @brief Construct a new Connection object
      44              :    *
      45              :    * @param rhs rhs to copy
      46              :    */
      47              :   Connection(const Connection &rhs);
      48              : 
      49              :   /**
      50              :    * @brief Copy assignment operator
      51              :    *
      52              :    * @param rhs rhs to copy
      53              :    * @return Connection&
      54              :    */
      55              :   Connection &operator=(const Connection &rhs);
      56              : 
      57              :   /**
      58              :    * @brief Move Construct Connection object
      59              :    *
      60              :    * @param rhs rhs to move
      61              :    */
      62              :   Connection(Connection &&rhs) noexcept;
      63              : 
      64              :   /**
      65              :    * @brief Move assign a connection operator
      66              :    *
      67              :    * @param rhs rhs to move
      68              :    * @return Connection&
      69              :    */
      70              :   Connection &operator=(Connection &&rhs) noexcept;
      71              : 
      72              :   /**
      73              :    * @brief string representation of connection
      74              :    *
      75              :    * @return std::string string format of {name}({idx})
      76              :    */
      77              :   std::string toString() const;
      78              : 
      79              :   /**
      80              :    * @brief Get the index
      81              :    *
      82              :    * @return unsigned index
      83              :    */
      84        21683 :   const unsigned getIndex() const { return index; }
      85              : 
      86              :   /**
      87              :    * @brief Get the index
      88              :    *
      89              :    * @return unsigned index
      90              :    */
      91        21032 :   unsigned &getIndex() { return index; }
      92              : 
      93              :   /**
      94              :    * @brief Get the Layer name object
      95              :    *
      96              :    * @return const Name& name of layer
      97              :    */
      98        28043 :   const std::string &getName() const { return name; }
      99              : 
     100              :   /**
     101              :    * @brief Get the Layer name object
     102              :    *
     103              :    * @return Name& name of layer
     104              :    */
     105        34897 :   std::string &getName() { return name; }
     106              : 
     107              :   /**
     108              :    *
     109              :    * @brief operator==
     110              :    *
     111              :    * @param rhs right side to compare
     112              :    * @return true if equal
     113              :    * @return false if not equal
     114              :    */
     115              :   bool operator==(const Connection &rhs) const noexcept;
     116              : 
     117              : private:
     118              :   unsigned index;
     119              :   std::string name;
     120              : };
     121              : 
     122              : } // namespace nntrainer
     123              : 
     124              : /**
     125              :  * @brief hash specialization for connection
     126              :  *
     127              :  */
     128              : template <> struct std::hash<nntrainer::Connection> {
     129              :   /**
     130              :    * @brief hash operator
     131              :    *
     132              :    * @param c connection to hash
     133              :    * @return std::size_t hash
     134              :    */
     135         8274 :   std::size_t operator()(const nntrainer::Connection &c) const {
     136         8274 :     return std::hash<std::string>{}(c.toString());
     137              :   }
     138              : };
     139              : 
     140              : #endif // __CONNECTION_H__
        

Generated by: LCOV version 2.0-1