Skip to content
Snippets Groups Projects
Commit b14af20f authored by Yannik Müller's avatar Yannik Müller
Browse files

Added clean handling of vector<bool> argument values

parent 20bc432f
No related branches found
No related tags found
1 merge request!57Implemented use_gpu_memory_on_task option
This commit is part of merge request !57. Comments created here will be created in the context of that merge request.
/****************************************************************************
** LinkTest **
*****************************************************************************
** Copyright (c) 2008-2022 **
** Forschungszentrum Juelich, Juelich Supercomputing Centre **
** **
** See the file COPYRIGHT in the package base directory for details **
****************************************************************************/
#include "argument_vector_bool.h"
#include <sstream>
#include <ios>
#include<algorithm>
std::vector<bool> Argument_Vector_Bool::getValue() const {
std::vector<bool> res;
copy(_value.begin(), _value.end(), back_inserter(res));
return res;
}
std::string Argument_Vector_Bool::getString() const {
std::stringstream ss;
ss << "[";
ss << std::boolalpha;
for(bool b: _value) {
ss << b << ",";
}
ss << "]";
return ss.str();
}
Argument_Vector_Bool::Argument_Vector_Bool (const std::string str){
if(str.front() != '[' || str.back() != ']') {
throw std::invalid_argument(str + " needs to be a list such as [] and [1,0,1,1]");
}
std::stringstream values(str.substr(1, str.size() -1));
std::string value;
while(std::getline(values, value, ','))
{
std::stringstream boolStr;
bool b;
boolStr << value;
boolStr >> b;
_value.push_back(b);
}
}
\ No newline at end of file
/****************************************************************************
** LinkTest **
*****************************************************************************
** Copyright (c) 2008-2022 **
** Forschungszentrum Juelich, Juelich Supercomputing Centre **
** **
** See the file COPYRIGHT in the package base directory for details **
****************************************************************************/
#ifndef LINKTEST_ARGUMENT_VECTOR_BOOL
#define LINKTEST_ARGUMENT_VECTOR_BOOL
#include <vector>
#include <string>
class Argument_Vector_Bool {
public:
std::vector<bool> getValue() const;
std::string getString() const;
Argument_Vector_Bool (const std::string str);
private:
std::vector<bool> _value;
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment