Browse Source

Added a toVector function to ConfigStore to allow pulling out vector of strings from delimited strings. Used in the dependancy resolution code coming up next.

master
DomtronVox 1 year ago
parent
commit
6b38bd30d8
2 changed files with 24 additions and 4 deletions
  1. +20
    -2
      src/Configuration/ConfigStore.cpp
  2. +4
    -2
      src/Configuration/ConfigStore.h

+ 20
- 2
src/Configuration/ConfigStore.cpp View File

@ -4,10 +4,12 @@
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
//convert string to double
// @return bool indicating success
bool toDecimal(std::string value, double& float_var) {
bool toDecimal(const std::string value, double& float_var) {
std::istringstream stream(value);
stream >> std::noskipws >> float_var; // noskipws considers leading whitespace invalid
@ -17,7 +19,7 @@ bool toDecimal(std::string value, double& float_var) {
//convert string to integer
// @return bool indicating success
bool toInt(std::string value, int& int_var) {
bool toInt(const std::string value, int& int_var) {
std::istringstream stream(value);
stream >> std::noskipws >> int_var; // noskipws considers leading whitespace invalid
@ -44,4 +46,20 @@ bool toBool(std::string value, bool& bool_var) {
}
//convert string to vector
// @return bool indicating success
bool toVector(const std::string value, std::vector< std::string >& vec_var, char delimiter) {
std::istringstream stream(value);
std::string item;
while (std::getline(stream, item, delimiter)) {
vec_var.push_back(item);
}
//if all those fail then the value isn't a boolean so successes fails
return false;
}

+ 4
- 2
src/Configuration/ConfigStore.h View File

@ -6,11 +6,13 @@
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
//functions to test string values for different basic types
bool toDecimal(std::string value, double& float_var);
bool toInt(std::string value, int& int_var);
bool toDecimal(const std::string value, double& float_var);
bool toInt(const std::string value, int& int_var);
bool toBool(std::string value, bool& bool_var);
bool toVector(const std::string value, std::vector< std::string >& vec_var, char delimiter);
class ConfigStore {


Loading…
Cancel
Save