/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2003-2012, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2003-2012 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////

#ifndef _EX_DBUNDOCONTROLLER_H_
#define _EX_DBUNDOCONTROLLER_H_

#include "TD_PackPush.h"
#include "DbUndoController.h"
#include "UInt8Array.h"
#include "OdList.h"
/** Description:
  This class implements platform-independent UndoController objects.
  
  {group:ExServices_Classes} Library: Source provided. 
*/
class ExUndoController : public OdDbUndoController
{
  OdList<OdUInt8Array>  m_records;
  OdUInt32              m_nMemoryUsed;

  OdUInt32              m_nMaxSteps;
  OdUInt32              m_nMaxMemory;
protected:
  ExUndoController();

  /** Description:
    Frees the first record of this UndoController object.
  */
  void freeFrontRecord();
  
  /** Description:
    Frees the last record of this UndoController object.
  */
  void freeBackRecord();
  
  /** Description:
    Returns the memory size (in bytes) of the first record of this UndoController object.
  */
  OdUInt32 frontRecordMemory() const;

  /** Description:
    Returns the memory size (in bytes) of the last record of this UndoController object.
  */
  OdUInt32 backRecordMemory() const;

  /** Description:
    Returns the memory size (in bytes) required for a record with the specified data size.
    Arguments:
    dataSize (I) Data size (in bytes).
  */
  static OdUInt32 recordMemory(OdUInt32 dataSize);
  
  /** Description:
    Frees extra memory from this UndoController object.
    Remarks:
    Frees front records until the memory size and number of records of the 
    UndoControler list is less that that specified by the limits.
  */
  void freeExtra();
  
  /** Description:
     Adds a record of the specifed size to the end of this UndoController object. 
     Remarks:
     Returns true if and only if successful. 
  */
  bool pushRecord(OdUInt32 nSizeOfRecToAppend);
public:
  /** Description:
    Sets the limits of this UndoController object.
    Arguments:
    maxSteps (I) Maximum number of records.
    maxMemory (I) Maximum memory in bytes.
  */
  void setLimits(OdUInt32 maxSteps, OdUInt32 maxMemory);

  /** Description:
    Adds the specified number of bytes from the specified StreamBuf object
    to the end of this UndoController object.
    Arguments:
    pStreamBuf (I) Pointer to the StreamBuf object from which the data are to be read.
    numBytes (I) Number of bytes to be read.   
  */
  void pushData(OdStreamBuf* pStreamBuf, OdUInt32 numBytes, OdUInt32 opt);

  /** Description:
    Returns true if and only if this UndoController object is not empty.
  */
  bool hasData() const;
  
  /** Description
    Writes the record at the end of this UndoController object to the specified
    StreamBuf object.
    Arguments:
    pStreamBuf (I) Pointer to the StreamBuf object to which the data are to be written.
    
  */ 
  OdUInt32 popData(OdStreamBuf* pStreamBuf);

  OdRxIteratorPtr newRecordStackIterator() const;
  
  void clearData();
};
#include "TD_PackPop.h"

#endif // _EX_DBUNDOCONTROLLER_H_
