Newer
Older
#include "Layer.hh"
LayerStackBuilder * LayerStackBuilder::_instance = NULL;
// static functions
LayerStackBuilder * LayerStackBuilder::GetInstance()
{
return _instance ? _instance : _instance = new LayerStackBuilder();
void LayerStackBuilder::RegisterLayerFactory(const std::string & type, LayerFactory * f)
{
LayerStackBuilder::GetInstance()->registerLayerFactory(type, f);
}
// member functions
LayerStackBuilder::LayerStackBuilder()
{
void LayerStackBuilder::registerLayerFactory(const std::string & type, LayerFactory * f)
Layer* LayerStackBuilder::createLayerStack(const char* s)
loggers::loggers::log(">>> LayerStackBuilder::createLayerStack: %s", s);
Layer * up = NULL;
// Parse str
try {
std::regex rgx ("(\\w+)(\\((.*?)\\))?(\\/|$)");
std::string str = s;
std::sregex_iterator begin(str.cbegin(), str.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("LayerStackBuilder::createLayerStack: %d - %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());
LayerFactoryMap::iterator i =_fs.find(m[1].str());
if (i == _fs.end()) {
loggers::loggers::error("LayerStackBuilder::createLayerStack: %s: Unknown layer type", m[1].str().c_str());
}
loggers::loggers::log("LayerStackBuilder::createLayerStack: Create layer %s, %s", m[1].str().c_str(), m[3].str().c_str());
Layer * l = i->second->createLayer(m[1].str(), m[3].str());
if (NULL == l) {
loggers::loggers::error("LayerStackBuilder::createLayerStack: %s: Layer creation error", m[1].str().c_str());
}
loggers::loggers::log("LayerStackBuilder::createLayerStack: Setup layers for %s", l->to_string().c_str());
l->addUpperLayer(up);
up = l;
} // End of 'for' statement
}
catch(const std::logic_error& e){
if(up){
up->deleteLayer();
up = NULL;