0025621: CAST analysis - Avoid constructors not supplying an initial value for all...
[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 <MMgt_TShared.hxx>
20 #include <Standard_DefineHandle.hxx>
21 #include <LDOM_Document.hxx>
22
23 class LDOM_BasicElement;
24
25 //  Class LDOM_MemManager (underlying structure of LDOM_Document)
26 //
27
28 class LDOM_MemManager : public MMgt_TShared
29 {
30  public:
31   // ---------- PUBLIC METHODS ----------
32
33   Standard_EXPORT LDOM_MemManager       (const Standard_Integer aBlockSize);
34   // Constructor
35
36   Standard_EXPORT ~LDOM_MemManager      ();
37   // Destructor
38
39   Standard_EXPORT void * Allocate       (const Standard_Integer aSize);
40   // General Memory allocator
41
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
46   // if already present 
47
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
52   // if already present 
53
54   static Standard_Integer Hash          (const char             * theString,
55                                          const Standard_Integer theLen)
56                                 { return HashTable::Hash (theString, theLen); }
57
58   static Standard_Boolean CompareStrings(const char             * theString,
59                                          const Standard_Integer theHashValue,
60                                          const char             * theHashedStr);
61
62   LDOM_Document           Doc           () const
63                                 { return LDOM_Document (* this); }
64
65   const LDOM_MemManager&  Self          () const
66                                 { return * this; }
67
68   const LDOM_BasicElement * RootElement   () const
69                                 { return myRootElement; }
70
71  private:
72   friend class LDOM_Document;
73   friend class LDOMParser;
74
75   // ---- CLASS MemBlock ----
76   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 *&);
81     ~MemBlock               ();
82     MemBlock * Next         ()           { return myNext; }
83
84     Standard_Integer    mySize;
85     Standard_Integer    * myBlock;
86     Standard_Integer    * myEndBlock;
87     Standard_Integer    * myFreeSpace;
88     MemBlock            * myNext;
89   };
90
91   // ---- CLASS HashTable ----
92   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);
101     struct TableItem {
102       char             * str;
103       struct TableItem * next;
104     }                           * myTable;
105     LDOM_MemManager&            myManager;
106     void operator= (const HashTable&);
107   };
108
109   // ---- PROHIBITED (PRIVATE) METHODS ----
110   LDOM_MemManager (const LDOM_MemManager& theOther);
111   // Copy constructor
112
113   LDOM_MemManager& operator = (const LDOM_MemManager& theOther);
114   // Assignment
115
116   // ---------- PRIVATE FIELDS ----------
117
118   const LDOM_BasicElement * myRootElement;
119   MemBlock              * myFirstBlock;
120   MemBlock              * myFirstWithoutRoom;
121   Standard_Integer      myBlockSize;
122   HashTable             * myHashTable;
123
124  public:
125   // CASCADE RTTI
126   DEFINE_STANDARD_RTTI (LDOM_MemManager)
127 };
128
129 #include <Handle_LDOM_MemManager.hxx>
130
131 #endif