bactria  0.0.1
The bactria library is a header-only C++14 library for profiling and tracing.
Incident.hpp
Go to the documentation of this file.
1 /* Copyright 2021 Jan Stephan
2  *
3  * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
4  * the European Commission - subsequent versions of the EUPL (the “Licence”).
5  * You may not use this work except in compliance with the Licence.
6  * You may obtain a copy of the Licence at:
7  *
8  * http://ec.europa.eu/idabc/eupl.html
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the Licence is distributed on an “AS IS” basis, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * Licence permissions and limitations under the Licence.
14  */
15 
23 #pragma once
24 
25 #include <string>
26 #include <type_traits>
27 #include <utility>
28 
29 namespace bactria
30 {
31  namespace reports
32  {
33  template<typename... TIncidents>
34  class Report;
35 
46  template<typename TValue>
47  class Incident
48  {
49  static_assert(
50  std::is_arithmetic<TValue>::value || std::is_same<TValue, std::string>::value,
51  "Incident value must be an arithmetic type or std::string");
52 
53  template<typename... TIncidents>
54  friend class Report;
55 
56  public:
62  Incident() = default;
63 
72  Incident(std::string key, TValue value) : m_key{std::move(key)}, m_value{value}
73  {
74  }
75 
84  Incident(Incident const& other) : m_key{other.m_key}, m_value{other.m_value}
85  {
86  }
87 
96  auto operator=(Incident const& rhs) -> Incident&
97  {
98  m_key = rhs.m_key;
99  m_value = rhs.m_value;
100  return *this;
101  }
102 
111  Incident(Incident&& other) noexcept : m_key{std::move(other.m_key)}, m_value{std::move(other.m_value)}
112  {
113  }
114 
123  auto operator=(Incident&& rhs) noexcept -> Incident&
124  {
125  m_key = std::move(rhs.m_key);
126  m_value = std::move(rhs.m_value);
127  return *this;
128  }
129 
133  ~Incident() = default;
134 
135  private:
136  std::string m_key{"BACTRIA_INCIDENT"};
137  TValue m_value{};
138  };
139 
152  template<typename TValue>
153  auto make_incident(std::string key, TValue value) -> Incident<std::remove_reference_t<TValue>>
154  {
155  using ValueType = std::remove_reference_t<TValue>;
156  return Incident<ValueType>{std::move(key), value};
157  }
158  } // namespace reports
159 } // namespace bactria
bactria::reports::Report
The report class.
Definition: Incident.hpp:34
bactria::reports::Incident::Incident
Incident(std::string key, TValue value)
Constructor.
Definition: Incident.hpp:72
bactria::reports::Incident::operator=
auto operator=(Incident const &rhs) -> Incident &
Copy-assignment operator.
Definition: Incident.hpp:96
bactria::reports::Incident::~Incident
~Incident()=default
Destructor.
bactria::reports::make_incident
auto make_incident(std::string key, TValue value) -> Incident< std::remove_reference_t< TValue >>
Create an incident from a key and a value.
Definition: Incident.hpp:153
bactria::reports::Incident
The incident type.
Definition: Incident.hpp:47
bactria::reports::Incident::Incident
Incident()=default
Default constructor.
bactria::reports::Incident::operator=
auto operator=(Incident &&rhs) noexcept -> Incident &
Move-assignment operator.
Definition: Incident.hpp:123
bactria::reports::Incident::Incident
Incident(Incident &&other) noexcept
Move constructor.
Definition: Incident.hpp:111
bactria::reports::Incident::Incident
Incident(Incident const &other)
Copy constructor.
Definition: Incident.hpp:84