-
Notifications
You must be signed in to change notification settings - Fork 1
/
fssettings.h
63 lines (53 loc) · 2.26 KB
/
fssettings.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef FSSETTINGS_H
#define FSSETTINGS_H
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <fstream>
using namespace std;
class FsSettingsValue
{ ///< A class for holding settings read from file
public:
FsSettingsValue(std::string line=""); // set from a string in the form (name:arg1 arg2 arg3), or create a black setting object
FsSettingsValue(std::vector<std::string> lineargs,bool throwerrors=false); // set from a vector in the form (name arg1 arg2...)
~FsSettingsValue();
void setFromCmdArgs(std::vector<std::string> lineargs,bool throwerrors);
void set(std::string line,bool throwerrors=false); // set the setting value
void set(std::string name, std::vector<std::string> lineargs,bool throwerrors=false);// set from a command line like string from a separated (name value) pair
void set(std::vector<std::string> lineargs,bool throwerrors=false);// set from a command line like string (name:val)
void setSection(std::string line);// assign it a section
void clear();// remove all data from the setting
std::string getName(); // return the name
std::string getSection(); // return the section
std::string getLine(); // return the original string
std::string getEndedLine(); // return the original string (with \n)
std::string getVal(); // return the value (as a string)
int getValAsInt(); // return the value
double getValAsDouble(); // return the value
std::vector<std::string> getValAsStringVec(char c=' '); // return the value
std::vector<int> getValAsIntVec();///< return the value
std::vector<double> getValAsDoubleVec();///< return the value
bool success; // whether it contains a read value
protected:
std::string section;
std::string name;
std::string val;
std::string line;
};
class FsSettingsReader
{
public:
FsSettingsReader(std::string f,bool verbose);///< Create from a file
~FsSettingsReader();///< Destructor
void openFile();/// < open the file
FsSettingsValue getNext();///< Gets the next settings value
protected:
bool verbose;///< Whether we output anything
string filename;///< The file name
std::ifstream fs;///< The stream from which we read the file
string line; //< previously read line
string section; //< the section we are currently in
};
#endif