Add namespace

dev v0.4
marcelb 11 months ago
parent 17daa1f03a
commit 057ebe3eba
  1. 3
      .vscode/settings.json
  2. 23
      README.md
  3. 3
      lib/config.hpp
  4. 16
      src/config.cpp
  5. 1
      test/test.cpp
  6. BIN
      test/test.o

@ -3,6 +3,7 @@
"*.tcc": "cpp",
"compare": "cpp",
"type_traits": "cpp",
"iostream": "cpp"
"iostream": "cpp",
"iosfwd": "cpp"
}
}

@ -18,25 +18,24 @@ Easily load variable configuration parameters into your program using this libra
Just download the latest release and unzip it into your project. You can turn it on with:
```
#include config/lib/config.hpp
```c++
#include "config/lib/config.hpp"
using namespace marcelb;
```
## Usage
```c++
#include <iostream>
#include "../lib/config.hpp"
using namespace std;
int main() {
/**
* Initialization and declaration
*/
config mycfg ("../example/config.cfg", {"Username", "API", "Domain" });
/**
* Accessing values using the key name and the [] operator
*/
cout << mycfg["consolePrintLogs"];
return 0;
}
```
### Configuration file example
@ -56,7 +55,7 @@ consolePrintLogs=true;
## Support & Feedback
For support and any feedback, contact the address: marcelb96@yahoo.com.
For support and any feedback, contact the address: marcelb96@yahoo.com
## Contributing

@ -9,6 +9,8 @@
using namespace std;
namespace marcelb {
/**
* Clears white fields from a string
*/
@ -65,5 +67,6 @@ class config {
};
}
#endif

@ -1,7 +1,7 @@
#include "../lib/config.hpp"
config::config(const string _configFilePath, const vector<string> _necessary) {
marcelb::config::config(const string _configFilePath, const vector<string> _necessary) {
necessary = _necessary;
if(!init(_configFilePath)) {
throw string("[ERROR] Init config file ");
@ -12,12 +12,12 @@ config::config(const string _configFilePath, const vector<string> _necessary) {
}
string config::operator[](const string& key) {
string marcelb::config::operator[](const string& key) {
return element[key];
}
bool config::init(const string _configFilePath) {
bool marcelb::config::init(const string _configFilePath) {
ifstream configFile;
configFile.open(_configFilePath, ios::in);
@ -42,7 +42,7 @@ bool config::init(const string _configFilePath) {
}
void config::print() {
void marcelb::config::print() {
for(auto i : element) {
cout << i.first << " " << i.second << "\n";
}
@ -50,7 +50,7 @@ void config::print() {
}
bool config::isHaveNecessary() {
bool marcelb::config::isHaveNecessary() {
bool necessaryHave = true;
for (int i=0; i<necessary.size(); i++) {
if (element[necessary[i]].empty()) {
@ -63,7 +63,7 @@ bool config::isHaveNecessary() {
}
void clearWhiteSpaces(string &a) {
void marcelb::clearWhiteSpaces(string &a) {
const char whitespaces[] = {' ', '\t'};
for (int i=0; i<sizeof(whitespaces)/sizeof(const char); i++) {
for (int j=0; j<a.length(); j++) {
@ -75,7 +75,7 @@ void clearWhiteSpaces(string &a) {
}
bool clearComments(string &a) {
bool marcelb::clearComments(string &a) {
bool r = a[0] != '#';
size_t commentLocation = a.find('#');
if(commentLocation <= a.length()) {
@ -85,7 +85,7 @@ bool clearComments(string &a) {
}
void parseConfigLine(const string a, string &b, string &c) {
void marcelb::parseConfigLine(const string a, string &b, string &c) {
size_t separatorLocation = a.find('=');
b = a.substr(0, separatorLocation);

@ -2,6 +2,7 @@
#include "../lib/config.hpp"
using namespace std;
using namespace marcelb;
int main() {

Binary file not shown.
Loading…
Cancel
Save