b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | #ifndef _Storage_BucketOfPersistent_HeaderFile |
16 | #define _Storage_BucketOfPersistent_HeaderFile |
17 | |
18 | #include <Standard_Integer.hxx> |
19 | #include <Standard_Persistent.hxx> |
20 | |
21 | class Storage_Schema; |
22 | class Storage_BucketOfPersistent; |
23 | class Storage_BucketIterator; |
24 | |
25 | class Storage_Bucket { |
26 | friend class Storage_BucketIterator; |
27 | friend class Storage_Schema; |
28 | friend class Storage_BucketOfPersistent; |
29 | |
30 | Standard_Persistent** mySpace; |
31 | Standard_Integer mySpaceSize; |
32 | Standard_Integer myCurrentSpace; |
33 | |
34 | |
35 | void Append(Standard_Persistent *); |
36 | |
37 | Standard_Persistent* Value(const Standard_Integer theIndex) const; |
38 | |
39 | public: |
40 | Storage_Bucket() : mySpace(0L), mySpaceSize(200000), myCurrentSpace(-1) |
41 | { |
1c35b92f |
42 | mySpace = (Standard_Persistent**)Standard::Allocate(sizeof(Standard_Persistent*) * mySpaceSize); |
7fd59977 |
43 | } |
44 | |
45 | Storage_Bucket(const Standard_Integer theSpaceSize) : mySpace(0L), mySpaceSize(theSpaceSize), myCurrentSpace(-1) |
46 | { |
1c35b92f |
47 | mySpace = (Standard_Persistent**)Standard::Allocate(sizeof(Standard_Persistent*) * mySpaceSize); |
7fd59977 |
48 | } |
49 | |
50 | void Clear(); |
51 | |
52 | ~Storage_Bucket(); |
53 | }; |
54 | |
55 | |
56 | class Storage_BucketOfPersistent { |
57 | friend class Storage_BucketIterator; |
58 | Storage_Bucket** myBuckets; |
59 | Standard_Integer myNumberOfBucket; |
60 | Standard_Integer myNumberOfBucketAllocated; |
61 | Storage_Bucket* myCurrentBucket; |
62 | Standard_Integer myCurrentBucketNumber; |
63 | Standard_Integer myLength; |
64 | Standard_Integer myBucketSize; |
65 | |
66 | public: |
67 | Storage_BucketOfPersistent(const Standard_Integer theBucketSize = 300000, const Standard_Integer theBucketNumber = 100); |
68 | |
69 | Standard_Integer Length() const |
70 | { |
71 | return myLength; |
72 | } |
73 | |
74 | void Append(const Handle(Standard_Persistent)& sp); |
75 | |
76 | Standard_Persistent* Value(const Standard_Integer theIndex); |
77 | |
78 | void Clear(); |
79 | |
80 | ~Storage_BucketOfPersistent() ; |
81 | |
82 | }; |
83 | |
84 | class Storage_BucketIterator { |
85 | Storage_BucketOfPersistent *myBucket; |
86 | Storage_Bucket *myCurrentBucket; |
87 | Standard_Integer myCurrentBucketIndex; |
88 | Standard_Integer myCurrentIndex; |
89 | Standard_Integer myBucketNumber; |
90 | Standard_Boolean myMoreObject; |
91 | |
92 | public: |
93 | Storage_BucketIterator(Storage_BucketOfPersistent*); |
94 | void Init(Storage_BucketOfPersistent*); |
95 | void Reset(); |
96 | |
97 | Standard_Persistent* Value() const |
98 | { |
99 | if (myCurrentBucket) { |
100 | return myCurrentBucket->mySpace[myCurrentIndex]; |
101 | } |
102 | else return 0L; |
103 | } |
104 | |
105 | Standard_Boolean More() const |
106 | { |
107 | return myMoreObject; |
108 | } |
109 | |
110 | void Next(); |
111 | }; |
112 | |
113 | #endif |