Skip to content
victor edited this page Jul 28, 2025 · 15 revisions

πŸ›οΈ Smart_Store

Technical Notes

Smart_Store Banner


Project Summary

Smart_Store is a robust, extensible, and modular C++20 framework for managing collections of arbitrary objects with advanced serialization, schema migration, and undo/redo state management. It is ideal for inventory management, asset tracking, game editors, and any application needing flexible object storage with persistence and versioning.


Core Objectives

  • Safe, maintainable item storage using std::shared_ptr
  • Tag-based lookup for fast item retrieval
  • Undo/redo history for state management
  • Import/export across JSON, XML, CSV, and Binary formats
  • Clean schema migration for legacy upgrades
  • Thread-safe operations
  • Extensible custom type registration via templates
  • Built with modern C++ idioms (RAII, STL, type safety)

Key Features

Memory Management

  • Uses std::shared_ptr for all items
  • No raw pointers exposed
  • Ownership fully managed internally
  • Undo/redo operates on deep clones

Undo / Redo History

  • Snapshots stored as deep clones
  • undo() and redo() for safe state traversal
  • Clear separation of history stacks

Thread Safety

  • Mutex locks (std::lock_guard<std::mutex>) for safe concurrent access
  • Read/write operations protected
  • Thread-safe API prevents race conditions

Schema Migration

  • Built-in MigrationRegistry system
  • Versioned upgrades of legacy JSON data on import
  • Gradual migration strategies (e.g., v1 β†’ v2 β†’ v3)
  • Reduces data corruption and incompatibility

Multi-Format Import / Export

Format Import Export Notes
JSON βœ… βœ… Human-friendly
CSV βœ… βœ… Interop with Excel
XML βœ… βœ… Human-readable
Binary βœ… βœ… Compact & fast

Architecture Overview

file structure

Main Components:

Component Role
ItemManager Core storage & API interface
BaseItem Abstract base for item types
ItemWrapper Handles serialization metadata
Logger Color logging for clarity
MigrationRegistry Manages version upgrades
AtomicFileWriter Safe file writing utility

Supported Types

  • Built-in: int, std::string, bool
  • Custom: Any user-defined class registered via registerType

Data Model

  • items: std::unordered_map<std::string, std::shared_ptr<BaseItem>> (tag β†’ object)
  • idMap: Optional map for reverse-lookup by ID

Design Considerations

Thread Safety

  • Anticipates concurrent access (UI threads, background saves)
  • Protects items against simultaneous reads/writes

Schema Migration

  • Ensures long-term data safety
  • Supports evolving needs without breaking data

Undo/Redo

  • Ideal for editors and asset tools
  • Encourages experimentation with state safety

Technical Stack

  • C++20: Modern features, STL, optional, shared_ptr
  • nlohmann::json: Intuitive JSON handling
  • TinyXML2: Lightweight XML parsing
  • ANSI Color Logger: Developer-friendly debugging
  • RAII: Automatic resource management

Limitations & Future Improvements

  • Single-level undo/redo (future: multi-depth branching)
  • Schema migration is JSON-focused (extend to XML/CSV)
  • Thread safety is global-lock (potential for finer-grained locking)

Ideal Use Cases

  • Inventory management systems
  • Asset tracking tools
  • Game editors
  • Data analysis tools with reversible state
  • Apps needing cross-format data interoperability

πŸ›οΈ Smart_Store

::| Development Guide |::

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

Clone this wiki locally