7fd59977 |
1 | // File: LDOM_MemManager.hxx |
2 | // Created: 26.06.01 11:30:08 |
3 | // Author: Alexander GRIGORIEV |
4 | // Copyright: OpenCascade 2001 |
5 | |
6 | |
7 | #ifndef LDOM_MemManager_HeaderFile |
8 | #define LDOM_MemManager_HeaderFile |
9 | |
10 | #include <MMgt_TShared.hxx> |
11 | #include <Standard_DefineHandle.hxx> |
12 | #include <LDOM_Document.hxx> |
13 | |
14 | class LDOM_BasicElement; |
15 | |
16 | // Class LDOM_MemManager (underlying structure of LDOM_Document) |
17 | // |
18 | |
19 | class LDOM_MemManager : public MMgt_TShared |
20 | { |
21 | public: |
22 | // ---------- PUBLIC METHODS ---------- |
23 | |
24 | Standard_EXPORT LDOM_MemManager (const Standard_Integer aBlockSize); |
25 | // Constructor |
26 | |
27 | Standard_EXPORT ~LDOM_MemManager (); |
28 | // Destructor |
29 | |
30 | Standard_EXPORT void * Allocate (const Standard_Integer aSize); |
31 | // General Memory allocator |
32 | |
33 | const char * HashedAllocate (const char * aString, |
34 | const Standard_Integer theLen, |
35 | Standard_Integer& theHash); |
36 | // Memory allocation with access via hash table. No new allocation |
37 | // if already present |
38 | |
39 | void HashedAllocate (const char * aString, |
40 | const Standard_Integer theLen, |
41 | LDOMBasicString& theResult); |
42 | // Memory allocation with access via hash table. No new allocation |
43 | // if already present |
44 | |
45 | static Standard_Integer Hash (const char * theString, |
46 | const Standard_Integer theLen) |
47 | { return HashTable::Hash (theString, theLen); } |
48 | |
49 | static Standard_Boolean CompareStrings(const char * theString, |
50 | const Standard_Integer theHashValue, |
51 | const char * theHashedStr); |
52 | |
53 | LDOM_Document Doc () const |
54 | { return LDOM_Document (* this); } |
55 | |
56 | const LDOM_MemManager& Self () const |
57 | { return * this; } |
58 | |
59 | const LDOM_BasicElement * RootElement () const |
60 | { return myRootElement; } |
61 | |
62 | private: |
63 | friend class LDOM_Document; |
64 | friend class LDOMParser; |
65 | |
66 | // ---- CLASS MemBlock ---- |
67 | class MemBlock { |
68 | friend class LDOM_MemManager; |
69 | inline MemBlock (const Standard_Integer aSize, MemBlock * aFirst); |
70 | inline void * Allocate (const Standard_Integer aSize); |
71 | void * AllocateAndCheck (const Standard_Integer aSize, const MemBlock *&); |
72 | ~MemBlock (); |
73 | MemBlock * Next () { return myNext; } |
74 | |
75 | Standard_Integer mySize; |
76 | Standard_Integer * myBlock; |
77 | Standard_Integer * myEndBlock; |
78 | Standard_Integer * myFreeSpace; |
79 | MemBlock * myNext; |
80 | }; |
81 | |
82 | // ---- CLASS HashTable ---- |
83 | class HashTable { |
84 | friend class LDOM_MemManager; |
85 | HashTable (/* const Standard_Integer theMask, */ |
86 | LDOM_MemManager& theMemManager); |
87 | const char * AddString (const char * theString, |
88 | const Standard_Integer theLen, |
89 | Standard_Integer& theHashIndex); |
90 | static Standard_Integer Hash(const char * theString, |
91 | const Standard_Integer theLen); |
92 | struct TableItem { |
93 | char * str; |
94 | struct TableItem * next; |
95 | } * myTable; |
96 | // Standard_Integer myMask; |
97 | LDOM_MemManager& myManager; |
98 | }; |
99 | |
100 | // ---- PROHIBITED (PRIVATE) METHODS ---- |
101 | LDOM_MemManager (const LDOM_MemManager& theOther); |
102 | // Copy constructor |
103 | |
104 | LDOM_MemManager& operator = (const LDOM_MemManager& theOther); |
105 | // Assignment |
106 | |
107 | // ---------- PRIVATE FIELDS ---------- |
108 | |
109 | const LDOM_BasicElement * myRootElement; |
110 | MemBlock * myFirstBlock; |
111 | MemBlock * myFirstWithoutRoom; |
112 | Standard_Integer myBlockSize; |
113 | HashTable * myHashTable; |
114 | |
115 | public: |
116 | // CASCADE RTTI |
117 | DEFINE_STANDARD_RTTI (LDOM_MemManager) |
118 | }; |
119 | |
120 | #include <Handle_LDOM_MemManager.hxx> |
121 | |
122 | #endif |