# class cogs::io::DataBlockExporter

## Overview

Enables writing or cogs structures into files. More…

    #include <DataBlockExporter.h>

    class DataBlockExporter {
    public:
        // structs

        struct DataBlockInfo;

        // fields

        static uint8_t VERSION;

        // construction

        DataBlockExporter();
        DataBlockExporter(const std::shared_ptr<DataBlockManager>& datablock_manager);
        DataBlockExporter(const DataBlockExporter&);
        DataBlockExporter(const DataBlockExporter&&);
        virtual ~DataBlockExporter();

        // methods

        DataBlockExporter& operator=(const DataBlockExporter&);
        DataBlockExporter& operator=(const DataBlockExporter&&);
        bool OpenFile(const std::string& filename, bool overwrite_existing = false);
        void CloseFile();
        DataBlockIndex WritePointCloud(const cogs::PointCloud& cloud);
        DataBlockIndex WriteScan(const cogs::Scan& scan);
        DataBlockIndex WriteMesh(const cogs::Mesh& mesh);
    };

## Detailed Documentation

Enables writing or cogs structures into files.

Objects and data blocks for export are stored in the export list, and have to be valid until file is saved. Each object can be represented by one or multiple data blocks.

By default, exporter supports only predefined data blocks, but can be altered to support also custom data blocks, when user-defined DataBlockManager is provided during class construction.

For more information about cogs file io system, see page cogs-file-format.

### Fields

    static uint8_t VERSION

Current exporter version.

### Construction

    DataBlockExporter()

Creates exporter with default DataBlockManager object.

    DataBlockExporter(const std::shared_ptr<DataBlockManager>& datablock_manager)

Creates exporter with custom DataBlockManager object.

### Methods

    bool OpenFile(const std::string& filename, bool overwrite_existing = false)

Opens file into which the data blocks can be written.

Parameters:

filename | Name of the file. When extension is not provided, sets to “cogs”.
overwrite_existing | Set to true is you wish to rewrite the file that already exists.

Returns:

True, if the file was successfully opened and can be used for writing.

    void CloseFile()

Finishes and closes currently opened file, disabling writers.

    DataBlockIndex WritePointCloud(const cogs::PointCloud& cloud)

Adds the object to the export list.

Parameters:

object_ref | Reference to object. Must be valid until saved.

Returns:

Index of data block for added object type.

    DataBlockIndex WriteScan(const cogs::Scan& scan)

Adds the object to the export list.

Parameters:

object_ref | Reference to object. Must be valid until saved.

Returns:

Index of data block for added object type.

    DataBlockIndex WriteMesh(const cogs::Mesh& mesh)

Adds the object to the export list.

Parameters:

object_ref | Reference to object. Must be valid until saved.

Returns:

Index of data block for added object type.