libmoost
moost::io::async_writer< TWork, TRolloverPolicy > Class Template Reference

async_writer is a class that simplifies the mechanics of writing to a file asynchronously. More...

#include <async_writer.hpp>

Inheritance diagram for moost::io::async_writer< TWork, TRolloverPolicy >:
Collaboration diagram for moost::io::async_writer< TWork, TRolloverPolicy >:

List of all members.

Public Member Functions

 async_writer (const std::string &base_path, const TRolloverPolicy &rollover_policy=TRolloverPolicy(), size_t max_queue=0, size_t enqueue_timeout=0)
 Constructs an async_writer.
 ~async_writer ()
void stop ()

Protected Member Functions

void do_work (TWork &work)
 Override this method and do your work here.

Private Member Functions

void reload_out ()
 open a new file to write

Private Attributes

std::string m_base_path
TRolloverPolicy m_rollover_policy
std::ofstream m_out

Detailed Description

template<typename TWork, class TRolloverPolicy = count_rollover>
class moost::io::async_writer< TWork, TRolloverPolicy >

async_writer is a class that simplifies the mechanics of writing to a file asynchronously.

To use it, you must provide a template parameter, and the template type must implement the method: write(std::ostream & out)

Definition at line 140 of file async_writer.hpp.


Constructor & Destructor Documentation

template<typename TWork , class TRolloverPolicy = count_rollover>
moost::io::async_writer< TWork, TRolloverPolicy >::async_writer ( const std::string &  base_path,
const TRolloverPolicy &  rollover_policy = TRolloverPolicy(),
size_t  max_queue = 0,
size_t  enqueue_timeout = 0 
) [inline]

Constructs an async_writer.

Parameters:
base_paththe base path name for file creation (unix time is appended)
max_queuethe maximum length the queue may grow before further enqueue's begin to wait (default don't wait)
enqueue_timeoutthe longest amount of time an enqueue may wait (-1 means wait forever)

Definition at line 188 of file async_writer.hpp.

template<typename TWork , class TRolloverPolicy = count_rollover>
moost::io::async_writer< TWork, TRolloverPolicy >::~async_writer ( ) [inline]

Destroys the async_writer

It's safe to destroy the async_writer without first calling stop(). It will shut down cleanly.

Definition at line 202 of file async_writer.hpp.

Here is the call graph for this function:


Member Function Documentation

template<typename TWork , class TRolloverPolicy = count_rollover>
void moost::io::async_writer< TWork, TRolloverPolicy >::do_work ( TWork &  work) [inline, protected, virtual]

Override this method and do your work here.

Implements moost::thread::async_worker< TWork >.

Definition at line 173 of file async_writer.hpp.

Here is the call graph for this function:

template<typename TWork , class TRolloverPolicy = count_rollover>
void moost::io::async_writer< TWork, TRolloverPolicy >::reload_out ( ) [inline, private]

open a new file to write

Definition at line 149 of file async_writer.hpp.

Here is the caller graph for this function:

template<typename TWork , class TRolloverPolicy = count_rollover>
void moost::io::async_writer< TWork, TRolloverPolicy >::stop ( ) [inline]

Reimplemented from moost::thread::async_worker< TWork >.

Definition at line 207 of file async_writer.hpp.

Here is the caller graph for this function:


Member Data Documentation

template<typename TWork , class TRolloverPolicy = count_rollover>
std::string moost::io::async_writer< TWork, TRolloverPolicy >::m_base_path [private]

Definition at line 144 of file async_writer.hpp.

template<typename TWork , class TRolloverPolicy = count_rollover>
std::ofstream moost::io::async_writer< TWork, TRolloverPolicy >::m_out [private]

Definition at line 146 of file async_writer.hpp.

template<typename TWork , class TRolloverPolicy = count_rollover>
TRolloverPolicy moost::io::async_writer< TWork, TRolloverPolicy >::m_rollover_policy [private]

Definition at line 145 of file async_writer.hpp.


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