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 <Standard_Transient.hxx>
20 #include <Standard_Type.hxx>
23 class LDOM_BasicElement;
24 class LDOM_MemManager;
25 class LDOMBasicString;
27 // Define handle class for LDOM_MemManager
28 DEFINE_STANDARD_HANDLE (LDOM_MemManager, Standard_Transient)
30 // Class LDOM_MemManager (underlying structure of LDOM_Document)
33 class LDOM_MemManager : public Standard_Transient
36 // ---------- PUBLIC METHODS ----------
38 Standard_EXPORT LDOM_MemManager (const Standard_Integer aBlockSize);
41 Standard_EXPORT ~LDOM_MemManager ();
44 Standard_EXPORT void * Allocate (const Standard_Integer aSize);
45 // General Memory allocator
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
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
59 static Standard_Integer Hash (const char * theString,
60 const Standard_Integer theLen)
61 { return HashTable::Hash (theString, theLen); }
63 static Standard_Boolean CompareStrings(const char * theString,
64 const Standard_Integer theHashValue,
65 const char * theHashedStr);
67 // LDOM_Document Doc () const
68 // { return LDOM_Document (* this); }
70 const LDOM_MemManager& Self () const
73 const LDOM_BasicElement * RootElement () const
74 { return myRootElement; }
77 friend class LDOM_Document;
78 friend class LDOMParser;
80 // ---- 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 *&);
87 MemBlock * Next () { return myNext; }
89 Standard_Integer mySize;
90 Standard_Integer * myBlock;
91 Standard_Integer * myEndBlock;
92 Standard_Integer * myFreeSpace;
96 // ---- 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);
108 struct TableItem * next;
110 LDOM_MemManager& myManager;
111 void operator= (const HashTable&);
114 // ---- PROHIBITED (PRIVATE) METHODS ----
115 LDOM_MemManager (const LDOM_MemManager& theOther);
118 LDOM_MemManager& operator = (const LDOM_MemManager& theOther);
121 // ---------- PRIVATE FIELDS ----------
123 const LDOM_BasicElement * myRootElement;
124 MemBlock * myFirstBlock;
125 MemBlock * myFirstWithoutRoom;
126 Standard_Integer myBlockSize;
127 HashTable * myHashTable;
131 DEFINE_STANDARD_RTTIEXT(LDOM_MemManager,Standard_Transient)