Browse Source

tmp commit

master
gtheler 5 years ago
parent
commit
a4e65cec5c
3 changed files with 42 additions and 11 deletions
  1. +11
    -5
      TODO
  2. +20
    -4
      src/conf.cpp
  3. +11
    -2
      src/conf.h

+ 11
- 5
TODO View File

* version and copyright * version and copyright
* messages implemented on the player's side * messages implemented on the player's side
* configuration files as map of strings to strings https://www.walletfox.com/course/parseconfigfile.php
* arranged shoes * arranged shoes
* multithreading
* deterministic seeds * deterministic seeds
* ENHC
* blackjack switch
* siete y medio
* name of the game the dealer deals * name of the game the dealer deals
* name of the games the player can play * name of the games the player can play
* delays? * 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 View File



// source https://www.walletfox.com/course/parseconfigfile.php // 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 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::size_t delimiterPos;
std::string name; std::string name;
continue; continue;
} }
// TODO: comments on the same line
delimiterPos = line.find("="); delimiterPos = line.find("=");
if (delimiterPos != std::string::npos) { if (delimiterPos != std::string::npos) {
name = line.substr(0, delimiterPos); name = line.substr(0, delimiterPos);
value = line.substr(delimiterPos + 1); value = line.substr(delimiterPos + 1);
data[name] = value; data[name] = value;
// TODO: add another map of string to bools to mark wheter the option was used or not // TODO: add another map of string to bools to mark wheter the option was used or not
} else {
// TODO: warning?
} }
} }
} else { } else {
std::cerr << "Couldn't open config file for reading.\n";
return -1;
} }
return 0;
} }


void Configuration::show(void) { void Configuration::show(void) {


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

+ 11
- 2
src/conf.h View File



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


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


void show(void); void show(void);
bool getBool(std::string); bool getBool(std::string);
private: private:
std::map<std::string, std::string> data; 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…
Cancel
Save