Skip to content
victor edited this page Aug 6, 2025 · 6 revisions

πŸ›οΈ Smart_Store API guide.

Smart_Store APIs are intuitive, powerful, and highly extensible. With just a single call to addItem(), you can store any object of arbitrary type, automatically registered and ready to use. Every item added inherits the full set of capabilities provided by the ItemManager interface, including tagging, querying, exporting, and state tracking. Whether you're working locally or leveraging global item access, Smart_Store APIs give you modular control and thread-safe operations right out of the box.
Below are practical examples to help you integrate and unleash the full potential of Smart_Store APIs:

Here's a factory-designed pattern managed by Smart_Store.


#include "t_manager/ItemManager.h"
#include "err_log/Logger.hpp"
#include <iostream>
#include <chrono>
#include <thread>
#include <unordered_map>
#include <functional>
#include <memory> 
using namespace std;


class Vehicle {
public:
    virtual void createVehicle() = 0;
};

class Jeep : public Vehicle {     // ----> Jeep class
public:
    void createVehicle() override {
        cout << ":::::::-> Jeep Produced." << endl;
    }
};

class Benz : public Vehicle {    // -----> Benz class
public:
    void createVehicle() override {
        cout << ":::::::-> Benz Produced." << endl;
    }
};

class RollsRoyce : public Vehicle {  // -----> RollsRoyce class
public:
    void createVehicle() override {
        cout << ":::::::-> Rolls-Royce Produced." << endl;
    }
};

class Ferrari : public Vehicle {    // ---> ferrari class
public:
    void createVehicle() override {
        cout << ":::::::-> Ferrari Produced." << endl;
    }
};


class Factory {
public:
    static unique_ptr<Vehicle> vehicleFactory(const string& productType) {
        static unordered_map<string, function<Vehicle* ()>> factoryMap = { // unordered map were new instance of different vehicles are returned as value
            {"benz", []() { return new Benz(); }},
            {"jeep", []() { return new Jeep(); }},
            {"ferrari", []() { return new Ferrari(); }},
            {"rollsroyce", []() { return new RollsRoyce(); }}
        };
        if (factoryMap.count(productType)) {
            return unique_ptr<Vehicle>(factoryMap[productType]());
        }
        return nullptr;
    }
};


void simulateCheck() {                   // This function delays the outputs on the client side.
    cout << "\n\n \t\t::: Checking ";
    for (int i = 0; i <= 4; ++i) {
        this_thread::sleep_for(chrono::milliseconds(500));
        cout << ".";
    }
    cout << endl;
}

class I_Client {
public:
  void garage() { // Here is the client class that displays the data.
      system("cls");
      cout << "\n\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl;
      cout << "*************** Vehicles available ***************\n\n";
      cout << "::: benz" << endl;
      cout << "::: jeep" << endl;
      cout << "::: ferrari" << endl;
      cout << "::: rollsroyce";
      cout << "\n\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl;
      cout << "Enter Product Type: ";
      string productType;
      cin >> productType;

      auto vehicle = Factory::vehicleFactory(productType);
      system("cls");

      simulateCheck(); 

      if (vehicle) {
          vehicle->createVehicle();
          this_thread::sleep_for(chrono::milliseconds(5000));
          garage();
      }
      else {
          cout << "\n\n \t\t::::::: No such product :::::::" << endl;
          this_thread::sleep_for(chrono::milliseconds(5000));
          garage();
      }
    }
};



int main() {
  ItemManager manager;
  auto Item1 = std::make_shared<I_Client>(); 
  manager.addItem(Item1, "car_factory");  // <- Item stored and automatically registered.
  auto item = manager.getItem<I_Client>("car_factory");
  item->garage();  // Start the client interaction

  return 0;
}

Here's another implementation containing other API features of ItemMangement:


πŸ›οΈ Smart_Store

::| Development Guide |::

If you encounter any issues and bugs, please reach out via email or GitHub issues.

Clone this wiki locally