scclib
Stable Cloud Computing C++ Library
Public Member Functions | List of all members
scc::util::ReadCounter Class Reference

Adds byte count to a read stream. More...

#include <rwcounter.h>

Inheritance diagram for scc::util::ReadCounter:
Inheritance graph
[legend]
Collaboration diagram for scc::util::ReadCounter:
Collaboration graph
[legend]

Public Member Functions

 ReadCounter ()
 Reads will return 0 until reset. More...
 
 ReadCounter (Reader &)
 Chain using a reference. More...
 
 ReadCounter (const std::shared_ptr< Reader > &)
 Chain using a shared pointer.
 
void read_reset (Reader &)
 Reset the chained reader.
 
virtual void read_reset (const std::shared_ptr< Reader > &)
 Reset the chained reader.
 
virtual std::shared_ptr< Readerread_shared () const
 
virtual size_t read (void *, size_t)
 Read interface. More...
 
uint64_t read_count () const
 
void read_count (uint64_t v)
 
void read_count_reset ()
 
uint64_t read_calls () const
 
void read_calls (uint64_t v)
 
void read_calls_reset ()
 

Detailed Description

Adds byte count to a read stream.

Example from scclib/util/unittest/iohelper.cc

using std::chrono::milliseconds;
using std::chrono::duration_cast;
struct Slow : public Reader, public Writer
{
Slow() {}
virtual ~Slow() {}
size_t read(void*, size_t l)
{
std::this_thread::sleep_for(milliseconds(50));
return l;
}
size_t write(const void*, size_t l)
{
std::this_thread::sleep_for(milliseconds(100));
return l;
}
};
Slow base;
RwCounter c(base, base);
RwTimer t(c, c);
t.read(0, 50);
t.write(0, 100);
cout << "read timer=" << t.read_dur().count() << endl;
cout << "write timer=" << t.write_dur().count() << endl;
cout << "read count=" << c.read_count() << endl;
cout << "write count=" << c.write_count() << endl;
ASSERT_EQ(duration_cast<milliseconds>(t.read_dur()).count(), 50);
ASSERT_EQ(duration_cast<milliseconds>(t.write_dur()).count(), 100);
ASSERT_EQ(c.read_count(), 50);
ASSERT_EQ(c.write_count(), 100);
virtual size_t read(void *, size_t)
Read interface.
Definition: iostream.cc:821
Examples
util/unittest/iohelper.cc.

Definition at line 58 of file rwcounter.h.

Constructor & Destructor Documentation

◆ ReadCounter() [1/2]

ReadCounter::ReadCounter ( )

Reads will return 0 until reset.

counters

Definition at line 807 of file iostream.cc.

◆ ReadCounter() [2/2]

ReadCounter::ReadCounter ( Reader r)

Chain using a reference.

Does not assume ownership.

Definition at line 811 of file iostream.cc.

Member Function Documentation

◆ read()

size_t ReadCounter::read ( void *  ,
size_t   
)
virtual

Read interface.

Read a block of data to a maximum. Return number of bytes read.

Implements scc::util::Reader.

Definition at line 821 of file iostream.cc.


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