1 // Created on: 2001-06-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
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.
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.
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.
22 #ifndef LDOM_MemManager_HeaderFile
23 #define LDOM_MemManager_HeaderFile
25 #include <MMgt_TShared.hxx>
26 #include <Standard_DefineHandle.hxx>
27 #include <LDOM_Document.hxx>
29 class LDOM_BasicElement;
31 // Class LDOM_MemManager (underlying structure of LDOM_Document)
34 class LDOM_MemManager : public MMgt_TShared
37 // ---------- PUBLIC METHODS ----------
39 Standard_EXPORT LDOM_MemManager (const Standard_Integer aBlockSize);
42 Standard_EXPORT ~LDOM_MemManager ();
45 Standard_EXPORT void * Allocate (const Standard_Integer aSize);
46 // General Memory allocator
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
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
60 static Standard_Integer Hash (const char * theString,
61 const Standard_Integer theLen)
62 { return HashTable::Hash (theString, theLen); }
64 static Standard_Boolean CompareStrings(const char * theString,
65 const Standard_Integer theHashValue,
66 const char * theHashedStr);
68 LDOM_Document Doc () const
69 { return LDOM_Document (* this); }
71 const LDOM_MemManager& Self () const
74 const LDOM_BasicElement * RootElement () const
75 { return myRootElement; }
78 friend class LDOM_Document;
79 friend class LDOMParser;
81 // ---- 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 *&);
88 MemBlock * Next () { return myNext; }
90 Standard_Integer mySize;
91 Standard_Integer * myBlock;
92 Standard_Integer * myEndBlock;
93 Standard_Integer * myFreeSpace;
97 // ---- 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);
109 struct TableItem * next;
111 // Standard_Integer myMask;
112 LDOM_MemManager& myManager;
115 // ---- PROHIBITED (PRIVATE) METHODS ----
116 LDOM_MemManager (const LDOM_MemManager& theOther);
119 LDOM_MemManager& operator = (const LDOM_MemManager& theOther);
122 // ---------- PRIVATE FIELDS ----------
124 const LDOM_BasicElement * myRootElement;
125 MemBlock * myFirstBlock;
126 MemBlock * myFirstWithoutRoom;
127 Standard_Integer myBlockSize;
128 HashTable * myHashTable;
132 DEFINE_STANDARD_RTTI (LDOM_MemManager)
135 #include <Handle_LDOM_MemManager.hxx>