Library for parsing configuration files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
config/lib/config.hpp

72 lines
1.4 KiB

1 year ago
#ifndef _CFG_
#define _CFG_
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <string>
using namespace std;
9 months ago
namespace marcelb {
/**
* Clears white fields from a string
*/
1 year ago
void clearWhiteSpaces(string &a);
/**
* Removes comments from a string
* Returns false if the entire line is a comment,
* false if it is not
*/
1 year ago
bool clearComments(string &a);
/**
* It parses the line of the configuration file,
* receives the string line and returns the key,
* value pair via reference
*/
1 year ago
void parseConfigLine(const string a, string &b, string &c);
/**
* Configuration class - at the level of a single file
*/
1 year ago
class config {
vector<string> necessary;
1 year ago
map<string, string> element;
/**
* Internal method to check if necessary keys exist
*/
bool isHaveNecessary();
/**
* Internal method for initialization
*/
bool init(const string _configFilePath);
1 year ago
public:
/**
* Constructor, receives a string of configuration file paths
* and a vector of strings with necessary keys (optional)
*/
config(const string _configFilePath, const vector<string> _necessary = {});
/**
* Operator [] to access individual configuration parameter via key
*/
string operator[] (const string& key);
/**
* Method to print all configuration key value pairs
*/
1 year ago
void print();
};
9 months ago
}
1 year ago
#endif