1// store.h --
2// $Id: store.h 1230 2007-03-09 15:58:53Z jcw $
3// This is part of Metakit, see http://www.equi4.com/metakit.html
4
5/** @file
6 * Definition of auxiliary storage management classes
7 */
8
9#ifndef __STORE_H__
10#define __STORE_H__
11
12/////////////////////////////////////////////////////////////////////////////
13
14class c4_Dependencies {
15    c4_PtrArray _refs;
16
17  public:
18    c4_Dependencies();
19    ~c4_Dependencies();
20
21    void Add(c4_Sequence *seq_);
22    bool Remove(c4_Sequence *seq_);
23
24    friend class c4_Notifier;
25};
26
27/////////////////////////////////////////////////////////////////////////////
28
29class c4_Notifier {
30    c4_Sequence *_origin;
31    c4_Notifier *_chain;
32    c4_Notifier *_next;
33
34  public:
35    enum {
36        kNone, kSetAt, kInsertAt, kRemoveAt, kMove, kSet, kLimit
37    };
38
39    c4_Notifier(c4_Sequence *origin_);
40    ~c4_Notifier();
41
42    bool HasDependents()const;
43
44    void StartSetAt(int index_, c4_Cursor &cursor_);
45    void StartInsertAt(int index_, c4_Cursor &cursor_, int count_);
46    void StartRemoveAt(int index_, int count_);
47    void StartMove(int from_, int to_);
48    void StartSet(int index_, int propId_, const c4_Bytes &buf_);
49
50    int _type;
51    int _index;
52    int _propId;
53    int _count;
54    c4_Cursor *_cursor;
55    const c4_Bytes *_bytes;
56
57  private:
58    void Notify();
59};
60
61/////////////////////////////////////////////////////////////////////////////
62
63class c4_DerivedSeq: public c4_Sequence {
64  protected:
65    c4_Sequence &_seq;
66
67  protected:
68    c4_DerivedSeq(c4_Sequence &seq_);
69    virtual ~c4_DerivedSeq();
70
71  public:
72    virtual int RemapIndex(int, const c4_Sequence*)const;
73
74    virtual int NumRows()const;
75    virtual void SetNumRows(int size_);
76
77    virtual int NumHandlers()const;
78    virtual c4_Handler &NthHandler(int)const;
79    virtual const c4_Sequence *HandlerContext(int)const;
80    virtual int AddHandler(c4_Handler*);
81    virtual c4_Handler *CreateHandler(const c4_Property &);
82
83    virtual c4_Notifier *PreChange(c4_Notifier &nf_);
84};
85
86/////////////////////////////////////////////////////////////////////////////
87
88class c4_StreamStrategy: public c4_Strategy {
89    c4_Stream *_stream;
90    t4_byte *_buffer;
91    t4_i32 _buflen;
92    t4_i32 _position;
93  public:
94    c4_StreamStrategy(t4_i32 buflen_);
95    c4_StreamStrategy(c4_Stream *stream_);
96    virtual ~c4_StreamStrategy();
97
98    virtual bool IsValid()const;
99    virtual int DataRead(t4_i32 pos_, void *buffer_, int length_);
100    virtual void DataWrite(t4_i32 pos_, const void *buffer_, int length_);
101    virtual t4_i32 FileSize();
102};
103
104/////////////////////////////////////////////////////////////////////////////
105
106#if q4_INLINE
107#include "store.inl"
108#endif
109
110/////////////////////////////////////////////////////////////////////////////
111
112#endif
113