# Barry::RecordBuilder< RecordT, StorageT > Class Template Reference

`#include <builder.h>`

Inheritance diagram for Barry::RecordBuilder< RecordT, StorageT >:

[legend]
Collaboration diagram for Barry::RecordBuilder< RecordT, StorageT >:

[legend]

List of all members.

## Detailed Description

### template<class RecordT, class StorageT>
class Barry::RecordBuilder< RecordT, StorageT >

Template class for easy creation of specific protocol packet builder objects.

This template takes the following template arguments:

- RecordT: One of the record classes in record.h
- StorageT: A custom storage functor class. An object of this type will be called as a function with empty Record as an argument. The storage class is expected to fill the record object in preparation for building the packet out of that data. These calls happen on the fly as the data is sent to the device over USB, so it should not block forever.

Example SaveDatabase() call:

        FIXME

Definition at line 167 of file builder.h.

## Public Member Functions

| RecordBuilder (StorageT &storage)
| Constructor that references an externally managed storage object.
| RecordBuilder (StorageT *storage)
| Constructor that references a locally managed storage object.
virtual bool | BuildRecord (DBData &data, size_t &offset, const IConverter *ic)
| Called to build the record field data.
virtual bool | FetchRecord (DBData &data, const IConverter *ic)
| Same as BuildRecord, but does not care about any offsets.
virtual bool | EndOfFile () const
| Sometimes a builder can have multiple databases stored in it, so when Build/Fetch returns false, check if there is more data with this function.

## Constructor & Destructor Documentation

template<class RecordT, class StorageT>

Barry::RecordBuilder< RecordT, StorageT >::RecordBuilder | ( | StorageT & | storage | ) | `[inline]`

Constructor that references an externally managed storage object.

Definition at line 177 of file builder.h.

template<class RecordT, class StorageT>

Barry::RecordBuilder< RecordT, StorageT >::RecordBuilder | ( | StorageT * | storage | ) | `[inline]`

Constructor that references a locally managed storage object.

The pointer passed in will be stored, and freed when this class is destroyed. It is safe to call this constructor with a 'new'ly created storage object.

Definition at line 189 of file builder.h.

## Member Function Documentation

template<class RecordT, class StorageT>

virtual bool Barry::RecordBuilder< RecordT, StorageT >::BuildRecord | ( | DBData & | data,
|  | size_t & | offset,
|  | const IConverter * | ic |
| ) |  |  | `[inline, virtual]`

Called to build the record field data.

Store the raw data in data, using offset to know where to write. Be sure to update offset, and be sure to adjust the size of the data packet (possibly with Data::ReleaseBuffer()).

Returns true if successful, and false if at the end of the series. Note that if EndOfFile() is false after this function returns false, then there may be another series available, which the next call to BuildRecord() will determine.

Implements Barry::Builder.

Definition at line 203 of file builder.h.

References Barry::SetDBData().

Referenced by Barry::RecordBuilder< RecordT, StorageT >::FetchRecord().

Here is the call graph for this function:

Here is the caller graph for this function:

template<class RecordT, class StorageT>

virtual bool Barry::RecordBuilder< RecordT, StorageT >::FetchRecord | ( | DBData & | data,
|  | const IConverter * | ic |
| ) |  |  | `[inline, virtual]`

Same as BuildRecord, but does not care about any offsets.

The caller should call DBData::GetOffset() afterward to discover if there is an offset to the result.

This is usually the fastest of the two functions, since extra copying may be required if a specific offset is given. When building records from Record classes, both functions are the same speed. But when building records from the device, the device decides the offset, so FetchRecord() is faster, since BuildRecord requires a copy to adjust to the right offset.

The caller should use the function that results in the least amount of copying for the caller. If the caller doesn't care about where the resulting record is in data, use FetchRecord().

Implements Barry::Builder.

Definition at line 218 of file builder.h.

References Barry::RecordBuilder< RecordT, StorageT >::BuildRecord().

Here is the call graph for this function:

template<class RecordT, class StorageT>

virtual bool Barry::RecordBuilder< RecordT, StorageT >::EndOfFile | ( |  | ) | const`[inline, virtual]`

Sometimes a builder can have multiple databases stored in it, so when Build/Fetch returns false, check if there is more data with this function.

This function is not used by database-oriented functions, but by pipe- oriented functions.

Implements Barry::Builder.

Definition at line 224 of file builder.h.

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

- builder.h