MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ElementTable.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  ElementTable.h Registry of elements
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
28 #ifndef ELEMENTTABLE_H
29 #define ELEMENTTABLE_H
30 
31 #include "BitVector.h"
32 #include "EventWindow.h"
33 #include "Dirs.h"
34 #include "itype.h"
35 #include "Element.h"
36 #include "Element_Empty.h"
37 #include "UsageTimer.h"
38 
39 namespace MFM
40 {
41 
42  template <class CC> class Element; // FORWARD
43  template <class CC> class EventWindow; // FORWARD
44 
45  template <class CC>
47  {
48  // Extract short type names
49  typedef typename CC::ATOM_TYPE T;
50  typedef typename CC::PARAM_CONFIG P;
51  enum { B = P::ELEMENT_TABLE_BITS};
52  enum { R = P::EVENT_WINDOW_RADIUS};
53  enum { ELEMENT_DATA_SLOTS = P::ELEMENT_DATA_SLOTS};
54 
55  public:
56  // -3 to avoid 2**k and 2**k-1 sizes; they seem to beat against type assignments
57  static const u32 SIZE = (1u<<B) - 3;
58 
62  void Reinit() ;
63 
70  void Insert(const Element<CC> & theElement) ;
71 
76  u32 GetSize() const
77  {
78  return SIZE;
79  }
80 
98  s32 GetIndex(u32 elementType) const ;
99 
103  ElementTable();
104 
109 
121  const Element<CC> * Lookup(u32 elementType) const;
122 
130  void Execute(EventWindow<CC>& window) ;
131 
139  bool RegisterElement(const Element<CC>& e) ;
140 
168  bool AllocateElementDataSlots(const Element<CC>& e, u32 slots) ;
169 
170  bool AllocateElementDataSlotsFromType(const u32 elementType, u32 slots) ;
171 
187  u64 * GetElementDataSlots(const Element<CC>& e, const u32 slots) ;
188 
189  u64 * GetElementDataSlotsFromType(const u32 elementType, const u32 slots) ;
190 
191  u64 * GetDataAndRegister(const u32 elementType, u32 slots) ;
192 
193  u64 * GetDataIfRegistered(const u32 elementType, u32 slots) ;
194 
195  private:
196 
207  u32 SlotFor(u32 elementType) const ;
208 
209  struct ElementEntry {
210  void Clear() {
211  m_element = 0;
212  m_elementDataStart = 0;
213  m_elementDataLength = 0;
214  }
215  const Element<CC>* m_element;
216  u16 m_elementDataStart;
217  u16 m_elementDataLength;
218  } m_hash[SIZE];
219  u32 m_hashSlotsInUse;
220 
221  u64 m_elementData[ELEMENT_DATA_SLOTS];
222  u32 m_nextFreeElementDataIndex;
223 
224  };
225 
226 } /* namespace MFM */
227 
228 #include "ElementTable.tcc"
229 
230 #endif /*ELEMENTTABLE_H*/
ElementTable()
Definition: ElementTable.tcc:92
void Execute(EventWindow< CC > &window)
Definition: ElementTable.tcc:61
const Element< CC > * Lookup(u32 elementType) const
Definition: ElementTable.tcc:55
void Reinit()
Definition: ElementTable.tcc:178
bool RegisterElement(const Element< CC > &e)
Definition: ElementTable.tcc:85
u32 GetSize() const
Definition: ElementTable.h:76
void Insert(const Element< CC > &theElement)
Definition: ElementTable.tcc:35
s32 GetIndex(u32 elementType) const
Definition: ElementTable.tcc:11
Definition: ElementTable.h:46
u64 * GetElementDataSlots(const Element< CC > &e, const u32 slots)
Definition: ElementTable.tcc:126
Definition: ElementTable.h:43
bool AllocateElementDataSlots(const Element< CC > &e, u32 slots)
Definition: ElementTable.tcc:98
~ElementTable()
Definition: ElementTable.h:108
Definition: Atom.h:43