LCOV - code coverage report
Current view: top level - jdx - AuditTrail.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 35 37 94.6 %
Date: 2025-06-15 16:18:27 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* Copyright (C) 2025 Robert Schiwon
       2             :  *
       3             :  * This file is part of libjdx.
       4             :  *
       5             :  * libjdx is free software: you can redistribute it and/or modify it under the
       6             :  * terms of the GNU Lesser General Public License as published by the Free
       7             :  * Software Foundation, either version 3 of the License, or (at your option) any
       8             :  * later version.
       9             :  *
      10             :  * libjdx is distributed in the hope that it will be useful, but WITHOUT ANY
      11             :  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      12             :  * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with libjdx. If not, see <https://www.gnu.org/licenses/>.
      17             :  */
      18             : #include "jdx/AuditTrail.hpp"
      19             : #include "util/AuditTrailParser.hpp"
      20             : #include "util/LdrUtils.hpp"
      21             : #include "util/StringUtils.hpp"
      22             : 
      23             : #include <algorithm>
      24             : 
      25          18 : libjdx::jdx::AuditTrail::AuditTrail(const std::string& label,
      26             :     std::string variableList, io::TextReader& reader,
      27          18 :     std::optional<std::string>& nextLine)
      28          18 :     : TabularData(label, std::move(variableList), reader)
      29             : {
      30          36 :     auto varList = getVariableList();
      31          18 :     util::trim(varList);
      32          18 :     validateInput(getLabel(), varList, s_label,
      33          36 :         std::vector<std::string>{
      34             :             std::begin(s_variableLists), std::end(s_variableLists)});
      35             : 
      36             :     // Bruker quirk: check if overruling Bruker var list is present
      37          18 :     m_brukerVarList = scanForBrukerVarList(nextLine);
      38          18 :     if (m_brukerVarList)
      39             :     {
      40           1 :         validateInput(getLabel(), m_brukerVarList.value(), s_label,
      41           2 :             std::vector<std::string>{
      42             :                 std::begin(s_variableLists), std::end(s_variableLists)});
      43             :     }
      44             : 
      45          18 :     util::skipToNextLdr(reader, nextLine, false);
      46          18 : }
      47             : 
      48             : std::vector<libjdx::jdx::AuditTrailEntry>
      49           8 : libjdx::jdx::AuditTrail::getData() const
      50             : {
      51          16 :     auto variableList = m_brukerVarList.value_or(getVariableList());
      52           8 :     if (util::isPureComment(variableList))
      53             :     {
      54             :         // deal with variable lists that sit behind "$$"
      55             :         variableList
      56           8 :             = util::stripLineComment(variableList, false, true).second.value();
      57             :     }
      58          10 :     util::AuditTrailParser parser{getReader(), variableList};
      59             :     return TabularData::getData<util::AuditTrailParser, AuditTrailEntry>(
      60          16 :         parser);
      61             : }
      62             : 
      63          18 : std::optional<std::string> libjdx::jdx::AuditTrail::scanForBrukerVarList(
      64             :     std::optional<std::string>& nextLine)
      65             : {
      66          18 :     auto& reader = getReader();
      67          18 :     if (!reader.eof())
      68             :     {
      69          18 :         nextLine = reader.readLine();
      70          18 :         if (!nextLine
      71          18 :             || nextLine.value().rfind("$$ ##TITLE= Audit trail,", 0) != 0)
      72             :         {
      73          17 :             return std::nullopt;
      74             :         }
      75             :     }
      76             :     // Bruker audit trail
      77           5 :     while (!reader.eof())
      78             :     {
      79           5 :         nextLine = reader.readLine();
      80           5 :         if (!nextLine || !util::isPureComment(nextLine.value()))
      81             :         {
      82           0 :             break;
      83             :         }
      84           5 :         if (nextLine.value().rfind("$$ ##AUDIT TRAIL=", 0) == 0)
      85             :         {
      86             :             auto brukerAuditTrail
      87           1 :                 = util::stripLineComment(nextLine.value(), false, true)
      88           2 :                       .second.value();
      89           2 :             auto brukerVarList = util::parseLdrStart(brukerAuditTrail).second;
      90           1 :             util::trim(brukerVarList);
      91           1 :             return brukerVarList;
      92             :         }
      93             :     }
      94           0 :     return std::nullopt;
      95             : }

Generated by: LCOV version 1.14