// deployer Services implementation // Copyright (C) 2024 Jean-Cloud // GNU General Public License v3 #include #include #include #include #include #include "Services.h" Services::Services(const char *ServicesCSV) { services=readServicesFromCSV(ServicesCSV); } Services::~Services(){} vector Services::readServicesFromCSV (const char *CSV) const { //this method extracts the list of uid|username|servers from the services.csv file //and returns them in a vector , with serviceData a structure defined in the header vector result; ifstream streamServices(CSV); if (!streamServices){ cout << "Invalid services.csv file." << endl; }else{ string line; int userID; string tmpUserID; string username; string serveur; list serveurs; while(getline(streamServices,line)){ if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account continue; } stringstream streamLine(line); getline(streamLine,tmpUserID,';'); //extracting the userID userID=stoi(tmpUserID); getline(streamLine,username,';'); //extracting the username while(getline(streamLine,serveur,';')){ //extracting the server(s) serveurs.push_back(serveur); } serviceData entry = {userID,username,serveurs}; result.push_back(entry); } } return result; }