gbase
Loading...
Searching...
No Matches
gbase.h File Reference

Lightweight CRTP base class that provides a pre-configured logger to derived types. More...

#include <iostream>
#include <string>
#include <typeinfo>
#include "glogger.h"
Include dependency graph for gbase.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

class  GBase< Derived >
 CRTP base class that provides logging facilities to the derived class. More...
 

Functions

std::string demangle (const char *name)
 Fallback demangle implementation for non-GNU toolchains.
 

Detailed Description

This header defines:

  • A small utility function, demangle(), used to turn compiler-specific type names (typically produced by typeid(T).name()) into more readable strings when supported.
  • The template class GBase , which centralizes logger construction and lifetime management for derived classes using the CRTP (Curiously Recurring Template Pattern).

Design goals:

  • Make logging setup consistent across many derived classes.
  • Keep logger ownership explicit and predictable via std::shared_ptr.
  • Optionally allow sharing a single logger across multiple objects to reduce overhead.

Notes on demangling:

  • When compiled with __GNUG__ (GNU-compatible toolchains), demangling uses abi::__cxa_demangle from <cxxabi.h>.
  • On other toolchains, demangle() returns the input name unchanged.

Definition in file gbase.h.

Function Documentation

◆ demangle()

std::string demangle ( const char * name)

On compilers/platforms where GNU-style demangling is not available, this function simply returns the input string unchanged.

This is a deliberate portability choice: the calling code can rely on the function existing everywhere, while still benefiting from readable names where supported.

Parameters
nameA mangled type name, usually produced by typeid(T).name().
Returns
The original name (no demangling performed).

Definition at line 78 of file gbase.h.