rippled
Classes | Public Member Functions | Private Types | Private Attributes | List of all members
ripple::test::csf::CollectorRef Class Reference

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

Collaboration diagram for ripple::test::csf::CollectorRef:
Collaboration graph
[legend]

Classes

class  Any
 
struct  ICollector
 

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 arbitray 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 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 68 of file CollectorRef.h.

Member Typedef Documentation

◆ tp

Definition at line 70 of file CollectorRef.h.

Constructor & Destructor Documentation

◆ CollectorRef() [1/3]

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

Definition at line 292 of file CollectorRef.h.

◆ CollectorRef() [2/3]

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

◆ CollectorRef() [3/3]

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

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ on()

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

Definition at line 307 of file CollectorRef.h.

Member Data Documentation

◆ impl_

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

Definition at line 288 of file CollectorRef.h.