eive-obsw/bsp_q7s/memory/scratchApi.cpp

51 lines
1.4 KiB
C++
Raw Normal View History

2021-07-09 16:57:34 +02:00
#include "scratchApi.h"
ReturnValue_t scratch::writeString(std::string name, std::string string) {
2022-07-13 11:25:53 +02:00
std::ostringstream oss("xsc_scratch write ", std::ostringstream::ate);
oss << name << " \"" << string << "\"";
2022-01-17 15:58:27 +01:00
int result = std::system(oss.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "scratch::writeString");
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-01-17 15:58:27 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-07-16 22:20:53 +02:00
}
ReturnValue_t scratch::readString(std::string key, std::string &string) {
2022-01-17 15:58:27 +01:00
std::ifstream file;
std::string filename;
ReturnValue_t result = readToFile(key, file, filename);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
return result;
}
2021-07-16 22:20:53 +02:00
2022-01-17 15:58:27 +01:00
std::string line;
if (not std::getline(file, line)) {
std::remove(filename.c_str());
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-01-17 15:58:27 +01:00
}
2021-07-16 22:20:53 +02:00
2022-01-17 15:58:27 +01:00
size_t pos = line.find("=");
if (pos == std::string::npos) {
sif::warning << "scratch::readNumber: Output file format invalid, "
"no \"=\" found"
<< std::endl;
// Could not find value
std::remove(filename.c_str());
return KEY_NOT_FOUND;
}
string = line.substr(pos + 1);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-07-16 22:20:53 +02:00
}
ReturnValue_t scratch::clearValue(std::string key) {
2022-07-13 11:25:53 +02:00
std::ostringstream oss("xsc_scratch clear ", std::ostringstream::ate);
oss << key;
2022-01-17 15:58:27 +01:00
int result = std::system(oss.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "scratch::clearValue");
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-01-17 15:58:27 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-07-09 16:57:34 +02:00
}