Skip to content
Snippets Groups Projects
Commit a9589259 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix static init bug in factories

parent 9bc447ac
No related branches found
No related tags found
No related merge requests found
Pipeline #10796 passed
......@@ -66,6 +66,8 @@ class RGBDSource : public ftl::Configurable {
* used as the instance name to construct.
*/
static RGBDSource *create(nlohmann::json &config, ftl::net::Universe *net);
static void init();
protected:
static void _register(const std::string &n, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)> f);
......@@ -78,7 +80,7 @@ class RGBDSource : public ftl::Configurable {
Eigen::Matrix4f pose_;
private:
static std::map<std::string,std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>> sources__;
static std::map<std::string,std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>> *sources__;
};
};
......
......@@ -9,7 +9,7 @@
using ftl::Disparity;
std::map<std::string, std::function<Disparity*(nlohmann::json&)>>
Disparity::algorithms__;
*Disparity::algorithms__ = nullptr;
Disparity::Disparity(nlohmann::json &config)
: config_(config),
......@@ -17,14 +17,15 @@ Disparity::Disparity(nlohmann::json &config)
max_disp_(config["maximum"]) {}
Disparity *Disparity::create(nlohmann::json &config) {
if (algorithms__.count(config["algorithm"]) != 1) return nullptr;
return algorithms__[config["algorithm"]](config);
if (algorithms__->count(config["algorithm"]) != 1) return nullptr;
return (*algorithms__)[config["algorithm"]](config);
}
void Disparity::_register(const std::string &n,
std::function<Disparity*(nlohmann::json&)> f) {
if (!algorithms__) algorithms__ = new std::map<std::string, std::function<Disparity*(nlohmann::json&)>>;
LOG(INFO) << "Register disparity algorithm: " << n;
algorithms__[n] = f;
(*algorithms__)[n] = f;
}
// TODO(Nick) Add remaining algorithms
......
......@@ -54,7 +54,7 @@ class Disparity {
size_t max_disp_;
private:
static std::map<std::string,std::function<Disparity*(nlohmann::json&)>> algorithms__;
static std::map<std::string,std::function<Disparity*(nlohmann::json&)>> *algorithms__;
};
};
......
......@@ -3,8 +3,7 @@
using ftl::rgbd::RGBDSource;
using ftl::Configurable;
std::map<std::string, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>>
RGBDSource::sources__;
std::map<std::string, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>> *RGBDSource::sources__ = nullptr;
RGBDSource::RGBDSource(nlohmann::json &config) : Configurable(config), net_(nullptr) {
......@@ -36,14 +35,15 @@ bool RGBDSource::snapshot(const std::string &fileprefix) {
RGBDSource *RGBDSource::create(nlohmann::json &config, ftl::net::Universe *net) {
if (config["type"].type_name() != "string") return nullptr;
if (sources__.count(config["type"]) != 1) return nullptr;
return sources__[config["type"]](config, net);
if (sources__->count(config["type"]) != 1) return nullptr;
return (*sources__)[config["type"]](config, net);
}
void RGBDSource::_register(const std::string &n,
std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)> f) {
if (!sources__) sources__ = new std::map<std::string, std::function<RGBDSource*(nlohmann::json&,ftl::net::Universe*)>>;
LOG(INFO) << "Register RGB-D Source: " << n;
sources__[n] = f;
(*sources__)[n] = f;
}
#include <ftl/net_source.hpp>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment