1 // Created on: 2001-06-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef LDOM_MemManager_HeaderFile
17 #define LDOM_MemManager_HeaderFile
19 #include <MMgt_TShared.hxx>
20 #include <Standard_Type.hxx>
21 #include <LDOM_Document.hxx>
23 class LDOM_BasicElement;
25 // Class LDOM_MemManager (underlying structure of LDOM_Document)
28 class LDOM_MemManager : public MMgt_TShared
31 // ---------- PUBLIC METHODS ----------
33 Standard_EXPORT LDOM_MemManager (const Standard_Integer aBlockSize);
36 Standard_EXPORT ~LDOM_MemManager ();
39 Standard_EXPORT void * Allocate (const Standard_Integer aSize);
40 // General Memory allocator
42 const char * HashedAllocate (const char * aString,
43 const Standard_Integer theLen,
44 Standard_Integer& theHash);
45 // Memory allocation with access via hash table. No new allocation
48 void HashedAllocate (const char * aString,
49 const Standard_Integer theLen,
50 LDOMBasicString& theResult);
51 // Memory allocation with access via hash table. No new allocation
54 static Standard_Integer Hash (const char * theString,
55 const Standard_Integer theLen)
56 { return HashTable::Hash (theString, theLen); }
58 static Standard_Boolean CompareStrings(const char * theString,
59 const Standard_Integer theHashValue,
60 const char * theHashedStr);
62 LDOM_Document Doc () const
63 { return LDOM_Document (* this); }
65 const LDOM_MemManager& Self () const
68 const LDOM_BasicElement * RootElement () const
69 { return myRootElement; }
72 friend class LDOM_Document;
73 friend class LDOMParser;
75 // ---- CLASS MemBlock ----
77 friend class LDOM_MemManager;
78 inline MemBlock (const Standard_Integer aSize, MemBlock * aFirst);
79 inline void * Allocate (const Standard_Integer aSize);
80 void * AllocateAndCheck (const Standard_Integer aSize, const MemBlock *&);
82 MemBlock * Next () { return myNext; }
84 Standard_Integer mySize;
85 Standard_Integer * myBlock;
86 Standard_Integer * myEndBlock;
87 Standard_Integer * myFreeSpace;
91 // ---- CLASS HashTable ----
93 friend class LDOM_MemManager;
94 HashTable (/* const Standard_Integer theMask, */
95 LDOM_MemManager& theMemManager);
96 const char * AddString (const char * theString,
97 const Standard_Integer theLen,
98 Standard_Integer& theHashIndex);
99 static Standard_Integer Hash(const char * theString,
100 const Standard_Integer theLen);
103 struct TableItem * next;
105 LDOM_MemManager& myManager;
106 void operator= (const HashTable&);
109 // ---- PROHIBITED (PRIVATE) METHODS ----
110 LDOM_MemManager (const LDOM_MemManager& theOther);
113 LDOM_MemManager& operator = (const LDOM_MemManager& theOther);
116 // ---------- PRIVATE FIELDS ----------
118 const LDOM_BasicElement * myRootElement;
119 MemBlock * myFirstBlock;
120 MemBlock * myFirstWithoutRoom;
121 Standard_Integer myBlockSize;
122 HashTable * myHashTable;
126 DEFINE_STANDARD_RTTI (LDOM_MemManager, MMgt_TShared)
129 #include <Handle_LDOM_MemManager.hxx>