b311480e |
1 | // Created on: 2001-06-26 |
2 | // Created by: Alexander GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #ifndef LDOM_MemManager_HeaderFile |
17 | #define LDOM_MemManager_HeaderFile |
18 | |
25e59720 |
19 | #include <Standard_Transient.hxx> |
ec357c5c |
20 | #include <Standard_Type.hxx> |
7fd59977 |
21 | |
e8862cf4 |
22 | class LDOM_Document; |
7fd59977 |
23 | class LDOM_BasicElement; |
c04c30b3 |
24 | class LDOM_MemManager; |
e8862cf4 |
25 | class LDOMBasicString; |
c04c30b3 |
26 | |
27 | // Define handle class for LDOM_MemManager |
25e59720 |
28 | DEFINE_STANDARD_HANDLE (LDOM_MemManager, Standard_Transient) |
7fd59977 |
29 | |
30 | // Class LDOM_MemManager (underlying structure of LDOM_Document) |
31 | // |
32 | |
25e59720 |
33 | class LDOM_MemManager : public Standard_Transient |
7fd59977 |
34 | { |
35 | public: |
36 | // ---------- PUBLIC METHODS ---------- |
37 | |
38 | Standard_EXPORT LDOM_MemManager (const Standard_Integer aBlockSize); |
39 | // Constructor |
40 | |
41 | Standard_EXPORT ~LDOM_MemManager (); |
42 | // Destructor |
43 | |
44 | Standard_EXPORT void * Allocate (const Standard_Integer aSize); |
45 | // General Memory allocator |
46 | |
47 | const char * HashedAllocate (const char * aString, |
48 | const Standard_Integer theLen, |
49 | Standard_Integer& theHash); |
50 | // Memory allocation with access via hash table. No new allocation |
51 | // if already present |
52 | |
53 | void HashedAllocate (const char * aString, |
54 | const Standard_Integer theLen, |
55 | LDOMBasicString& theResult); |
56 | // Memory allocation with access via hash table. No new allocation |
57 | // if already present |
58 | |
59 | static Standard_Integer Hash (const char * theString, |
60 | const Standard_Integer theLen) |
61 | { return HashTable::Hash (theString, theLen); } |
62 | |
63 | static Standard_Boolean CompareStrings(const char * theString, |
64 | const Standard_Integer theHashValue, |
65 | const char * theHashedStr); |
66 | |
e8862cf4 |
67 | // LDOM_Document Doc () const |
68 | // { return LDOM_Document (* this); } |
7fd59977 |
69 | |
70 | const LDOM_MemManager& Self () const |
71 | { return * this; } |
72 | |
73 | const LDOM_BasicElement * RootElement () const |
74 | { return myRootElement; } |
75 | |
76 | private: |
77 | friend class LDOM_Document; |
78 | friend class LDOMParser; |
79 | |
80 | // ---- CLASS MemBlock ---- |
81 | class MemBlock { |
82 | friend class LDOM_MemManager; |
83 | inline MemBlock (const Standard_Integer aSize, MemBlock * aFirst); |
84 | inline void * Allocate (const Standard_Integer aSize); |
85 | void * AllocateAndCheck (const Standard_Integer aSize, const MemBlock *&); |
86 | ~MemBlock (); |
87 | MemBlock * Next () { return myNext; } |
88 | |
89 | Standard_Integer mySize; |
90 | Standard_Integer * myBlock; |
91 | Standard_Integer * myEndBlock; |
92 | Standard_Integer * myFreeSpace; |
93 | MemBlock * myNext; |
94 | }; |
95 | |
96 | // ---- CLASS HashTable ---- |
97 | class HashTable { |
98 | friend class LDOM_MemManager; |
99 | HashTable (/* const Standard_Integer theMask, */ |
100 | LDOM_MemManager& theMemManager); |
101 | const char * AddString (const char * theString, |
102 | const Standard_Integer theLen, |
103 | Standard_Integer& theHashIndex); |
104 | static Standard_Integer Hash(const char * theString, |
105 | const Standard_Integer theLen); |
106 | struct TableItem { |
107 | char * str; |
108 | struct TableItem * next; |
109 | } * myTable; |
7fd59977 |
110 | LDOM_MemManager& myManager; |
d390b166 |
111 | void operator= (const HashTable&); |
7fd59977 |
112 | }; |
113 | |
114 | // ---- PROHIBITED (PRIVATE) METHODS ---- |
115 | LDOM_MemManager (const LDOM_MemManager& theOther); |
116 | // Copy constructor |
117 | |
118 | LDOM_MemManager& operator = (const LDOM_MemManager& theOther); |
119 | // Assignment |
120 | |
121 | // ---------- PRIVATE FIELDS ---------- |
122 | |
123 | const LDOM_BasicElement * myRootElement; |
124 | MemBlock * myFirstBlock; |
125 | MemBlock * myFirstWithoutRoom; |
126 | Standard_Integer myBlockSize; |
127 | HashTable * myHashTable; |
128 | |
129 | public: |
130 | // CASCADE RTTI |
25e59720 |
131 | DEFINE_STANDARD_RTTIEXT(LDOM_MemManager,Standard_Transient) |
7fd59977 |
132 | }; |
133 | |
7fd59977 |
134 | |
135 | #endif |