commons 0.1.5
Header-only C++23 library of common/shared types for the C++ libraries
Loading...
Searching...
No Matches
origin.hpp File Reference

A polymorphic provenance envelope — comms::IOrigin — that records where a definition came from, discriminated by a compile-time kind. More...

#include <commons/display_info.hpp>
#include <commons/fixed_string.hpp>
#include <concepts>
#include <format>
#include <functional>
#include <map>
#include <memory>
#include <ostream>
#include <string>
#include <string_view>
#include <utility>
Include dependency graph for origin.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  comms::IOrigin
 Abstract provenance envelope. More...
 
class  comms::OriginKind< Kind, Derived >
 CRTP base wiring kind(), clone(), and info() from a compile-time kind string and the concrete Derived type. More...
 
class  comms::CoreOrigin
 The definition was registered by the host core itself. More...
 
class  comms::InternalOrigin
 The definition was registered by an internal subsystem. More...
 
class  comms::ExternalOrigin
 The definition came from an external source, named by source. More...
 
class  comms::UnknownOrigin
 Provenance is unknown. More...
 
class  comms::GlobalOriginRegistry
 A program-wide registry mapping an origin kind string to a factory. More...
 
struct  comms::OriginRegistrar< T >
 A self-registering object: constructing one registers T's factory into the GlobalOriginRegistry. More...
 
struct  std::formatter< T >
 Formats any comms::IOrigin (and derived) as its kind() string. No spec. More...
 

Macros

#define COMMONS_REGISTER_ORIGIN(Ident)    inline const ::comms::OriginRegistrar<Ident> commons_origin_registrar_##Ident {}
 Register an already-defined origin type Ident into the GlobalOriginRegistry.
 

Typedefs

using comms::OriginPtr = std::unique_ptr< IOrigin >
 A heap-owned origin. The canonical way to carry an IOrigin by value.
 

Functions

std::string comms::to_string (const IOrigin &o)
 An origin as its kind() string.
 

Detailed Description

A polymorphic provenance envelope — comms::IOrigin — that records where a definition came from, discriminated by a compile-time kind.

comms::IOrigin is an abstract base for an open set of provenance sources. Each concrete origin identifies itself with a kind() string, but that string is supplied as a compile-time comms::FixedString template parameter rather than hand-written per subclass — the same pattern as IconifySet<FixedString Set>. Derive a concrete origin from OriginKind<"yourkind", YourType> and it gets kind(), a deep clone(), and a polymorphic info() for free.

info() returns a comms::DisplayInfo (name/description/icon/color) sourced from the concrete type's static display_info(), so every origin is also a comms::Displayable and works with comms::display_info<CoreOrigin>().

New kinds register themselves into the program-wide GlobalOriginRegistry via COMMONS_REGISTER_ORIGIN(Type) — mirroring GlobalFlagRegistry / COMMONS_REGISTER_FLAG — so a JSON kind discriminator can be turned back into the right concrete type without consumers enumerating the set.

The built-in kinds are CoreOrigin ("core"), InternalOrigin ("internal"), ExternalOrigin ("external", carrying a source string), and UnknownOrigin ("unknown").

Serialization (in commons/json.hpp, gated by COMMONS_WITH_NLOHMANN_JSON): the base library has no forced dependency, so this header carries no JSON. An origin travels as a JSON object {"kind": …, …fields}; the four built-in kinds round-trip their fields, and a custom kind supplies its own to_json/from_json.

Text output (always available): to_string, operator<<, and std::format all emit the kind() string.

Macro Definition Documentation

◆ COMMONS_REGISTER_ORIGIN

#define COMMONS_REGISTER_ORIGIN (   Ident)     inline const ::comms::OriginRegistrar<Ident> commons_origin_registrar_##Ident {}

Register an already-defined origin type Ident into the GlobalOriginRegistry.

Place it at namespace scope after the type.