xrpld
Loading...
Searching...
No Matches
xrpl::test::csf::CollectorRef Class Reference

Holds a type-erased reference to an arbitrary collector. More...

#include <CollectorRef.h>

Collaboration diagram for xrpl::test::csf::CollectorRef:

Classes

struct  ICollector
class  Any

Public Member Functions

template<class T>
 CollectorRef (T &t)
 CollectorRef (CollectorRef const &c)=delete
CollectorRefoperator= (CollectorRef &c)=delete
 CollectorRef (CollectorRef &&)=default
CollectorRefoperator= (CollectorRef &&)=default
template<class E>
void on (PeerID node, tp when, E const &e)

Private Types

using tp = SimTime

Private Attributes

std::unique_ptr< ICollectorimpl_

Detailed Description

Holds a type-erased reference to an arbitrary collector.

A collector is any class that implements

on(NodeID, SimTime, Event)

for all events emitted by a Peer.

This class is used to type-erase the actual collector used by each peer in the simulation. The idea is to compose complicated and typed collectors using the helpers in collectors.h, then only type erase at the higher-most level when adding to the simulation.

The example code below demonstrates the reason for storing the collector as a reference. The collector's lifetime will generally be longer than the simulation; perhaps several simulations are run for a single collector instance. The collector potentially stores lots of data as well, so the simulation needs to point to the single instance, rather than requiring collectors to manage copying that data efficiently in their design.

// Initialize a specific collector that might write to a file.
SomeFancyCollector collector{"out.file"};
// Setup your simulation
Sim sim(trustgraph, topology, collector);
// Run the simulation
sim.run(100);
// do any reported related to the collector
collector.report();
Note
If a new event type is added, it needs to be added to the interfaces below.

Definition at line 47 of file CollectorRef.h.

Member Typedef Documentation

◆ tp

Definition at line 49 of file CollectorRef.h.

Constructor & Destructor Documentation

◆ CollectorRef() [1/3]

template<class T>
xrpl::test::csf::CollectorRef::CollectorRef ( T & t)

Definition at line 271 of file CollectorRef.h.

◆ CollectorRef() [2/3]

xrpl::test::csf::CollectorRef::CollectorRef ( CollectorRef const & c)
delete

◆ CollectorRef() [3/3]

xrpl::test::csf::CollectorRef::CollectorRef ( CollectorRef && )
default

Member Function Documentation

◆ operator=() [1/2]

CollectorRef & xrpl::test::csf::CollectorRef::operator= ( CollectorRef & c)
delete

◆ operator=() [2/2]

CollectorRef & xrpl::test::csf::CollectorRef::operator= ( CollectorRef && )
default

◆ on()

template<class E>
void xrpl::test::csf::CollectorRef::on ( PeerID node,
tp when,
E const & e )

Definition at line 286 of file CollectorRef.h.

Member Data Documentation

◆ impl_

std::unique_ptr<ICollector> xrpl::test::csf::CollectorRef::impl_
private

Definition at line 267 of file CollectorRef.h.