DEV Community

Cover image for Smart_Store: A Modern C++ API for Scalable Inventory and Object Management
Emmanuel Victor
Emmanuel Victor

Posted on

Smart_Store: A Modern C++ API for Scalable Inventory and Object Management

In today’s software landscape, modularity, performance, and clarity are non-negotiable. That’s why I built Smart_Store, a high-performance, thread-safe inventory manager powered by modern C++ and designed to handle dynamic object lifecycles with elegance.

Whether you're managing vehicles, people, or abstract entities, Smart_Store gives you intuitive APIs and clean architecture to build scalable systems with minimal friction.

Why Smart_Store?

Smart_Store APIs are designed to be:

  • Intuitive: Add and retrieve items with minimal boilerplate.
  • Extensible: Store any object of arbitrary type.
  • Powerful: Every item inherits full capabilities from the ItemManager interface — tagging, querying, exporting, and state tracking.
  • Thread-safe: Built for concurrent environments without sacrificing performance.

With just a single call to "addItem()", your object is registered automatically and ready to use; no manual bookkeeping, no fragile pointers.

To walk through the integration steps on a new tab: Smart_Store Integration

Example 1: Vehicle Factory System
This example demonstrates how Smart_Store integrates with a factory pattern to dynamically produce and manage vehicle types.

#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;

// Vehicle Hierarchy
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;
    }
};

//  Factory Logic
class Factory {
public:
    static unique_ptr<Vehicle> vehicleFactory(const string& productType) {
       static unordered_map<string, function<Vehicle* ()>> factoryMap = { 
/* 
  unordered map where a new instance of different vehicles is 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;
    }
};

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

//Interface for car manufacturing.
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();
      }
    }
};


//  Smart_Store Integration
int main() {
  ItemManager manager;

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

  return 0;
}
Enter fullscreen mode Exit fullscreen mode

This setup allows users to interactively select and produce vehicles, with Smart_Store managing the lifecycle and access.

Here is the outcome: The output

Example 2: Human Interaction System
This second example showcases Smart_Store’s advanced features like modification, undo/redo, and dynamic interaction.

#include "t_manager/ItemManager.h"
#include "err_log/Logger.hpp"
#include <iostream>
#include <string>

using namespace std;

// HumanBeing Interface
class HumanBeing {
public:
    virtual void speak() const = 0;
    virtual void walk() const = 0;
    virtual void eat() const = 0;
    virtual ~HumanBeing() = default;
};

// Example derived class 
class Boy : public HumanBeing {
public:
    std::string name;
    int age;

public:
    /*
     If you have a constructor that takes parameters, make sure to define 
     the default constructor as well to avoid issues.
    */ 

    Boy(std::string name, int age): name(name), age(age) {}
    Boy() {}
    ~Boy() {}

    void speak() const override {
         LOG_CONTEXT(LogLevel::DISPLAY, "Hello, I am a boy named: " + name
                +  " I am " + to_string(age) + " years old.", {});
    }

    void walk() const override {
        LOG_CONTEXT(LogLevel::DISPLAY, "I am walking like a boy named "   
                       + name+ ".", {});
    }

    void eat() const override {
        LOG_CONTEXT(LogLevel::DISPLAY, "I am eating like a boy named " 
                   + name + ".", {});
    }
};

// Example of a girl
class Girl : public HumanBeing {
public:
    std::string name;
    int age;

public:
    /*
     If you have a constructor that takes parameters, make sure to define
     the default constructor as well to avoid issues.
    */ 

    Girl(std::string name, int age): name(name), age(age) {}
    Girl() {}
    ~Girl() {}

    void speak() const override {
        LOG_CONTEXT(LogLevel::DISPLAY, "Hello, I am a girl named: " + name 
               +  " I am " + to_string(age) + " years old.", {});
    }

    void walk() const override {
        LOG_CONTEXT(LogLevel::DISPLAY, "I am walking like a girl named "
                       + name + ".", {});
    }

    void eat() const override {
        LOG_CONTEXT(LogLevel::DISPLAY, "I am eating like a girl named " 
                       + name + ".", {});
    }
};

int main() {
    ItemManager manager;

    // Add items using constructor
    auto Item1 = std::make_shared<Boy>("Tom", 12);
    auto Item2 = std::make_shared<Girl>("Alice", 10);
    manager.addItem(Item1, "Boy1");
    manager.addItem(Item2, "Girl1");

    // Interact with the Boy by returning the Boy item.
    manager.getItem<Boy>("Boy1")->speak();
    manager.getItem<Boy>("Boy1")->walk();
    manager.getItem<Boy>("Boy1")->eat();

    // Modify Boy
    manager.modifyItem<Boy>("Boy1", [](Boy& item) {
        item.age += 1;
        item.name = "UpdatedTom";
    });

    manager.getItem<Boy>("Boy1")->speak();  // See updated values

    std::cout << "::::::::::::::::::::::::::::::::::::::::::::::\n";

    // Interact with Girl by returning the Girl Item
    manager.getItem<Girl>("Girl1")->speak();
    manager.getItem<Girl>("Girl1")->walk();
    manager.getItem<Girl>("Girl1")->eat();

    /*
      Modify Girl
      This function returns the value for modification or
      change of the value.
    */ 
    manager.modifyItem<Girl>("Girl1", [](Girl& item) {
        item.age += 1;
        item.name = "UpdatedAlice";
    });

    /*
     This function returns the Item with this tag for accessing its value.
    */
    manager.getItem<Girl>("Girl1")->speak();  // See updated values

    std::cout << "::::::::::::::::::::::::::::::::::::::::::::::\n";

    // Undo both modifications
    manager.undo(); // Undo Girl
    manager.undo(); // Undo Boy

    manager.getItem<Boy>("Boy1")->speak();   // Should show "Tom", 12
    manager.getItem<Girl>("Girl1")->speak(); // Should show "Alice", 10

    std::cout << "::::::::::::::::::::::::::::::::::::::::::::::\n";

    // Redo both modifications
    manager.redo(); // Redo Boy
    manager.redo(); // Redo Girl

    manager.getItem<Boy>("Boy1")->speak(); // Should show "UpdatedTom", 13
    manager.getItem<Girl>("Girl1")->speak(); // Should show    
                                             // "UpdatedAlice", 11
    std::cout << "::::::::::::::::::::::::::::::::::::::::::::::\n";

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

This example highlights Smart_Store’s ability to track state changes, support undo/redo operations, and maintain clean object access, all while using modern C++ idioms like lambdas and smart pointers.

Expected output:

If you look very closely at the output, you will realise that the undo/redo methods are doing their job at ease; reverting and tracking each object to its previous state and also restoring it to the current assigned values.

Key Takeaways
Smart_Store abstracts away the complexity of object lifecycle management.

It supports real-time interaction, state tracking, storing objects at runtime, and modification history.

It’s built with modern C++ principles: RAII, smart pointers, lambdas, and clean separation of concerns.

Final Thoughts
Smart_Store isn’t just an API; it’s a blueprint for building scalable, maintainable systems in C++. Whether you're managing vehicles, people, or abstract entities, Smart_Store gives you the tools to build with confidence and focus mainly on logic.

Code should be simple to write, powerful to run, and beautiful to extend. That’s the Smart_Store way. I’m exploring an architectural foundation that unifies different dimensions of programming into a single living structure — one I call Bio-Struct, inspired by biological systems that power Smart_Store.

Top comments (0)