// custom.h --
// This is part of Metakit, the homepage is http://www.equi4.com/metakit.html

/** @file
 * Encapsulation of many custom viewer classes
 */

#ifndef __CUSTOM_H__
#define __CUSTOM_H__

#ifndef __FIELD_H__
#include "field.h"
#endif
#ifndef __STORE_H__
#include "handler.h"
#endif

/////////////////////////////////////////////////////////////////////////////

class c4_CustomSeq: public c4_HandlerSeq
{
    c4_CustomViewer *_viewer;
    bool _inited;

public:
    c4_CustomSeq(c4_CustomViewer *viewer_);
    virtual ~c4_CustomSeq();

    int NumRows()const Q_DECL_OVERRIDE;

    bool RestrictSearch(c4_Cursor, int &, int &) Q_DECL_OVERRIDE;

    void InsertAt(int, c4_Cursor, int = 1) Q_DECL_OVERRIDE;
    void RemoveAt(int, int = 1) Q_DECL_OVERRIDE;
    void Move(int from_, int) Q_DECL_OVERRIDE;

    bool DoGet(int row_, int col_, c4_Bytes &buf_)const;
    void DoSet(int row_, int col_, const c4_Bytes &buf_);

private:
    // this *is* used, as Q_DECL_OVERRIDE
    c4_Handler *CreateHandler(const c4_Property &) Q_DECL_OVERRIDE;
};

/////////////////////////////////////////////////////////////////////////////

extern c4_CustomViewer *f4_CustSlice(c4_Sequence &, int, int, int);
extern c4_CustomViewer *f4_CustProduct(c4_Sequence &, const c4_View &);
extern c4_CustomViewer *f4_CustRemapWith(c4_Sequence &, const c4_View &);
extern c4_CustomViewer *f4_CustPair(c4_Sequence &, const c4_View &);
extern c4_CustomViewer *f4_CustConcat(c4_Sequence &, const c4_View &);
extern c4_CustomViewer *f4_CustRename(c4_Sequence &, const c4_Property &, const
                                      c4_Property &);
extern c4_CustomViewer *f4_CustGroupBy(c4_Sequence &, const c4_View &, const
                                       c4_Property &);
extern c4_CustomViewer *f4_CustJoinProp(c4_Sequence &, const c4_ViewProp &,
                                        bool);
extern c4_CustomViewer *f4_CustJoin(c4_Sequence &, const c4_View &, const
                                    c4_View &, bool);

/////////////////////////////////////////////////////////////////////////////

#endif
