
//***************************************************
// Generalised Bitmap Module C++ adapter for GBM plugins
//
// Requires: GBM.DLL version 1.35 or higher (with multipage support)
//
// Copyright (C) 2006-2008 Heiko Nitzsche
//
//   This software is provided 'as-is', without any express or implied
//   warranty.  In no event will the author be held liable for any damages
//   arising from the use of this software.
//
//   Permission is granted to anyone to use this software for any purpose,
//   including commercial applications, and to alter it and redistribute it
//   freely, subject to the following restrictions:
//
//   1. The origin of this software must not be misrepresented; you must not
//      claim that you wrote the original software. If you use this software
//      in a product, an acknowledgment in the product documentation would be
//      appreciated but is not required.
//   2. Altered source versions must be plainly marked as such, and must not be
//      misrepresented as being the original software.
//   3. This notice may not be removed or altered from any source distribution.
//
//***************************************************

#ifndef __CLASS_GBM_ACCESSOR__
    #define __CLASS_GBM_ACCESSOR__

#include "gbm.h"

// ---------------------------------------------------------

class GbmAccessorException
{
    public:
       GbmAccessorException() {}
      ~GbmAccessorException() {}
};

// ---------------------------------------------------------

class GbmAccessor
{
    private:

        char    * moduleName;
        HMODULE   moduleHandle;

        GbmAccessor(const GbmAccessor & accessor);
        GbmAccessor & operator =(const GbmAccessor & accessor);

        BOOLEAN init(const char * dllPath);

        // --- Function prototype for DLL functions ---

      #if defined(__IBMC__) || defined(__IBMCPP__)

          // --- _System variants

          GBM_ERR (* _System fn_Gbm_init)  (void);
          GBM_ERR (* _System fn_Gbm_deinit)(void);

          GBM_ERR (* _System fn_Gbm_version)  (void);
          int     (* _System fn_Gbm_io_open)  (const char *fn, int mode);
          int     (* _System fn_Gbm_io_create)(const char *fn, int mode);
          void    (* _System fn_Gbm_io_close) (int fd);
          long    (* _System fn_Gbm_io_lseek) (int fd, long  pos, int whence);
          int     (* _System fn_Gbm_io_read)  (int fd, void *buf, int len);
          int     (* _System fn_Gbm_io_write) (int fd, const void *buf, int len);

          GBM_ERR (* _System fn_Gbm_query_n_filetypes)(int *n_ft);
          GBM_ERR (* _System fn_Gbm_guess_filetype)   (const char *fn, int *ft);
          GBM_ERR (* _System fn_Gbm_query_filetype)   (int ft, GBMFT *gbmft);

          GBM_ERR (* _System fn_Gbm_read_imgcount)(const char *fn, int fd, int ft, int *pimgcnt);
          GBM_ERR (* _System fn_Gbm_read_header)  (const char *fn, int fd, int ft, GBM *gbm, const char *opt);
          GBM_ERR (* _System fn_Gbm_read_palette) (int fd, int ft, GBM *gbm, GBMRGB *gbmrgb);
          GBM_ERR (* _System fn_Gbm_read_data)    (int fd, int ft, GBM *gbm, byte *data);
          GBM_ERR (* _System fn_Gbm_write)        (const char *fn, int fd, int ft, const GBM *gbm, const GBMRGB *gbmrgb, const byte *data, const char *opt);

          const char * (* _System fn_Gbm_err)(GBM_ERR rc);

      #else

          // --- _System variants

          GBM_ERR (_System * fn_Gbm_init)  (void);
          GBM_ERR (_System * fn_Gbm_deinit)(void);

          GBM_ERR (_System * fn_Gbm_version)  (void);
          int     (_System * fn_Gbm_io_open)  (const char *fn, int mode);
          int     (_System * fn_Gbm_io_create)(const char *fn, int mode);
          void    (_System * fn_Gbm_io_close) (int fd);
          long    (_System * fn_Gbm_io_lseek) (int fd, long  pos, int whence);
          int     (_System * fn_Gbm_io_read)  (int fd, void *buf, int len);
          int     (_System * fn_Gbm_io_write) (int fd, const void *buf, int len);

          GBM_ERR (_System * fn_Gbm_query_n_filetypes)(int *n_ft);
          GBM_ERR (_System * fn_Gbm_guess_filetype)   (const char *fn, int *ft);
          GBM_ERR (_System * fn_Gbm_query_filetype)   (int ft, GBMFT *gbmft);

          GBM_ERR (_System * fn_Gbm_read_imgcount)(const char *fn, int fd, int ft, int *pimgcnt);
          GBM_ERR (_System * fn_Gbm_read_header)  (const char *fn, int fd, int ft, GBM *gbm, const char *opt);
          GBM_ERR (_System * fn_Gbm_read_palette) (int fd, int ft, GBM *gbm, GBMRGB *gbmrgb);
          GBM_ERR (_System * fn_Gbm_read_data)    (int fd, int ft, GBM *gbm, byte *data);
          GBM_ERR (_System * fn_Gbm_write)        (const char *fn, int fd, int ft, const GBM *gbm, const GBMRGB *gbmrgb, const byte *data, const char *opt);

          const char * (_System * fn_Gbm_err)(GBM_ERR rc);

      #endif

    // ---------------------------------------------------------

    public:

        GbmAccessor() throw (GbmAccessorException);
        GbmAccessor(const char * dllPath) throw (GbmAccessorException);

        virtual ~GbmAccessor();

        const char * getModuleName() const;

        // GBM wrapper functions

        int  Gbm_version() const;

        int  Gbm_io_open  (const char *fn, int mode) const;
        int  Gbm_io_create(const char *fn, int mode) const;
        void Gbm_io_close (int fd) const;
        long Gbm_io_lseek (int fd, long  pos, int whence) const;
        int  Gbm_io_read  (int fd, void *buf, int len) const;
        int  Gbm_io_write (int fd, const void *buf, int len) const;

        GBM_ERR Gbm_query_n_filetypes(int *n_ft) const;
        GBM_ERR Gbm_guess_filetype   (const char *fn, int *ft) const;
        GBM_ERR Gbm_query_filetype   (int ft, GBMFT *gbmft) const;

        GBM_ERR Gbm_read_imgcount(const char *fn, int fd, int ft, int *pimgcnt) const;
        GBM_ERR Gbm_read_header  (const char *fn, int fd, int ft, GBM *gbm, const char *opt) const;
        GBM_ERR Gbm_read_palette (int fd, int ft, GBM *gbm, GBMRGB *gbmrgb) const;
        GBM_ERR Gbm_read_data    (int fd, int ft, GBM *gbm, byte *data) const;
        GBM_ERR Gbm_write        (const char *fn, int fd, int ft, const GBM *gbm, const GBMRGB *gbmrgb, const byte *data, const char *opt) const;

        const char * Gbm_err(GBM_ERR rc) const;
};

#endif


