ADD: added serialization and deserialization for the IdentifierClass
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "SimCore/SimCore.hpp"
|
||||
#include <SimCore/SimCore.hpp>
|
||||
#include <SimCore/UtilFunctions.hpp>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <loguru.hpp>
|
||||
@@ -12,6 +13,7 @@ namespace SimCore {
|
||||
Identifier() = default;
|
||||
Identifier(int number,SimCore::ObjectSource ObjectSource) ;
|
||||
Identifier(std::pair<int, SimCore::ObjectSource> id);
|
||||
Identifier(std::string str);
|
||||
|
||||
|
||||
int getNumber();
|
||||
@@ -21,6 +23,8 @@ namespace SimCore {
|
||||
|
||||
std::pair<int, SimCore::ObjectSource> getPair();
|
||||
|
||||
std::string serialize();
|
||||
|
||||
friend bool operator==(const Identifier &lhs,const Identifier &rhs);
|
||||
|
||||
private:
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace SimCore {
|
||||
public:
|
||||
static std::vector<std::string> explode(std::string const & s, char delim);
|
||||
|
||||
static bool isNumber(const std::string& s);
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Submodule libs/whisper-com updated: 01e4f666c2...6b8d6ad265
@@ -1,8 +1,10 @@
|
||||
#include "SimCore/SimCore.hpp"
|
||||
#include <SimCore/Identifier.hpp>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#define StringDelimiter ';'
|
||||
|
||||
namespace SimCore {
|
||||
|
||||
@@ -15,6 +17,25 @@ Identifier::Identifier(std::pair<int, SimCore::ObjectSource> id):number_(id.firs
|
||||
{
|
||||
|
||||
}
|
||||
Identifier::Identifier(std::string str)
|
||||
{
|
||||
std::vector<std::string> var = UtilFunctions::explode(str,StringDelimiter);
|
||||
if (UtilFunctions::isNumber(var[0])) {
|
||||
number_ = stoi(var[0]);
|
||||
|
||||
}
|
||||
if (UtilFunctions::isNumber(var[1])) {
|
||||
objectSource_ = (SimCore::ObjectSource)stoi(var[1]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
std::string Identifier::serialize()
|
||||
{
|
||||
return std::to_string(number_) + StringDelimiter + std::to_string(objectSource_);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int Identifier::getNumber()
|
||||
{
|
||||
|
||||
@@ -16,4 +16,11 @@ namespace SimCore {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool UtilFunctions::isNumber(const std::string& s)
|
||||
{
|
||||
return !s.empty() && std::find_if(s.begin(),
|
||||
s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,9 @@ SCENARIO("Testing the SimCorePositionClass")
|
||||
|
||||
WHEN("constructing Position Object with data")
|
||||
{
|
||||
|
||||
std::string serID = ID1.serialize();
|
||||
SimCore::Identifier ID5(serID);
|
||||
|
||||
THEN("positions attributes are correct")
|
||||
{
|
||||
@@ -30,6 +33,8 @@ SCENARIO("Testing the SimCorePositionClass")
|
||||
REQUIRE(ID1 == ID2);
|
||||
REQUIRE(ID1 != ID3);
|
||||
REQUIRE(ID4 != ID3);
|
||||
|
||||
REQUIRE(ID5 == ID1);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user