replace tuple-based singleton with individual singletons
The tuple-based singletons did not actually enforce singleton behavior
and the requirement of the accessor mechanism to include all of the
member types at once was starting to cause a header prerequisite
tangle. This removes the cross-dependencies and enforces actual
singletons by making a single way to access the class.
Tested: Run ipmitool to show that behavior has not changed
Change-Id: Ie966e1142363d279365b1095066380c8383e9f9b
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/command_table.hpp b/command_table.hpp
index e882300..172c015 100644
--- a/command_table.hpp
+++ b/command_table.hpp
@@ -216,8 +216,16 @@
*/
class Table
{
+ private:
+ struct Private
+ {
+ };
+
public:
- Table() = default;
+ explicit Table(const Private&)
+ {
+ }
+ Table() = delete;
~Table() = default;
// Command Table is a singleton so copy, copy-assignment, move and
// move assignment is deleted
@@ -226,6 +234,21 @@
Table(Table&&) = default;
Table& operator=(Table&&) = default;
+ /**
+ * @brief Get a reference to the singleton Table
+ *
+ * @return Table reference
+ */
+ static Table& get()
+ {
+ static std::shared_ptr<Table> ptr = nullptr;
+ if (!ptr)
+ {
+ ptr = std::make_shared<Table>(Private());
+ }
+ return *ptr;
+ }
+
using CommandTable = std::map<uint32_t, std::unique_ptr<Entry>>;
/**