btcollider/bfclient/src/comm/Work.cpp
armin f6ed227073 Success/Failure for work packages
Repeat working, send succ/fail msg for work package, added succ/fail
facility
2018-04-25 23:37:19 +02:00

56 lines
1.1 KiB
C++

/*
* Work.cpp
*
* Created on: Apr 12, 2018
* Author: armin
*/
#include <Work.h>
#include <stddef.h>
#include <cassert>
#include <cstdlib>
#include <sstream>
namespace comm {
using namespace std;
Work::Work() : total(0) {}
Work::Work(string work_s) {
vector<string> wrk_v = split(work_s, " ");
assert(wrk_v.size() == 3);
from = wrk_v.at(0);
to = wrk_v.at(1);
total = strtol(wrk_v.at(2).c_str(), nullptr, 10);
}
bool Work::isEmpty() { return (total <= 0); }
vector<string> Work::split(const string s, const string delimiter) {
vector<string> split_str;
size_t start_pos = 0;
size_t end_pos = 0;
while ((end_pos = s.find(delimiter, start_pos)) != string::npos) {
split_str.push_back(s.substr(start_pos, end_pos - start_pos));
start_pos = end_pos + delimiter.size();
}
split_str.push_back(s.substr(start_pos, string::npos));
return (split_str);
}
string Work::repr(void) {
ostringstream buffer;
buffer << "<" << from << " " << to << " " << total << ">";
return (buffer.str());
}
Work::~Work() {
// TODO Auto-generated destructor stub
}
} // namespace comm