# Barry::Restore Class Reference

`#include <restore.h>`

Inheritance diagram for Barry::Restore:

[legend]
Collaboration diagram for Barry::Restore:

[legend]

List of all members.

## Detailed Description

Barry Backup Restore builder class.

This class is suitable to be used as a builder object anywhere a builder object is accepted. It reads from a Barry Backup tar.gz backup file, and builds records in a staged manner.

If a backup file contains more than one database (for example both Address Book and Calendar), then it will build one database first, return false on Retrieve(), and then build the next. If Retrieve() returns false, but EndOfFile() also returns false, then more databases are available.

The idea is that you can call Desktop::SaveDatabase() multiple times with this same Restore object, for all the databases in the backup file.

It is safe to call Retrieve() multiple times, so when first starting a restore:

- call the constructor
- call AddDB() with any filters
- then call Retrieve(), which will grab the first record, and make GetDBName() valid.

Definition at line 64 of file restore.h.

## Public Member Functions

| Restore (const std::string &tarpath, bool default_all_db=true)
| If default_all_db is true, and none of the Add*() functions are called (meaning that Restore has an empty database list), then all records are restored.
void | AddDB (const std::string &dbName)
| Add database name to the read filter.
void | Add (const DBListType &dbList)
| Add all database names in dblist to the read filter This function is additive.
unsigned int | GetRecordTotal () const
| Loads the given file, and counts all records according to the current read filter.
bool | GetNextMeta (DBData &data)
| If this function returns true, it fills data with the meta data that the next call to BuildRecord() will retrieve.
bool | BuildRecord (Barry::DBData &data, size_t &offset, const Barry::IConverter *ic)
| Called to build the record field data.
bool | FetchRecord (Barry::DBData &data, const Barry::IConverter *ic)
| Same as BuildRecord, but does not care about any offsets.
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.

## Static Public Member Functions

static unsigned int | GetRecordTotal (const std::string &tarpath, const DBListType &dbList, bool default_all_db)
| Static version of above call.

## Static Protected Member Functions

static bool | SplitTarPath (const std::string &tarpath, std::string &dbname, std::string &dbid_text, uint8_t &dbrectype, uint32_t &dbid)
| Splits a tarpath of the form "DBName/DBID" into separate string values.

## Constructor & Destructor Documentation

Barry::Restore::Restore | ( | const std::string & | tarpath,
|  | bool | default_all_db = `true` |
| ) |  |  | `[explicit]`

If default_all_db is true, and none of the Add*() functions are called (meaning that Restore has an empty database list), then all records are restored.

If false in this situation, nothing is restored.

If any of the Add*() functions are called, then the database list takes precedence, and default_all_db has no effect.

Definition at line 96 of file restore.cc.

## Member Function Documentation

bool Barry::Restore::SplitTarPath | ( | const std::string & | tarpath,
|  | std::string & | dbname,
|  | std::string & | dbid_text,
|  | uint8_t & | dbrectype,
|  | uint32_t & | dbid |
| ) |  |  | `[static, protected]`

Splits a tarpath of the form "DBName/DBID" into separate string values.

Returns true if successful, false if tarpath is a bad name.

Definition at line 69 of file restore.cc.

void Barry::Restore::AddDB | ( | const std::string & | dbName | ) |

Add database name to the read filter.

Definition at line 133 of file restore.cc.

Referenced by Add().

Here is the caller graph for this function:

void Barry::Restore::Add | ( | const DBListType & | dbList | ) |

Add all database names in dblist to the read filter This function is additive.

Definition at line 141 of file restore.cc.

References AddDB().

Here is the call graph for this function:

unsigned int Barry::Restore::GetRecordTotal | ( |  | ) | const

Loads the given file, and counts all records according to the current read filter.

Does not use the main Restore file, but opens the file separately. It is safe to call this function as often as needed.

Definition at line 167 of file restore.cc.

unsigned int Barry::Restore::GetRecordTotal | ( | const std::string & | tarpath,
|  | const DBListType & | dbList,
|  | bool | default_all_db |
| ) |  |  | `[static]`

Static version of above call.

Definition at line 172 of file restore.cc.

bool Barry::Restore::GetNextMeta | ( | DBData & | data | ) |

If this function returns true, it fills data with the meta data that the next call to BuildRecord() will retrieve.

This is useful for applications that need to setup a manual call to Desktop::SaveDatabase().

Definition at line 192 of file restore.cc.

References Barry::DBData::SetDBName(), Barry::DBData::SetIds(), Barry::DBData::SetOffset(), and Barry::DBData::SetVersion().

Here is the call graph for this function:

bool Barry::Restore::BuildRecord | ( | Barry::DBData & | data,
|  | size_t & | offset,
|  | const Barry::IConverter * | ic |
| ) |  |  | `[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 273 of file restore.cc.

References Barry::DBData::SetDBName(), Barry::DBData::SetIds(), Barry::DBData::SetOffset(), Barry::DBData::SetVersion(), and Barry::DBData::UseData().

Here is the call graph for this function:

bool Barry::Restore::FetchRecord | ( | Barry::DBData & | data,
|  | const Barry::IConverter * | ic |
| ) |  |  | `[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 316 of file restore.cc.

References Barry::DBData::GetData(), Barry::DBData::SetDBName(), Barry::DBData::SetIds(), Barry::DBData::SetOffset(), Barry::DBData::SetVersion(), and Barry::DBData::UseData().

Here is the call graph for this function:

bool Barry::Restore::EndOfFile | ( |  | ) | const`[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 368 of file restore.cc.

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

- restore.h
- restore.cc