// SingleCharInsertOrDeleteOp.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2005

#ifndef Ceda_OpTrans_OpTransTest_SingleCharInsertOrDeleteOp_H
#define Ceda_OpTrans_OpTransTest_SingleCharInsertOrDeleteOp_H

#include "Opid.h"

struct StringDocSet;

///////////////////////////////////////////////////////////////////////////////////////////////////
// SingleCharInsertOrDeleteOp

struct SingleCharInsertOrDeleteOp
{
    SingleCharInsertOrDeleteOp();

    SiteId GetId() const { return m_opid.id; }

    typedef StringDocSet OpDocSet;

    void Do(StringDocSet& ds) const;
    void Undo(StringDocSet& ds) const;

    bool operator==(const SingleCharInsertOrDeleteOp& rhs) const;

    struct RandomInitSettings
    {
        RandomInitSettings()
        {
        }
    };
    void SetRandom(RandomInitSettings ris, const OpDocSet& ds, Opid opid);

    //////////////// State ///////////////////

    Opid m_opid;
    bool ins;       // true for insert operation, false for delete operation
    bool enabled;   // Is the operation enabled?
    ssize_t buf;        // Identifies document in which insertion is to be made
    ssize_t p;          // Insertion/deletion position in the document
    ssize_t q;          // Effects position
    xchar c;         // Character inserted/deleted by the operation
};

xostream& operator<<(xostream& os, const SingleCharInsertOrDeleteOp& O);

void IT(SingleCharInsertOrDeleteOp& O1, const SingleCharInsertOrDeleteOp& O2);
void ET(SingleCharInsertOrDeleteOp& O1, const SingleCharInsertOrDeleteOp& O2);

void DualIT(SingleCharInsertOrDeleteOp& O1, SingleCharInsertOrDeleteOp& O2);
void Transpose(SingleCharInsertOrDeleteOp& O1, SingleCharInsertOrDeleteOp& O2);

void Merge(SingleCharInsertOrDeleteOp& O1, const SingleCharInsertOrDeleteOp& O2);

#endif // include guard
