MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExternalConfig.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  ExternalConfig.h Support for grid configurations on the drive
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 EXTERNALCONFIG_H
29 #define EXTERNALCONFIG_H
30 
31 #include "Grid.h"
32 #include "OverflowableCharBufferByteSink.h" /* For OString16 */
33 #include "LineCountingByteSource.h"
34 #include "ByteSink.h"
35 #include "ElementRegistry.h"
36 
37 namespace MFM
38 {
39 
40  template<typename> class ConfigFunctionCall;
41 
45  template<class GC>
46  class ExternalConfig
47  {
48  typedef typename GC::CORE_CONFIG CC;
49  typedef typename CC::PARAM_CONFIG P;
50  typedef typename CC::ATOM_TYPE T;
51  enum { BPA = P::BITS_PER_ATOM };
52 
53  public:
54 
55  /*
56  * Construct a new ExternalConfig referencing a specified Grid
57  *
58  * @param grid The grid to read from or write to.
59  */
60  ExternalConfig(Grid<GC>& grid);
61 
62  void SetByteSource(ByteSource & byteSource, const char * label) ;
63 
64  void SetErrorByteSink(ByteSink & errorsTo) ;
65 
73  bool Read();
74 
78  void Write(ByteSink & byteSink);
79 
80  void RegisterFunction(ConfigFunctionCall<GC> & fc) ;
81 
82  bool RegisterElement(const UUID & uuid, OString16 & nick) ;
83 
84  Element<CC> * LookupElement(const OString16 & nick) const ;
85 
86  bool PlaceAtom(const Element<CC> & elt, s32 x, s32 y, const char* dataStr) ;
87 
88  bool PlaceAtom(const Element<CC> & elt, s32 x, s32 y, const BitVector<BPA> & bv) ;
89 
90  void SetTileToExecuteOnly(const SPoint& tileLoc, bool value);
91 
92  LineCountingByteSource & GetByteSource()
93  {
94  return m_in;
95  }
96 
97  private:
98  LineCountingByteSource m_in;
99  ByteSink * m_errorsTo;
100 
104  Grid<GC>& m_grid;
105 
109  ElementRegistry<CC>& m_elementRegistry;
110 
111 #define MAX_REGISTERED_FUNCTIONS 64
112  ConfigFunctionCall<GC> * (m_registeredFunctions[MAX_REGISTERED_FUNCTIONS]);
113  u32 m_registeredFunctionCount;
114 
115 #define MAX_REGISTERED_ELEMENTS 64
116  struct RegElt {
117  UUID m_uuid;
118  OString16 m_nick;
119  Element<CC> * m_element;
120  } m_registeredElements[MAX_REGISTERED_ELEMENTS];
121  u32 m_registeredElementCount;
122 
123  };
124 }
125 
126 #include "ConfigFunctionCall.h"
127 #include "ExternalConfig.tcc"
128 
129 #endif /* EXTERNALCONFIG_H */
bool Read()
Definition: ExternalConfig.tcc:35
void Write(ByteSink &byteSink)
Definition: ExternalConfig.tcc:83