-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedia.cpp
More file actions
66 lines (60 loc) · 1.47 KB
/
media.cpp
File metadata and controls
66 lines (60 loc) · 1.47 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* media.h
*
* @authors Juan Arias & Nick Tibbott
*
*/
#include "media.h"
/*
* Friend function
* Output stream operator overload
*/
ostream& operator<<(ostream& os, const Media& media) {
os << media.type;
return os;
}
/*
* Static function to ensure map is initialized when subclasses self register
*@return static map holding all self registered subclasses
*/
map<string, Media *>& Media::getMap() {
static map<string, Media*> typeMap;
return typeMap;
}
/*
* Static function for subclasses to self register
* @param type The name of the type of Media
* @param media The instance of the subclass to self register
*/
void Media::registerType(const string& type, Media* media) {
Media::getMap().emplace(type, media);
}
/*
* constructs Media from a given string
*/
Media::Media(const string& type): type(type) {
}
/*
* Static function for client to retrieve a Media subclass
* according to its name as a string
* @param type The name of the type of Media
*/
const Media* Media::getMedia(const string& type) {
auto map = Media::getMap();
if(map.find(type) != map.end())
{
if (map.at(type) != nullptr)
return map.at(type);
else
return nullptr;
} else{
return nullptr;
}
// return Media::getMap().count(type) ? Media::getMap().at(type) : nullptr;
}
/*
* Less than operator overload to allow sorting in map containers
*/
bool Media::operator<(const Media& other) const {
return this->type < other.type;
}