LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc::bwf::ContextNames< T > Class Template Reference

#include <bwf_base.h>

Inheritance diagram for swoc::bwf::ContextNames< T >:
Inheritance graph
Collaboration diagram for swoc::bwf::ContextNames< T >:
Collaboration graph

Classes

class  Binding
 Specialized binding for names in an instance of ContextNames. More...
 

Public Types

using context_type = T
 
using Generator = typename super_type::Generator
 Functional type for a generator.
 
using ExternalGenerator = std::function<ExternalGeneratorSignature>
 Signature for an external (context-free) generator.
 
- Public Types inherited from swoc::bwf::NameMap< BufferWriter &(BufferWriter &, const Spec &, T &)>
using Generator
 Signature for generators.
 

Public Member Functions

self_typeassign (std::string_view const &name, const ExternalGenerator &bg)
 
self_typeassign (std::string_view const &name, Generator const &generator)
 
Binding bind (context_type &context)
 
- Public Member Functions inherited from swoc::bwf::NameMap< BufferWriter &(BufferWriter &, const Spec &, T &)>
 NameMap ()
 Construct an empty container.
 
 NameMap (std::initializer_list< std::tuple< std::string_view, Generator const & > > list)
 Construct and assign the names and generators in list.
 
self_typeassign (std::string_view const &name, Generator const &generator)
 
bool contains (std::string_view name)
 
 NameMap ()
 Construct an empty container.
 
 NameMap (std::initializer_list< std::tuple< std::string_view, Generator const & > > list)
 Construct and assign the names and generators in list.
 
self_typeassign (std::string_view const &name, Generator const &generator)
 
bool contains (std::string_view name)
 

Protected Member Functions

virtual BufferWriteroperator() (BufferWriter &w, const Spec &spec, context_type &ctx) const
 
- Protected Member Functions inherited from swoc::bwf::NameMap< BufferWriter &(BufferWriter &, const Spec &, T &)>
std::string_view localize (std::string_view const &name)
 Copy name in to local storage and return a view of it.
 
std::string_view localize (std::string_view const &name)
 Copy name in to local storage and return a view of it.
 

Additional Inherited Members

- Protected Types inherited from swoc::bwf::NameMap< BufferWriter &(BufferWriter &, const Spec &, T &)>
using Map
 
- Protected Attributes inherited from swoc::bwf::NameMap< BufferWriter &(BufferWriter &, const Spec &, T &)>
Map _map
 Name to name generator.
 
MemArena _arena
 Local name storage.
 
Map _map
 Name to name generator.
 
MemArena _arena
 Local name storage.
 

Detailed Description

template<typename T>
class swoc::bwf::ContextNames< T >

Associate names with context dependent generators.

Template Parameters
TThe context type. This is used directly. If the context needs to be const then this parameter should make that explicit, e.g. ContextNames<const Context>. This parameter is accessible via the context_type alias.

This provides a name binding that also has a local context, provided at the formatting call site. The functors have access to this context and are presumed to use it to generate output. This binding can also contain external generators which do not get access to the context to make it convenient to add external generators as well as context generators.

A context functor should have the signature

BufferWriter & generator(BufferWriter & w, const Spec & spec, T & context);

context will be the context for the binding passed to the formatter.

This is used by the formatting logic by calling the bind method with a context object.

Definition at line 382 of file bwf_base.h.

Member Typedef Documentation

◆ context_type

template<typename T>
using swoc::bwf::ContextNames< T >::context_type = T

Export for external convenience.

Definition at line 389 of file bwf_base.h.

◆ ExternalGenerator

template<typename T>
using swoc::bwf::ContextNames< T >::ExternalGenerator = std::function<ExternalGeneratorSignature>

Signature for an external (context-free) generator.

Definition at line 393 of file bwf_base.h.

◆ Generator

template<typename T>
using swoc::bwf::ContextNames< T >::Generator = typename super_type::Generator

Functional type for a generator.

Definition at line 391 of file bwf_base.h.

Member Function Documentation

◆ assign() [1/2]

template<typename T>
auto swoc::bwf::ContextNames< T >::assign ( std::string_view const & name,
const ExternalGenerator & bg )

Assign the external generator bg to name.

This is used for generators in the namespace that do not use the context.

Parameters
nameName associated with the generator.
bgAn external generator that requires no context.
Returns
*this

Definition at line 623 of file bwf_base.h.

◆ assign() [2/2]

template<typename T>
auto swoc::bwf::ContextNames< T >::assign ( std::string_view const & name,
Generator const & generator )

Assign the generator to the name.

Parameters
nameName associated with the generator.
generatorThe generator function.

Definition at line 631 of file bwf_base.h.

◆ bind()

template<typename T>
auto swoc::bwf::ContextNames< T >::bind ( context_type & context)
inline

Bind the name map to a specific context.

Parameters
contextThe instance of T to use in the generators.
Returns
A reference to an internal instance of a subclass of the protocol class BoundNames.

This is used when passing the context name map to the formatter.

Definition at line 558 of file bwf_base.h.

◆ operator()()

template<typename T>
BufferWriter & swoc::bwf::ContextNames< T >::operator() ( BufferWriter & w,
const Spec & spec,
context_type & ctx ) const
protectedvirtual

Generate output based on the name in spec.

Parameters
wOutput.
specFormat specifier for output.
ctxThe context object.
Returns
w

This is called from the formatting logic to generate output for a named specifier. Subclasses that need to handle name dispatch differently should override this method. This method performs a name lookup in the local nameset.

Definition at line 564 of file bwf_base.h.


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