0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / LDOM / LDOM_MemManager.hxx
1 // Created on: 2001-06-26
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef LDOM_MemManager_HeaderFile
17 #define LDOM_MemManager_HeaderFile
18
19 #include <Standard_Transient.hxx>
20 #include <Standard_Type.hxx>
21
22 class LDOM_Document;
23 class LDOM_BasicElement;
24 class LDOM_MemManager;
25 class LDOMBasicString;
26
27 // Define handle class for LDOM_MemManager
28 DEFINE_STANDARD_HANDLE (LDOM_MemManager, Standard_Transient)
29
30 //  Class LDOM_MemManager (underlying structure of LDOM_Document)
31 //
32
33 class LDOM_MemManager : public Standard_Transient
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
67 //  LDOM_Document           Doc           () const
68 //                                { return LDOM_Document (* this); }
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;
110     LDOM_MemManager&            myManager;
111     void operator= (const HashTable&);
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
131   DEFINE_STANDARD_RTTIEXT(LDOM_MemManager,Standard_Transient)
132 };
133
134
135 #endif