| ThorVG v0.5

Public Member Functions | Static Public Member Functions | List of all members
Saver
ThorVG

A class for exporting a paint object into a specified file, from which to recover the paint data later. More...

## Public Member Functions
Result | save (std::unique_ptr< Paint > paint, const std::string &path, bool compress=true) noexcept
| Exports the given `paint` data to the given `path`. More...
Result | sync () noexcept
| Guarantees that the saving task is finished. More...

## Static Public Member Functions
static std::unique_ptr< Saver > | gen () noexcept
| Creates a new Saver object. More...

## Detailed Description

A class for exporting a paint object into a specified file, from which to recover the paint data later.

ThorVG provides a feature for exporting & importing paint data, the Saver has a role to export it to a file. Basically, this feature is useful when you need to save the composed scene or image from a paint object and recreate it later.

The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment. If it doesn't support the file format, it will return the `NonSuppport` result by the save() method.

Once you export a paint to the file successfully, you can recreate it using the Picture class.

See also
  Picture::load()

Since
  0.5

## Member Function Documentation

## ◆ gen()

static std::unique_ptr<Saver> gen | ( |  | ) |
| static noexcept

Creates a new Saver object.

Returns
  A new Saver object.

Since
  0.5

## ◆ save()

Result save | ( | std::unique_ptr< Paint > | paint,
|  | const std::string & | path,
|  | bool | compress = `true`
| ) |  |
| noexcept

Exports the given `paint` data to the given `path`.

If the saver module supports any compression mechanism, it will optimize the data size. This might affect the encoding/decoding time slow down in cases, You can turn off the compression if your system whole focus on the speed.

Parameters

  [in] | paint | The paint to be saved with all its associated properties.
  [in] | path | A path to the file, in which the paint data is to be saved.
  [in] | compress | Use data compression if it's available.

Return values

  Result::Success | When succeed.
  Result::NonSupport | When trying to save a file with an unknown extension nor non supported format.
  Result::Unknown | Others.

Note
  Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards.

See also
  Saver::sync()

Since
  0.5

## ◆ sync()

Result sync | ( |  | ) |
| noexcept

Guarantees that the saving task is finished.

The behavior of the saver will work on a sync/async basis, depending on the threading setting of the Initializer. Thus if you wish to have a benefit of it, you must call sync() after the save() in the proper delayed time. Otherwise, you can call sync() immediately.

Returns
  Result::Success when succeed.
  Result::InsufficientCondition otherwise.

Note
  The asynchronous tasking is depend on the saver module implementation.

See also
  Saver::save()

Since
  0.5