MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AbstractElement_WaPat.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  AbstractElement_WaPat.h Common attributes of inhabitants of Wa-Pat
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 
27 #ifndef ABSTRACTELEMENT_WAPAT_H
28 #define ABSTRACTELEMENT_WAPAT_H
29 
30 #include "Element.h"
31 #include "EventWindow.h"
32 #include "ElementTable.h"
33 #include "itype.h"
34 #include "P3Atom.h"
35 
36 namespace MFM
37 {
38  template <class CC>
39  class AbstractElement_WaPat : public Element<CC>
40  {
41  public:
42  // Extract short names for parameter types
43  typedef typename CC::ATOM_TYPE T;
44  typedef typename CC::PARAM_CONFIG P;
45  enum
46  {
47  R = P::EVENT_WINDOW_RADIUS,
48  BITS = P::BITS_PER_ATOM,
49 
51  // Element state fields
52 
53  BIRTH_AGE_POS = P3Atom<P>::P3_STATE_BITS_POS,
54  BIRTH_AGE_LEN = 8,
55 
56  CURRENT_AGE_POS = BIRTH_AGE_POS + BIRTH_AGE_LEN,
57  CURRENT_AGE_LEN = 8,
58 
59  WAPAT_FIRST_FREE_POS = CURRENT_AGE_POS + CURRENT_AGE_LEN
60  };
61 
62  typedef BitField<BitVector<BITS>, VD::U32, CURRENT_AGE_LEN, CURRENT_AGE_POS> AFCurrentAge;
63  typedef BitField<BitVector<BITS>, VD::U32, BIRTH_AGE_LEN, BIRTH_AGE_POS> AFBirthAge;
64 
65  u32 GetCurrentAge(const T& us) const
66  {
67  return AFCurrentAge::Read(this->GetBits(us));
68  }
69 
70  void SetCurrentAge(T& us, const u32 age) const
71  {
72  AFCurrentAge::Write(this->GetBits(us), age);
73  }
74 
75  u32 GetBirthAge(const T& us) const
76  {
77  return AFBirthAge::Read(this->GetBits(us));
78  }
79 
80  void SetBirthAge(T& us, const u32 age) const
81  {
82  AFBirthAge::Write(this->GetBits(us), age);
83  }
84 
85  AbstractElement_WaPat(const UUID & uuid) : Element<CC>(uuid)
86  { }
87 
88  virtual u32 PercentMovable(const T& you,
89  const T& me, const SPoint& offset) const
90  {
91  return 100;
92  }
93 
94  };
95 }
96 
97 #endif /* ABSTRACTELEMENT_WAPAT_H */
static void Write(BV &bv, u32 val)
Definition: BitField.h:84
static u32 Read(const BV &bv)
Definition: BitField.h:73
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: AbstractElement_WaPat.h:88
Definition: Atom.h:45
Definition: AbstractElement_WaPat.h:39
Definition: UUID.h:44
const BitVector< P::BITS_PER_ATOM > & GetBits(const T &atom) const
Definition: Element.h:132
Definition: P3Atom.h:44
Definition: Atom.h:43