-
Notifications
You must be signed in to change notification settings - Fork 0
/
hosts.hpp
50 lines (46 loc) · 1.39 KB
/
hosts.hpp
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
// Author: Alexandros Nicolaides
// Purpose: Class blueprint for hosts.cpp
// File: hosts.hpp
// Dependencies: hosts.cpp
#ifndef HOSTS_HPP
#define HOSTS_HPP
#include <iostream>
#include <algorithm> /* transform() */
#include <cstdio> /* rename(), remove() */
#include <fstream>
#include <sstream>
#include <string>
#include <unordered_set>
#include <stdexcept>
#include <cstdlib> /* abort, NULL */
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::fstream;
using std::ios;
using std::string;
using std::stringstream;
typedef std::unordered_set<string> stringset;
class Hosts{
public:
Hosts(const string &);
void populateStringset(); /* throws runtime_error */
void blockDomain(string &); /* throws runtime_error */
bool appendFile(const string &); /* throws runtime_error */
inline bool renameFile(const string &, const string &) const;
bool removeDomain(string &, const bool &); /* throws runtime_error */
void printDomains() const;
bool backupHostsFile() const; /* throws runtime_error */
bool clearHosts(); /* rethrows runtime_error from removeDomain() */
bool overwriteHosts(const string &);
string getBackupFileName() const;
private:
void parseDomain(string &) const;
stringset hfContents;
const static string BACKUP_FILE;
const static string NON_ROUTABLE;
const static string UNIX_PATH;
const string SYS_PATH;
};
#endif