Tag Parser  6.1.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
statusprovider.cpp
Go to the documentation of this file.
1 #include "./statusprovider.h"
2 
3 using namespace std;
4 
5 namespace Media {
6 
17 StatusProvider::StatusProvider() :
18  m_worstNotificationType(NotificationType::None),
19  m_percentage(0.0),
20  m_abort(false),
21  m_forward(nullptr)
22 {}
23 
34 {
35  size_t id = 0;
36  for(auto &registred : m_callbacks) {
37  if(!registred) {
38  registred = callback;
39  return id;
40  }
41  ++id;
42  }
43  m_callbacks.push_back(callback);
44  return id;
45 }
46 
51 {
52  m_notifications.push_back(notification);
53  m_worstNotificationType |= notification.type();
54  invokeCallbacks();
55 }
56 
61 void StatusProvider::addNotification(NotificationType type, const string &message, const string &context)
62 {
63  m_notifications.emplace_back(type, message, context);
64  m_worstNotificationType |= type;
65  invokeCallbacks();
66 }
67 
73 {
74  if(&from == this) {
75  return;
76  }
77  m_notifications.insert(m_notifications.end(), from.m_notifications.cbegin(), from.m_notifications.cend());
78  m_worstNotificationType |= from.worstNotificationType();
79  invokeCallbacks();
80 }
81 
88 void StatusProvider::addNotifications(const string &higherContext, const StatusProvider &from)
89 {
90  if(&from == this) {
91  return;
92  }
93  for(const auto &notification : from.m_notifications) {
94  addNotification(notification.type(), notification.message(), higherContext + ", " + notification.context());
95  }
96 }
97 
102 {
103  m_notifications.insert(m_notifications.end(), notifications.cbegin(), notifications.cend());
104  if(m_worstNotificationType != Notification::worstNotificationType()) {
105  for(const Notification &notification : notifications) {
106  if((m_worstNotificationType |= notification.type()) == Notification::worstNotificationType()) {
107  break;
108  }
109  }
110  }
111  invokeCallbacks();
112 }
113 
114 }
size_t registerCallback(CallbackFunction callback)
Registers a callback function.
const NotificationList & notifications() const
Returns notifications for the current object.
NotificationType
Specifies the notification type.
Definition: notification.h:18
NotificationType worstNotificationType() const
Returns the worst notification type.
STL namespace.
void addNotification(const Notification &notification)
This protected method is meant to be called by the derived class to add a notification.
static constexpr NotificationType worstNotificationType()
Returns the worst notification type.
Definition: notification.h:98
std::function< void(StatusProvider &sender)> CallbackFunction
NotificationType type() const
Returns the notification type.
Definition: notification.h:66
std::list< Notification > NotificationList
Definition: notification.h:39
The Notification class holds a notification message of a certain notification type.
Definition: notification.h:43
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
The StatusProvider class acts as a base class for objects providing status information.
void addNotifications(const StatusProvider &from)
This protected method is meant to be called by the derived class to add all notifications from anothe...