-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsection_col.cpp
More file actions
56 lines (42 loc) · 1.22 KB
/
section_col.cpp
File metadata and controls
56 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <map>
#include <iostream>
#include "section_col.h"
#include <algorithm>
#include <stdexcept>
using namespace std;
void SectionCol::add_section(Section &c) {
string sectionName = c.get_name();
sections.insert(map<string, Section>::value_type(sectionName, c));
}
void SectionCol::delete_section(string name) {
map<string, Section>::iterator it = sections.find(name);
if (it != sections.end()) {
sections.erase(it);
} else {
throw logic_error("This section does not exist - " + name + "\n");
}
}
Section &SectionCol::get_section(string name) {
if (is_section(name)) {
return sections.find(name)->second;
} else {
throw logic_error("This section does not exist - " + name + "\n");
}
}
const map<string, Section> &SectionCol::get_sections() const {
return sections;
}
bool SectionCol::is_section(string name) {
map<string, Section>::iterator it = sections.find(name);
if (it != sections.end()) {
return true;
}
return false;
}
void SectionCol::show_all() {
cout << "Sections: " << endl;
map<string, Section>::iterator it;
for (it = sections.begin(); it != sections.end(); it++) {
cout << it->second << endl;
}
}