Line data Source code
1 :
2 : #include "ErrorHandler/MessageAnalyzer/ma_participants.h"
3 :
4 : #include <sstream>
5 : #include <stdexcept>
6 :
7 : using namespace novadaq::errorhandler;
8 :
9 : // -----------------------------------------------------------------
10 : // add group
11 :
12 0 : void ma_participants::add_group(std::string const& group)
13 : {
14 0 : groups_t::const_iterator it = groups.find(group);
15 :
16 0 : if (it != groups.end())
17 0 : throw std::runtime_error(group + " already exists while creating new group");
18 :
19 0 : string_set_t apps;
20 0 : groups.insert(std::make_pair(group, apps));
21 0 : }
22 :
23 0 : void ma_participants::add_group(std::string const& group, size_t size)
24 : {
25 0 : groups_t::const_iterator it = groups.find(group);
26 :
27 0 : if (it != groups.end())
28 0 : throw std::runtime_error(group + " already exists while creating new group");
29 :
30 0 : string_set_t apps;
31 0 : std::stringstream ss;
32 :
33 0 : for (size_t i = 0; i < size; ++i)
34 : {
35 0 : ss.str(group);
36 0 : ss << "-" << i;
37 0 : apps.insert(ss.str());
38 0 : all_apps.insert(ss.str());
39 : }
40 :
41 0 : groups.insert(std::make_pair(group, apps));
42 0 : }
43 :
44 : // -----------------------------------------------------------------
45 : // add participant
46 :
47 0 : void ma_participants::add_participant(std::string const& group, std::string const& app)
48 : {
49 0 : groups_t::iterator it = groups.find(group);
50 :
51 0 : if (it == groups.end())
52 0 : throw std::runtime_error(group + " does not exist while inserting participants");
53 :
54 0 : it->second.insert(app);
55 0 : all_apps.insert(app);
56 0 : }
57 :
58 0 : void ma_participants::add_participant(std::string const& app)
59 : {
60 0 : ungrouped_apps.insert(app);
61 0 : all_apps.insert(app);
62 0 : }
63 :
64 : // -----------------------------------------------------------------
65 : // get count
66 :
67 0 : size_t ma_participants::
68 : get_group_participant_count(std::string const& group) const
69 : {
70 0 : groups_t::const_iterator it = groups.find(group);
71 :
72 0 : if (it == groups.end())
73 0 : throw std::runtime_error(group + " does not exist while getting participant count");
74 :
75 0 : return it->second.size();
76 : }
77 :
78 0 : size_t ma_participants::
79 : get_participant_count() const
80 : {
81 0 : return all_apps.size();
82 : }
83 :
84 : // -----------------------------------------------------------------
85 : // reset
86 0 : void ma_participants::reset()
87 : {
88 0 : ungrouped_apps.clear();
89 0 : all_apps.clear();
90 0 : groups.clear();
91 0 : }
|