-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProperties.cpp
More file actions
77 lines (64 loc) · 1.64 KB
/
Properties.cpp
File metadata and controls
77 lines (64 loc) · 1.64 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
67
68
69
70
71
72
73
74
75
76
77
/*
* Argus Open Source
* Software to apply Statistical Disclosure Control techniques
*
* Copyright 2014 Statistics Netherlands
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the European Union Public Licence
* (EUPL) version 1.1, as published by the European Commission.
*
* You can find the text of the EUPL v1.1 on
* https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
*
* This software is distributed on an "AS IS" basis without
* warranties or conditions of any kind, either express or implied.
*/
#include "Properties.h"
#include <fstream>
using namespace std;
Properties::Properties(const string &fileName)
{
load(fileName);
}
void Properties::load(const string &fileName)
{
map.clear();
ifstream file(fileName.c_str());
if (file.is_open()) {
load(file);
file.close();
}
}
void Properties::load(istream &is)
{
string line;
while (is.good()) {
getline(is, line);
size_t pos = line.find('#');
size_t size = (pos == string::npos) ? line.size() : pos;
pos = line.find('=');
if (pos != string::npos && pos < size) {
string leftSide = line.substr(0, pos);
string rightSide = line.substr(pos + 1, size - pos - 1);
setProperty(leftSide, rightSide);
}
}
}
void Properties::setProperty(const string &key, const string &value)
{
map[key] = value;
}
string Properties::getProperty(const string &key)
{
return map[key];
}
/*
int main(int argc, char* argv[])
{
Properties properties;
properties.load("TauArgus.properties");
cout << properties.getProperty("1000") << endl;
return 0;
}
*/