b311480e |
1 | // Created on: 2001-06-26 |
2 | // Created by: Alexander GRIGORIEV |
3 | // Copyright (c) 2001-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | |
22 | #ifndef LDOM_MemManager_HeaderFile |
23 | #define LDOM_MemManager_HeaderFile |
24 | |
25 | #include <MMgt_TShared.hxx> |
26 | #include <Standard_DefineHandle.hxx> |
27 | #include <LDOM_Document.hxx> |
28 | |
29 | class LDOM_BasicElement; |
30 | |
31 | // Class LDOM_MemManager (underlying structure of LDOM_Document) |
32 | // |
33 | |
34 | class LDOM_MemManager : public MMgt_TShared |
35 | { |
36 | public: |
37 | // ---------- PUBLIC METHODS ---------- |
38 | |
39 | Standard_EXPORT LDOM_MemManager (const Standard_Integer aBlockSize); |
40 | // Constructor |
41 | |
42 | Standard_EXPORT ~LDOM_MemManager (); |
43 | // Destructor |
44 | |
45 | Standard_EXPORT void * Allocate (const Standard_Integer aSize); |
46 | // General Memory allocator |
47 | |
48 | const char * HashedAllocate (const char * aString, |
49 | const Standard_Integer theLen, |
50 | Standard_Integer& theHash); |
51 | // Memory allocation with access via hash table. No new allocation |
52 | // if already present |
53 | |
54 | void HashedAllocate (const char * aString, |
55 | const Standard_Integer theLen, |
56 | LDOMBasicString& theResult); |
57 | // Memory allocation with access via hash table. No new allocation |
58 | // if already present |
59 | |
60 | static Standard_Integer Hash (const char * theString, |
61 | const Standard_Integer theLen) |
62 | { return HashTable::Hash (theString, theLen); } |
63 | |
64 | static Standard_Boolean CompareStrings(const char * theString, |
65 | const Standard_Integer theHashValue, |
66 | const char * theHashedStr); |
67 | |
68 | LDOM_Document Doc () const |
69 | { return LDOM_Document (* this); } |
70 | |
71 | const LDOM_MemManager& Self () const |
72 | { return * this; } |
73 | |
74 | const LDOM_BasicElement * RootElement () const |
75 | { return myRootElement; } |
76 | |
77 | private: |
78 | friend class LDOM_Document; |
79 | friend class LDOMParser; |
80 | |
81 | // ---- CLASS MemBlock ---- |
82 | class MemBlock { |
83 | friend class LDOM_MemManager; |
84 | inline MemBlock (const Standard_Integer aSize, MemBlock * aFirst); |
85 | inline void * Allocate (const Standard_Integer aSize); |
86 | void * AllocateAndCheck (const Standard_Integer aSize, const MemBlock *&); |
87 | ~MemBlock (); |
88 | MemBlock * Next () { return myNext; } |
89 | |
90 | Standard_Integer mySize; |
91 | Standard_Integer * myBlock; |
92 | Standard_Integer * myEndBlock; |
93 | Standard_Integer * myFreeSpace; |
94 | MemBlock * myNext; |
95 | }; |
96 | |
97 | // ---- CLASS HashTable ---- |
98 | class HashTable { |
99 | friend class LDOM_MemManager; |
100 | HashTable (/* const Standard_Integer theMask, */ |
101 | LDOM_MemManager& theMemManager); |
102 | const char * AddString (const char * theString, |
103 | const Standard_Integer theLen, |
104 | Standard_Integer& theHashIndex); |
105 | static Standard_Integer Hash(const char * theString, |
106 | const Standard_Integer theLen); |
107 | struct TableItem { |
108 | char * str; |
109 | struct TableItem * next; |
110 | } * myTable; |
7fd59977 |
111 | LDOM_MemManager& myManager; |
d390b166 |
112 | void operator= (const HashTable&); |
7fd59977 |
113 | }; |
114 | |
115 | // ---- PROHIBITED (PRIVATE) METHODS ---- |
116 | LDOM_MemManager (const LDOM_MemManager& theOther); |
117 | // Copy constructor |
118 | |
119 | LDOM_MemManager& operator = (const LDOM_MemManager& theOther); |
120 | // Assignment |
121 | |
122 | // ---------- PRIVATE FIELDS ---------- |
123 | |
124 | const LDOM_BasicElement * myRootElement; |
125 | MemBlock * myFirstBlock; |
126 | MemBlock * myFirstWithoutRoom; |
127 | Standard_Integer myBlockSize; |
128 | HashTable * myHashTable; |
129 | |
130 | public: |
131 | // CASCADE RTTI |
132 | DEFINE_STANDARD_RTTI (LDOM_MemManager) |
133 | }; |
134 | |
135 | #include <Handle_LDOM_MemManager.hxx> |
136 | |
137 | #endif |