-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAdditionalFields.h
40 lines (35 loc) · 1.06 KB
/
AdditionalFields.h
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
#ifndef ADDITIONALFIELDS_H_INCLUDED
#define ADDITIONALFIELDS_H_INCLUDED
#include <map>
#include <string>
#include <boost/lexical_cast.hpp>
#include <exception>
#include "Utils.h"
namespace FCPLib {
class AdditionalFields {
std::map<std::string, std::string> fields;
public:
AdditionalFields() {}
void addField(std::string key, int value) {
fields[key] = boost::lexical_cast<std::string>(value);
}
void addField(std::string key, char* value) {
fields[key] = std::string( value );
}
void addField(std::string key, bool value) {
fields[key] = Converter::toString( value );
}
bool hasField(std::string key) const {
if (fields.find(key) == fields.end()) return false;
return true;
}
const std::string& getField(std::string key) const throw(std::invalid_argument){
std::map<std::string, std::string>::const_iterator it;
it = fields.find(key);
if (it == fields.end())
throw std::invalid_argument("Additional fields object does not contain: " + key);
return it->second;
}
};
}
#endif // ADDITIONALFIELDS_H_INCLUDED