gtheler преди 5 години
родител
ревизия
a4e65cec5c
променени са 3 файла, в които са добавени 42 реда и са изтрити 11 реда
  1. +11
    -5
      TODO
  2. +20
    -4
      src/conf.cpp
  3. +11
    -2
      src/conf.h

+ 11
- 5
TODO Целия файл

@@ -1,13 +1,19 @@
* version and copyright
* messages implemented on the player's side
* configuration files as map of strings to strings https://www.walletfox.com/course/parseconfigfile.php
* arranged shoes
* multithreading
* deterministic seeds
* ENHC
* blackjack switch
* siete y medio
* name of the game the dealer deals
* name of the games the player can play
* delays?
* dealers
* ENHC
* blackjack switch
* blackjack under?
* siete y medio
*

* multithreading
* use of const and restrict
* runtime-linked players in shared objects

+ 20
- 4
src/conf.cpp Целия файл

@@ -7,10 +7,20 @@

// source https://www.walletfox.com/course/parseconfigfile.php

Configuration::Configuration(std::string filePath, bool mandatory) {
Configuration::Configuration(int argc, char **argv) {
int i, optc;
int option_index = 0;
// TODO: if blackjack.conf exists parse it
parseConfigFile();
}

int Configuration::parseConfigFile(std::string filePath) {
// std::ifstream is RAII, i.e. no need to call close
std::ifstream fileStream((filePath != "") ? filePath : "./blackjack.conf");
std::ifstream fileStream(filePath);
std::size_t delimiterPos;
std::string name;
@@ -24,17 +34,23 @@ Configuration::Configuration(std::string filePath, bool mandatory) {
continue;
}
// TODO: comments on the same line
delimiterPos = line.find("=");
if (delimiterPos != std::string::npos) {
name = line.substr(0, delimiterPos);
value = line.substr(delimiterPos + 1);
data[name] = value;
// TODO: add another map of string to bools to mark wheter the option was used or not
} else {
// TODO: warning?
}
}
} else {
std::cerr << "Couldn't open config file for reading.\n";
return -1;
}
return 0;
}

void Configuration::show(void) {
@@ -52,4 +68,4 @@ int Configuration::getInt(std::string key) {

Configuration::~Configuration() {
data.clear();
}
}

+ 11
- 2
src/conf.h Целия файл

@@ -27,10 +27,13 @@

class Configuration {
public:
Configuration(std::string = "", bool = false);
Configuration(int, char **);
~Configuration();

int readConfigFile(std::string);
bool exists(std::string key) { return !(data.find(key) == data.end()); }

void show(void);
bool getBool(std::string);
@@ -39,5 +42,11 @@ class Configuration {
private:
std::map<std::string, std::string> data;
bool show_help = false;
bool show_version = false;
bool show_bar = false;
bool bar_already_alloced = false;
unsigned int hands_per_char = false;
};
#endif
#endif

Loading…
Отказ
Запис