MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CharBufferByteSource.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  CharBufferByteSource.h Source bytes from a fixed char buffer
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 CHARBUFFERBYTESOURCE_H
28 #define CHARBUFFERBYTESOURCE_H
29 
30 #include "ByteSource.h"
31 
32 namespace MFM
33 {
38  {
39  public:
40 
53  CharBufferByteSource(const char * input, u32 length)
54  : m_input(input),
55  m_length(length),
56  m_read(0)
57  {
58  if (!input)
59  {
60  FAIL(NULL_POINTER);
61  }
62  }
63 
70  virtual int ReadByte()
71  {
72  if (m_read >= m_length)
73  {
74  return -1;
75  }
76  return m_input[m_read++];
77  }
78 
90  void ChangeBuffer(const char * newBuffer, u32 bufferLength)
91  {
92  if (!newBuffer)
93  {
94  FAIL(NULL_POINTER);
95  }
96  m_input = newBuffer;
97  m_length = bufferLength;
98 
99  Reset();
100  }
101 
107  void Reset()
108  {
109  m_read = 0;
110  }
111 
112  private:
113 
118  const char * m_input;
119 
124  u32 m_length;
125 
130  u32 m_read;
131  };
132 }
133 
134 #endif /* CHARBUFFERBYTESOURCE_H */
CharBufferByteSource(const char *input, u32 length)
Definition: CharBufferByteSource.h:53
Definition: CharBufferByteSource.h:37
Definition: ByteSource.h:44
void ChangeBuffer(const char *newBuffer, u32 bufferLength)
Definition: CharBufferByteSource.h:90
void Reset()
Definition: CharBufferByteSource.h:107
virtual int ReadByte()
Definition: CharBufferByteSource.h:70