MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomSerializer.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*- */
2 
3 /*
4  AtomSerializer.h A wrapper for (de)serializing an Atom
5  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  USA
21 */
22 
29 #ifndef ATOMSERIALIZER_H
30 #define ATOMSERIALIZER_H
31 
32 #include "itype.h"
33 #include "Atom.h"
34 #include "BitVector.h"
35 #include "ByteSerializable.h"
36 
37 namespace MFM
38 {
39 
46  template <class CC>
47  class AtomSerializer : public ByteSerializable
48  {
49  typedef typename CC::PARAM_CONFIG P;
50  enum { BPA = P::BITS_PER_ATOM };
51  private:
52  Atom<CC> & m_atom;
53 
54  public:
55  AtomSerializer(Atom<CC> & atom) : m_atom(atom)
56  { }
57 
58  Result PrintTo(ByteSink & bs, s32 argument = 0)
59  {
60  m_atom.m_bits.Print(bs);
61  return SUCCESS;
62  }
63 
64  Result ReadFrom(ByteSource & bs, s32 argument = 0)
65  {
66  if (m_atom.m_bits.Read(bs))
67  return SUCCESS;
68  return FAILURE;
69  }
70 
71  const BitVector<BPA> & GetBits() const
72  {
73  return m_atom.m_bits;
74  }
75 
76  };
77 } /* namespace MFM */
78 
79 #endif /*ATOMSERIALIZER_H*/
Result PrintTo(ByteSink &bs, s32 argument=0)
Definition: AtomSerializer.h:58
Definition: ByteSource.h:44
Definition: ByteSink.h:47
Result ReadFrom(ByteSource &bs, s32 argument=0)
Definition: AtomSerializer.h:64