ADD: added serialization and deserialization for the IdentifierClass
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
#include "SimCore/SimCore.hpp"
|
#include <SimCore/SimCore.hpp>
|
||||||
|
#include <SimCore/UtilFunctions.hpp>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
@@ -12,6 +13,7 @@ namespace SimCore {
|
|||||||
Identifier() = default;
|
Identifier() = default;
|
||||||
Identifier(int number,SimCore::ObjectSource ObjectSource) ;
|
Identifier(int number,SimCore::ObjectSource ObjectSource) ;
|
||||||
Identifier(std::pair<int, SimCore::ObjectSource> id);
|
Identifier(std::pair<int, SimCore::ObjectSource> id);
|
||||||
|
Identifier(std::string str);
|
||||||
|
|
||||||
|
|
||||||
int getNumber();
|
int getNumber();
|
||||||
@@ -21,6 +23,8 @@ namespace SimCore {
|
|||||||
|
|
||||||
std::pair<int, SimCore::ObjectSource> getPair();
|
std::pair<int, SimCore::ObjectSource> getPair();
|
||||||
|
|
||||||
|
std::string serialize();
|
||||||
|
|
||||||
friend bool operator==(const Identifier &lhs,const Identifier &rhs);
|
friend bool operator==(const Identifier &lhs,const Identifier &rhs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ namespace SimCore {
|
|||||||
public:
|
public:
|
||||||
static std::vector<std::string> explode(std::string const & s, char delim);
|
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/SimCore.hpp"
|
||||||
#include <SimCore/Identifier.hpp>
|
#include <SimCore/Identifier.hpp>
|
||||||
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define StringDelimiter ';'
|
||||||
|
|
||||||
namespace SimCore {
|
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()
|
int Identifier::getNumber()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,4 +16,11 @@ namespace SimCore {
|
|||||||
return result;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,9 @@ SCENARIO("Testing the SimCorePositionClass")
|
|||||||
WHEN("constructing Position Object with data")
|
WHEN("constructing Position Object with data")
|
||||||
{
|
{
|
||||||
|
|
||||||
|
std::string serID = ID1.serialize();
|
||||||
|
SimCore::Identifier ID5(serID);
|
||||||
|
|
||||||
THEN("positions attributes are correct")
|
THEN("positions attributes are correct")
|
||||||
{
|
{
|
||||||
REQUIRE(ID1.getNumber() == 100);
|
REQUIRE(ID1.getNumber() == 100);
|
||||||
@@ -31,6 +34,8 @@ SCENARIO("Testing the SimCorePositionClass")
|
|||||||
REQUIRE(ID1 != ID3);
|
REQUIRE(ID1 != ID3);
|
||||||
REQUIRE(ID4 != ID3);
|
REQUIRE(ID4 != ID3);
|
||||||
|
|
||||||
|
REQUIRE(ID5 == ID1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user