summaryrefslogtreecommitdiff
path: root/src/urlreader.cpp
blob: c417df869186cbdd97cbcc4f5c7f519eb45f685e (plain) (blame)
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
#include <fstream>

#include <urlreader.h>

using namespace newsbeuter;

urlreader::urlreader(const std::string& file) : filename(file) {
	reload();
}

urlreader::~urlreader() { }

std::vector<std::string>& urlreader::get_urls() {
	return urls;
}

void urlreader::reload() {
	std::fstream f;
	f.open(filename.c_str(),std::fstream::in);
	if (f.is_open()) {
		std::string line;
		do {
			getline(f,line);
			if (!f.eof() && line.length() > 0 && line[0] != '#')
				urls.push_back(line);
		} while (!f.eof());
	}
}

void urlreader::load_config(const std::string& file) {
	filename = file;
	reload();
}

void urlreader::write_config() {
	std::fstream f;
	f.open(filename.c_str(),std::fstream::out);
	if (f.is_open()) {
		for (std::vector<std::string>::iterator it=urls.begin(); it != urls.end(); ++it) {
			f << *it << std::endl;
		}
	}
}