/vapor

A lightweight runtime reflection and dynamic type system for C++, started as a weekend project to learn more about modern C++ features.

Primary LanguageC++MIT LicenseMIT

Vapor Reflection Engine

A lightweight, dependency-free runtime reflection and dynamic type system for C++, optimized for loading thousands of data-driven types from configuration files (written in an easy-to-use DSL) while maintaining high performance.

Features

  • Runtime Type Creation: Load types dynamically from DSL files at runtime
  • Full Introspection: Iterate over properties, query inheritance hierarchies
  • Inheritance Support: Multi-level inheritance with automatic property collection
  • Type-Safe Storage: Built on std::variant for compile-time type safety
  • Zero Dependencies: Uses only C++17 standard library (we will be upgrading to C++23)
  • Scalable: Designed to handle thousands of types efficiently

Build Options

Option Default Description
VAPOR_BUILD_EXAMPLES ON Build example programs
VAPOR_BUILD_TESTS OFF Build test suite
VAPOR_BUILD_BENCHMARKS OFF Build performance benchmarks
VAPOR_BUILD_SHARED OFF Build shared library instead of static

Architecture

Core Components

  • PropertyValue: Type-safe storage using std::variant<int, double, std::string, bool, std::vector<int>, std::vector<double>, std::vector<std::string>>
  • TypeDescriptor: Metadata for types and their properties
  • TypeRegistry: Singleton registry for type management and object creation
  • DynamicObject: Runtime instances with property access
  • DSLParser: Parser for type definition files

Design Principles

  1. Simplicity over Magic: Avoided complex template metaprogramming for maintainability
  2. Performance Where It Matters: O(1) property access via hash maps
  3. Type Safety: Compile-time type checking where possible, runtime validation elsewhere
  4. Scalability: Tested conceptually with thousands of types

Known Limitations

  • Limited to 7 basic property types (int, double, string, bool, vector, vector, vector)
    • This should suffice for most general purpose applications to start with
  • Not thread-safe by default (work will be done on this front once we are at a point of implementation)
  • No built-in serialization

Roadmap

  • Additional property types (custom structs, etc.)
  • Method/function support in type descriptors
  • Data serialization format (possibly integrate JSON and binary formats)
  • Runtime schema evolution
  • Multi-threading support
  • Plugin architecture for custom native types