LCOV - code coverage report
Current view: top level - python - docstring.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 6 100.0 %
Date: 2024-11-24 01:48:31 Functions: 6 6 100.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             : #pragma once
       6             : 
       7             : #include <map>
       8             : #include <string>
       9             : #include <vector>
      10             : 
      11             : #include "scipp/dataset/dataset.h"
      12             : #include "scipp/variable/variable.h"
      13             : 
      14             : using namespace scipp::variable;
      15             : using namespace scipp::dataset;
      16             : 
      17          72 : template <class T> const std::string type_to_string() {
      18             :   if (std::is_same_v<T, Variable>)
      19             :     return "Variable";
      20             :   if (std::is_same_v<T, DataArray>)
      21          36 :     return "DataArray";
      22             :   if (std::is_same_v<T, Dataset>)
      23          36 :     return "Dataset";
      24             :   return "";
      25             : }
      26             : 
      27             : class Docstring {
      28             : public:
      29             :   Docstring &description(const std::string &s, const bool append = false);
      30             :   Docstring &raises(const std::string &s, const bool append = false);
      31             :   Docstring &seealso(const std::string &s, const bool append = false);
      32             :   Docstring &returns(const std::string &s, const bool append = false);
      33             :   Docstring &rtype(const std::string &s, const bool append = false);
      34             :   Docstring &param(const std::string &name, const std::string &about,
      35             :                    const std::string &type);
      36             : 
      37          66 :   template <class T> Docstring &rtype() { return rtype(type_to_string<T>()); }
      38             : 
      39             :   template <class T>
      40           6 :   Docstring &param(const std::string &name, const std::string &about) {
      41           6 :     return param(name, about, type_to_string<T>());
      42             :   }
      43             : 
      44             :   const char *c_str();
      45             : 
      46             : private:
      47             :   std::string m_description;
      48             :   std::string m_raises;
      49             :   std::string m_seealso;
      50             :   std::string m_returns;
      51             :   std::string m_rtype;
      52             :   std::string m_output;
      53             :   std::vector<std::string> m_order;
      54             :   std::map<std::string, std::pair<std::string, std::string>> m_params;
      55             :   void update(std::string &field, const std::string &s,
      56             :               const bool append = false);
      57             : };

Generated by: LCOV version 1.14