MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
P2Atom.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  P2Atom.h Atom with (eventually) built in bond support
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 P2ATOM_H /* -*- C++ -*- */
28 #define P2ATOM_H
29 
30 #include <stdio.h>
31 #include "itype.h"
32 #include "Point.h"
33 #include "BitVector.h"
34 #include "MDist.h"
35 
36 #define P2ATOM_SIZE 96
37 #define P2ATOM_RADIUS 5
38 
39 #define P2ATOM_HEADER_SIZE 8
40 #define P2ATOM_LONGBOND_SIZE 8
41 #define P2ATOM_SHORTBOND_SIZE 4
42 
43 
44 namespace MFM {
45 
46  class P2Atom
47  {
48  public: enum { ATOM_CATEGORY = 2 };
49  private:
51 
52  typedef MDist<4> MDist4;
53 
54  public:
55 
56  static u32 StateFunc(P2Atom* atom)
57  {
58  return atom->GetState();
59  }
60 
61  P2Atom() {
62  FAIL(DEPRECATED);
63  }
64 
65  P2Atom(u32 state)
66  {
67  SetState(state);
68  FAIL(DEPRECATED);
69  }
70 
71  bool IsSane() const
72  {
73  // P2Atom has no implemented error detection abilities
74  return true;
75  }
76 
77  bool HasBeenRepaired()
78  {
79  // If somebody thinks it's bad, we can't fix it.
80  return false;
81  }
82 
83 
84  u32 GetState()
85  { return m_bits.Read(2, 6); }
86 
87  void SetState(u32 state)
88  { m_bits.Write(2, 6, state); }
89 
90  u32 GetLongBondCount()
91  { return m_bits.Read(9, 3); }
92 
93  void SetLongBondCount(u32 count)
94  { m_bits.Write(9, 3, count); }
95 
96  u32 GetShortBondCount()
97  { return m_bits.Read(12, 4); }
98 
99  void SetShortBondCount(u32 count)
100  { m_bits.Write(12, 4, count); }
101 
102  void ReadVariableBodyInto(u32* arr)
103  {
104  arr[0] = m_bits.Read(16, 16);
105  arr[1] = m_bits.Read(32, 32);
106  }
107 
108  void WriteVariableBodyFrom(u32* arr)
109  {
110  m_bits.Write(16, 16, arr[0]);
111  m_bits.Write(32, 32, arr[1]);
112  }
113 
114  void WriteLowerBits(u32 val)
115  {
116  m_bits.Write(32, 32, val);
117  }
118 
119  u32 ReadLowerBits()
120  {
121  return m_bits.Read(32, 32);
122  }
123 
124  void PrintBits(ByteSink & ostream)
125  { m_bits.Print(ostream); }
126 
127  /* Adds a long bond. Returns its index. */
128  u32 AddLongBond(const SPoint& offset);
129 
130  u32 AddShortBond(const SPoint& offset);
131 
132  /* Fills pt with the long bond location in index. */
133  void FillLongBond(u32 index, SPoint& pt);
134 
135  void FillShortBond(u32 index, SPoint& pt);
136 
137  /*
138  * Removes a long bond. Be careful; if a
139  * bond is removed, the bonds ahead of it
140  * (if they exist) will be pushed downwards.
141  * The indices of these bonds will need to
142  * be updated again afterwards.
143  */
144  void RemoveLongBond(u32 index);
145 
146  void RemoveShortBond(u32 index);
147 
148  P2Atom& operator=(P2Atom rhs);
149  };
150 } /* namespace MFM */
151 #endif /*P2ATOM_H*/
void Write(const u32 startIdx, const u32 length, const u32 value)
Definition: BitVector.tcc:99
u32 Read(const u32 startIdx, const u32 length) const
Definition: BitVector.tcc:129
void Print(ByteSink &ostream) const
Definition: BitVector.tcc:202
Definition: P2Atom.h:46
Definition: ByteSink.h:47
Definition: MDist.h:69