Skip to content

Commit

Permalink
deserializeValue: try to fix IPLPoint/IPLColor loading (always reset …
Browse files Browse the repository at this point in the history
…to 0) using some C++11
  • Loading branch information
Raphaël Droz committed Jul 9, 2018
1 parent 29b0560 commit a6de2bc
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions IPL/src/IPLProcessProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,45 +183,27 @@ inline void deserializeValue(const std::string &data, std::vector<double> &value

inline void deserializeValue(const std::string &data, IPLColor &value)
{
std::array<float,3> color;

int i = 0;
std::smatch match;
auto pos = data.begin();
while(i < (int) color.size() && std::regex_search(pos,data.end(),match,std::regex("[-0-9.]")))
{
pos += match.position();

int charsParsed = 0;
float element = 0;
if (sscanf(&(*pos),"%f%n",&element,&charsParsed) > 0)
color[i++] = element;

pos += charsParsed;
std::regex e ("\\[([-0-9.eE]+),([-0-9.eE]+),([-0-9.eE]+)\\]");
if (!std::regex_search(data, match, e) || match.size() - 1 != 3) {
value = IPLColor(0, 0, 0);
return;
}
value = IPLColor(color[0], color[1], color[2]);
value = IPLColor(std::stof(match.str(1)),
std::stof(match.str(2)),
std::stof(match.str(3)));
}

inline void deserializeValue(const std::string &data, IPLPoint &value)
{
std::array<double,2> point;

int i = 0;
std::smatch match;
auto pos = data.begin();
while(i < (int) point.size() && std::regex_search(pos,data.end(),match,std::regex("[-0-9.]")))
{
pos += match.position();

int charsParsed = 0;
float element = 0;
if (sscanf(&(*pos),"%f%n",&element,&charsParsed) > 0)
point[i++] = element;

pos += charsParsed;
std::regex e ("\\[([-0-9.eE]+),([-0-9.eE]+)\\]");
if (!std::regex_search(data, match, e) || match.size() - 1 != 2) {
value = IPLPoint(0, 0, 0);
return;
}

value = IPLPoint(point[0], point[1]);
value = IPLPoint(std::stod(match.str(1)),
std::stod(match.str(2)));
}

inline void deserializeValue(const std::string &data, std::string &value)
Expand Down

0 comments on commit a6de2bc

Please sign in to comment.