From 2954367c629c56659bff1cef7a3ae7ade8ca1883 Mon Sep 17 00:00:00 2001 From: Stefan Brechtken Date: Wed, 19 Feb 2020 12:12:57 +0100 Subject: [PATCH] Temporary: adding Singleton pattern in order to bypass tesseract iterators and lists --- src/ccstruct/tabletransfer.hpp | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/ccstruct/tabletransfer.hpp diff --git a/src/ccstruct/tabletransfer.hpp b/src/ccstruct/tabletransfer.hpp new file mode 100644 index 000000000..d3ec6a4b3 --- /dev/null +++ b/src/ccstruct/tabletransfer.hpp @@ -0,0 +1,42 @@ +#pragma once +#include +#include +#include "rect.h" + + +/// Structure for data transfer from table detector +struct MyTable { + TBOX box; + std::vector rows; + std::vector cols; +}; + +/** \brief You can use this small template function to ensure that one and + * only one object of type T exists. It implements the Singleton Pattern. + * + * T must be default-constructable. + * Usage examples: + * A& a = uniqueInstance(); + * a.xyz(); + * uniqueInstance(make_unique(42)); // replace instance + * a.foo(); + * or + * uniqueInstance().xyz(); + */ +template +T& uniqueInstance(std::unique_ptr new_instance = nullptr) +{ + static std::unique_ptr _instance = std::make_unique(); + + if(new_instance) + _instance = std::move(new_instance); + + return *_instance.get(); +} + +/// return const version of \see uniqueInstance +template +const T& constUniqueInstance(std::unique_ptr new_instance = nullptr) +{ + return uniqueInstance(std::move(new_instance)); +}