Simple-Log  alpha-v0.7
sl::log::RecordBuilder< TRecord > Class Template Reference

Helper class for building new Records. More...

#include <RecordBuilder.hpp>

Public Types

using Record_t = std::remove_cvref_t< TRecord >
 
using SeverityLevel_t = RecordSeverity_t< Record_t >
 
using Channel_t = RecordChannel_t< Record_t >
 

Public Member Functions

 RecordBuilder (Record_t prefabRec, LogCallback_t cb) noexcept
 Constructor. More...
 
 ~RecordBuilder () noexcept
 Destructor. More...
 
 RecordBuilder (RecordBuilder &&other) noexcept
 Move constructor. More...
 
RecordBuilderoperator= (RecordBuilder &&other) noexcept
 Move-assign operator. More...
 
 RecordBuilder (const RecordBuilder &)=delete
 Deleted copy constructor. More...
 
RecordBuilderoperator= (const RecordBuilder &)=delete
 Deleted copy-assign operator. More...
 
Record_trecord () noexcept
 Accessor to the internal record object. More...
 
const Record_trecord () const noexcept
 Const accessor to the internal record object. More...
 
template<class T >
requires requires (T &&data)
 Output operator. More...
 
RecordBuilderoperator<< (T &&data)
 
template<std::invocable< Record_t & > TAction>
RecordBuilderoperator<< (TAction action)
 Special output operator overload for actions on Record. More...
 

Detailed Description

template<Record TRecord>
class sl::log::RecordBuilder< TRecord >

Helper class for building new Records.

Template Parameters
TRecordUsed Record type.

This is class provides the simple and elegant interface for making logging expressions. Its objects are non-copyable but movable. When a RecordBuilder object gets destroyed (mainly because going out of scope) it will automatically send its created Record to the designated Logger object. Users should not instantiate objects themselves, but should instead use the Logger objects.

Examples
CustomRecordType/main.cpp.

Member Typedef Documentation

◆ Channel_t

template<Record TRecord>
using sl::log::RecordBuilder< TRecord >::Channel_t = RecordChannel_t<Record_t>

◆ Record_t

template<Record TRecord>
using sl::log::RecordBuilder< TRecord >::Record_t = std::remove_cvref_t<TRecord>

◆ SeverityLevel_t

template<Record TRecord>
using sl::log::RecordBuilder< TRecord >::SeverityLevel_t = RecordSeverity_t<Record_t>

Constructor & Destructor Documentation

◆ RecordBuilder() [1/3]

template<Record TRecord>
sl::log::RecordBuilder< TRecord >::RecordBuilder ( Record_t  prefabRec,
LogCallback_t  cb 
)
inlineexplicitnoexcept

Constructor.

Parameters
prefabRecPrefabricated Record
cbCallback to the associated Logger object

This constructor requires a callback to the associated Logger objects log function. The callback should have the following signature:

void(Record)
concept Record
Concept which all the necessary concepts for Record types.
Definition: Record.hpp:204

◆ ~RecordBuilder()

template<Record TRecord>
sl::log::RecordBuilder< TRecord >::~RecordBuilder ( )
inlinenoexcept

Destructor.

If RecordBuilder is valid (in fact, if a callback is installed) it moves its created Record object to the Logger object.

◆ RecordBuilder() [2/3]

template<Record TRecord>
sl::log::RecordBuilder< TRecord >::RecordBuilder ( RecordBuilder< TRecord > &&  other)
inlinenoexcept

Move constructor.

Transfers ownership of other's data to this object. If other has an installed callback, it will be cleared.

Parameters
otherAnother RecordBuilder object

◆ RecordBuilder() [3/3]

template<Record TRecord>
sl::log::RecordBuilder< TRecord >::RecordBuilder ( const RecordBuilder< TRecord > &  )
delete

Deleted copy constructor.

Member Function Documentation

◆ operator<<() [1/2]

template<Record TRecord>
RecordBuilder& sl::log::RecordBuilder< TRecord >::operator<< ( T &&  data)
inline

◆ operator<<() [2/2]

template<Record TRecord>
template<std::invocable< Record_t & > TAction>
RecordBuilder& sl::log::RecordBuilder< TRecord >::operator<< ( TAction  action)
inline

Special output operator overload for actions on Record.

Parameters
actionAction which will be applied to the internal Record object.
Returns
Returns a reference to this.

◆ operator=() [1/2]

template<Record TRecord>
RecordBuilder& sl::log::RecordBuilder< TRecord >::operator= ( const RecordBuilder< TRecord > &  )
delete

Deleted copy-assign operator.

◆ operator=() [2/2]

template<Record TRecord>
RecordBuilder& sl::log::RecordBuilder< TRecord >::operator= ( RecordBuilder< TRecord > &&  other)
inlinenoexcept

Move-assign operator.

Transfers ownership of other's data to this object. If other has an installed callback, it will be cleared.

Parameters
otherAnother RecordBuilder object
Returns
Returns a reference to this.

◆ record() [1/2]

template<Record TRecord>
const Record_t& sl::log::RecordBuilder< TRecord >::record ( ) const
inlinenoexcept

Const accessor to the internal record object.

◆ record() [2/2]

template<Record TRecord>
Record_t& sl::log::RecordBuilder< TRecord >::record ( )
inlinenoexcept

Accessor to the internal record object.

◆ requires()

template<Record TRecord>
template<class T >
requires sl::log::RecordBuilder< TRecord >::requires ( T &&  data)
inline

Output operator.

Attaches data to the underlying ostream object.

Template Parameters
TRequires that std::ostringstream has an overload of operator << for T.
Parameters
dataData about to be attached.
Returns
Returns a reference to this.

The documentation for this class was generated from the following file: