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

83 lines
1.6 KiB

2 years ago
#ifndef _CFG_
#define _CFG_
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <string>
using namespace std;
1 year ago
namespace marcelb {
/**
* Clears white fields from a string
*/
static void clearWhiteSpaces(string &a);
/**
* Removes comments from a string
* Returns false if the entire line is a comment,
* false if it is not
*/
static bool clearComments(string &a);
/**
* It parses the line of the configuration file,
* receives the string line and returns the key,
* value pair via reference
*/
static void parseConfigLine(const string a, string &b, string &c);
2 years ago
/**
* Configuration class - at the level of a single file
*/
2 years ago
class config {
const string configFilePath;
vector<string> necessary;
2 years ago
map<string, string> element;
/**
* Internal method to check if necessary keys exist
*/
bool isHaveNecessary();
/**
* Internal method for initialization
*/
bool init(const string _configFilePath);
/**
* Update config file
*/
void update_file(const string& key);
2 years 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);
/**
* Update config entry
*/
void update(const string& key, const string& value);
/**
* Method to print all configuration key value pairs
*/
2 years ago
void print();
};
1 year ago
}
2 years ago
#endif