LCOV - code coverage report
Current view: top level - python - docstring.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 32 41 78.0 %
Date: 2024-04-28 01:25:40 Functions: 6 8 75.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: BSD-3-Clause
       2             : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
       3             : /// @file
       4             : /// @author Neil Vaytet
       5             : #include "docstring.h"
       6             : 
       7         198 : void Docstring::update(std::string &field, const std::string &s,
       8             :                        const bool append) {
       9         198 :   if (append)
      10           0 :     field += s;
      11             :   else
      12         198 :     field = s;
      13         198 : }
      14             : 
      15          66 : Docstring &Docstring::description(const std::string &s, const bool append) {
      16          66 :   update(m_description, s, append);
      17          66 :   return *this;
      18             : }
      19             : 
      20           0 : Docstring &Docstring::raises(const std::string &s, const bool append) {
      21           0 :   update(m_raises, s, append);
      22           0 :   return *this;
      23             : }
      24             : 
      25           0 : Docstring &Docstring::seealso(const std::string &s, const bool append) {
      26           0 :   update(m_seealso, s, append);
      27           0 :   return *this;
      28             : }
      29             : 
      30          66 : Docstring &Docstring::returns(const std::string &s, const bool append) {
      31          66 :   update(m_returns, s, append);
      32          66 :   return *this;
      33             : }
      34             : 
      35          66 : Docstring &Docstring::rtype(const std::string &s, const bool append) {
      36          66 :   update(m_rtype, s, append);
      37          66 :   return *this;
      38             : }
      39             : 
      40          72 : Docstring &Docstring::param(const std::string &name, const std::string &about,
      41             :                             const std::string &type) {
      42          72 :   if (m_params.find(name) == m_params.end()) {
      43          72 :     m_order.push_back(name);
      44             :   }
      45          72 :   m_params[name] = {about, type};
      46          72 :   return *this;
      47             : }
      48             : 
      49          66 : const char *Docstring::c_str() {
      50          66 :   m_output.clear();
      51          66 :   if (m_description.size() > 0)
      52          66 :     m_output = m_description + "\n\n";
      53         138 :   for (const auto &name : m_order) {
      54         144 :     m_output += ":param " + name + ": " + m_params[name].first + "\n:type " +
      55         144 :                 name + ": " + m_params[name].second + "\n";
      56             :   }
      57          66 :   if (m_raises.size() > 0)
      58           0 :     m_output += ":raises: " + m_raises + "\n";
      59          66 :   if (m_seealso.size() > 0)
      60           0 :     m_output += ":seealso: " + m_seealso + "\n";
      61          66 :   if (m_returns.size() > 0)
      62          66 :     m_output += ":return: " + m_returns + "\n";
      63          66 :   if (m_rtype.size() > 0)
      64          66 :     m_output += ":rtype: " + m_rtype;
      65          66 :   return m_output.c_str();
      66             : }

Generated by: LCOV version 1.14