# gcu::Loader Class Reference

class used to implement serialization engines. More...

`#include <gcu/loader.h>`

List of all members.

## Public Member Functions

| Loader ()
virtual | ~Loader ()
virtual bool | Read (Document *doc, GsfInput *in, char const *mime_type, IOContext *io)
virtual bool | Write (Document *doc, GsfOutput *out, char const *mime_type, IOContext *io)

## Static Public Member Functions

static void | Init ()
static bool | GetFirstLoader (std::map< std::string, LoaderStruct >::iterator &it)
static bool | GetNextLoader (std::map< std::string, LoaderStruct >::iterator &it)
static Loader * | GetLoader (char const *mime_type)
static Loader * | GetSaver (char const *mime_type)

## Protected Member Functions

void | AddMimeType (const char *mime_type)
void | RemoveMimeType (const char *mime_type)

## Protected Attributes

std::list< std::string > | MimeTypes

## Detailed Description

class used to implement serialization engines.

This class is used to load and save files of various types, using the gcu::Object framework. Derived classes should be implemented in plugins, using the goffice plugins API. When Loader::Init is called, the framework collects informations about the services exposed by each plugin in XML files. For the CDX file loader plugin, the corresponding plugin.xml.in file content is:

    <?xml version="1.0" encoding="UTF-8"?>
    <plugin id="GCULoader_cdxml">
            <information>
                    <_name>Loader : cdxml</_name>
                    <_description>Chemdraw XML files loader.</_description>
            </information>
            <loader type="Gnumeric_Builtin:module">
                    <attribute name="module_file" value="cdxml"/>
            </loader>
            <services>
                    <service type="chemical_loader" id="GCULoader_cdxml">
                            <mime_type name="chemical/x-cdxml" capabilities="r" scope="2"/>
                            <information>
                                    <_description>Chemdraw XML files loader</_description>
                            </information>
                    </service>
            </services>
    </plugin>

In the present context, the important node is the mime type related one. Its attributes are:

- name: the mime type.
- capabilities: what is supported: r for reading, w for writing. Both "rw" and "wr" are valid.
- scope: 2 and 3 mean 2D and 3D structures, repectively, c means crystal structure, and s, spectra . Any combination might be used.

Other fields are standard in the goffice world. The plugin is loaded only when needed.

Each plugin should implement at least one derived class and a static instance of this class. The CDX loader has:

    class CDXLoader: public gcu::Loader
    {
    public:
            CDXLoader ();
            virtual ~CDXLoader ();

            bool Read (Document *doc, GsfInput *in, char const *mime_type, IOContext *io);
            bool Write (Document *doc, GsfOutput *out, char const *mime_type, IOContext *io);

    private:
            ...
    };

    ...
    static CDXLoader loader;

Definition at line 142 of file loader.h.

## Constructor & Destructor Documentation

gcu::Loader::Loader | ( |  | ) |

The constructor. Derived class need to call Loader::AddMimeType for each mime type they support.

virtual gcu::Loader::~Loader | ( |  | ) | `[virtual]`

The destructor Derived class should call Loader::RemoveMimeType for each mime type they support.

## Member Function Documentation

static void gcu::Loader::Init | ( |  | ) | `[static]`

Initializes the load/save engines system. This must be called before trying to use any loader (no one will be available before, anyway).

static bool gcu::Loader::GetFirstLoader | ( | std::map< std::string, LoaderStruct >::iterator & | it | ) | `[static]`

Parameters:

  | it | a std::map iterator.

Must be called to access the first LoaderStruct instance. When successful the iterator can be used to retrieve both the mime type ((*it).first), and the corresponding LoaderStruct ((*it).second)

Returns:
  true if successful, false otherwise.

static bool gcu::Loader::GetNextLoader | ( | std::map< std::string, LoaderStruct >::iterator & | it | ) | `[static]`

Parameters:

  | it | a std::map iterator initialized by Loader::GetFirstLoader

Gets the next LoderStruct and its associated mime type.

Returns:
  true if successful, false otherwise.

static Loader* gcu::Loader::GetLoader | ( | char const * | mime_type | ) | `[static]`

Parameters:

  | mime_type | a mime type.

Returns:
  the Loader instance able to read the mime type if any.

static Loader* gcu::Loader::GetSaver | ( | char const * | mime_type | ) | `[static]`

Parameters:

  | mime_type | a mime type.

Returns:
  the Loader instance able to write the mime type if any.

virtual bool gcu::Loader::Read | ( | Document * | doc,
|  | GsfInput * | in,
|  | char const * | mime_type,
|  | IOContext * | io |
| ) |  |  | `[virtual]`

Parameters:

  | doc | the gcu::Document being read.
  | in | a GsfInput (see the libgsf documentation at http://library.gnome.org/devel/gsf/stable/gsf-Input-from-unstructured-files.html#GsfInput).
  | mime_type | the mime type of the data.
  | io | a GOffice IOContext.

This function must be overloaded by a derived class able to read. Default implementation just return false.

Returns:
  true on success, false otherwise.

virtual bool gcu::Loader::Write | ( | Document * | doc,
|  | GsfOutput * | out,
|  | char const * | mime_type,
|  | IOContext * | io |
| ) |  |  | `[virtual]`

Parameters:

  | doc | the gcu::Document being written.
  | out | a GsfOutput (see the libgsf documentation at http://library.gnome.org/devel/gsf/stable/gsf-Output-to-unstructured-files.html#GsfOutput).
  | mime_type | the mime type of the data.
  | io | a GOffice IOContext.

This function must be overloaded by a derived class able to write. Default implementation just return false.

Returns:
  true on success, false otherwise.

void gcu::Loader::AddMimeType | ( | const char * | mime_type | ) | `[protected]`

Parameters:

  | mime_type | a mime type.

Registers a mime type and stores the instance calling it as the Loader for this mime type.

void gcu::Loader::RemoveMimeType | ( | const char * | mime_type | ) | `[protected]`

Parameters:

  | mime_type | a mime type.

Unregisters a mime type.

## Member Data Documentation

std::list<std::string> gcu::Loader::MimeTypes `[protected]`

The list of supported mime types.

Definition at line 236 of file loader.h.

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

- loader.h