CbmRoot
Loading...
Searching...
No Matches
CbmQaReportElement.h
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once
11
12#include "CbmQaReportDefines.h"
13
14#include <memory>
15#include <string>
16#include <vector>
17
18namespace cbm::qa::report
19{
20 class Engine;
21
25 class Element {
26 friend class CollapsibleElement;
27
28 public:
32 Element(std::string_view label, std::string_view title) : fsLabel(label), fsTitle(title) {}
33
35 Element() = default;
36
38 virtual ~Element() = default;
39
42 virtual std::string GetBody(const Engine& engine) const = 0;
43
45 const std::string& GetLabel() const { return fsLabel; }
46
48 const std::string& GetTitle() const { return fsTitle; }
49
51 void SetLabel(std::string_view label) { fsLabel = label; }
52
54 void SetTitle(std::string_view title) { fsTitle = title; }
55
57 const Element* GetMother() const { return fpMother; }
58
59 private:
60 void AssignMother(const Element* pMother) { fpMother = pMother; }
61
62 // TODO: Add check for multiple label definition
63 const Element* fpMother = nullptr;
64 std::string fsLabel = "";
65 std::string fsTitle = "";
66 };
67
71 class CollapsibleElement : public Element {
72 public:
73 using Element::Element;
74
76 virtual ~CollapsibleElement() = default;
77
79 // TODO: Check for label
80 virtual void Add(std::shared_ptr<Element> pElement)
81 {
82 pElement->AssignMother(this);
83 fvDaughterElements.push_back(pElement);
84 }
85
87 const std::vector<std::shared_ptr<Element>> GetDaughterElements() const { return fvDaughterElements; }
88
89 private:
90 std::vector<std::shared_ptr<Element>> fvDaughterElements;
91 };
92} // namespace cbm::qa::report
Common definitions for cbm::qa::report.
Interface to the element, which can contain daughter elements.
const std::vector< std::shared_ptr< Element > > GetDaughterElements() const
Get daughter elements.
std::vector< std::shared_ptr< Element > > fvDaughterElements
Daughter elements.
virtual void Add(std::shared_ptr< Element > pElement)
Adds element.
virtual ~CollapsibleElement()=default
Destructor.
Interface for the report element.
virtual ~Element()=default
Destructor.
virtual std::string GetBody(const Engine &engine) const =0
Gets body of the element.
const Element * GetMother() const
Gets mother element.
void AssignMother(const Element *pMother)
std::string fsLabel
Label for referencing.
const Element * fpMother
Mother element.
Element(std::string_view label, std::string_view title)
Constructor.
Element()=default
Default constructor.
const std::string & GetTitle() const
Gets name.
std::string fsTitle
Title of the element.
const std::string & GetLabel() const
Gets label.
void SetTitle(std::string_view title)
Sets name.
void SetLabel(std::string_view label)
Sets label.
A base abstract class to provide an interface for element body (a visitor in the Visitor pattern)