Commit 612f663a authored by garciay's avatar garciay
Browse files

GeoNetworking codecs & Layers ongoing

parent 0e66cc91
......@@ -4,7 +4,8 @@
#include <map>
#include <vector>
typedef std::map<std::string, std::string> Params;
#include "Params.hh"
class OCTETSTRING;
class Layer {
......@@ -53,7 +54,7 @@ template <typename TPort> class TLayer : public Layer {
class LayerFactory {
public:
LayerFactory(){}
virtual Layer * createLayer(const std::string & type, const std::string & param) = 0;
virtual Layer * createLayer(const std::string & type, const std::string & param) = 0;
};
class LayerStackBuilder {
......
#pragma once
#include <map>
//typedef std::map<std::string, std::string> Params;
class Params : public std::map<std::string, std::string> {
public:
Params() : std::map<std::string, std::string>() {};
virtual ~Params() {};
void log();
static void convert(Params& p_param, const std::string p_parameters);
};
#pragma once
#include <map>
typedef std::map<std::string, std::string> params;
......@@ -57,7 +57,7 @@ Layer* LayerStackBuilder::createLayerStack(const char* s)
l->addUpperLayer(up);
up = l;
}
} // End of 'for' statement
}
catch(const std::logic_error& e){
if(up){
......
#include <stdexcept>
#include <regex>
#include "Params.hh"
#include "loggers.hh"
void Params::convert(Params& p_param, const std::string p_parameters) {
loggers::loggers::log(">>> Params::convert: '%s'", p_parameters.c_str());
// Sanity checks
if (p_parameters.length() == 0) {
return;
}
// Extract parameters
try {
std::regex rgx ("((\\.*)\\s*=\\s*(\\.*))(,((\\.*)\\s*=\\s*(\\.*)))*");
std::sregex_iterator begin(p_parameters.cbegin(), p_parameters.cend(), rgx);
std::sregex_iterator end = std::sregex_iterator();
for (std::sregex_iterator it = begin; it != end; ++it) {
std::smatch m = *it;
loggers::loggers::log("Params::convert: %d - %s - %s - %s - %s - %s", m.size(), m[0].str().c_str(), m[1].str().c_str(), m[2].str().c_str(), m[3].str().c_str(), m[4].str().c_str());
p_param.insert(std::pair<std::string, std::string>(m[1].str(), m[2].str()));
} // End of 'for' statement
}
catch(const std::logic_error& e){
p_param.clear();
}
}
void Params::log() {
loggers::loggers::log("Params::log");
for (const_iterator it = cbegin(); it != cend(); ++it) {
loggers::loggers::log("\t(%s, %s)", it->first.c_str(), it->second.c_str());
} // End of 'for' statement
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment