zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Input.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #include "Input.h"
8 
9 #include <algorithm>
10 #include <cassert>
11 #include <cstring>
12 
13 namespace pp
14 {
15 
16 Input::Input() : mCount(0), mString(0)
17 {
18 }
19 
20 Input::Input(size_t count, const char* const string[], const int length[]) :
21  mCount(count),
22  mString(string)
23 {
24  mLength.reserve(mCount);
25  for (size_t i = 0; i < mCount; ++i)
26  {
27  int len = length ? length[i] : -1;
28  mLength.push_back(len < 0 ? std::strlen(mString[i]) : len);
29  }
30 }
31 
32 size_t Input::read(char* buf, size_t maxSize)
33 {
34  size_t nRead = 0;
35  while ((nRead < maxSize) && (mReadLoc.sIndex < mCount))
36  {
37  size_t size = mLength[mReadLoc.sIndex] - mReadLoc.cIndex;
38  size = std::min(size, maxSize);
39  std::memcpy(buf + nRead, mString[mReadLoc.sIndex] + mReadLoc.cIndex, size);
40  nRead += size;
41  mReadLoc.cIndex += size;
42 
43  // Advance string if we reached the end of current string.
44  if (mReadLoc.cIndex == mLength[mReadLoc.sIndex])
45  {
46  ++mReadLoc.sIndex;
47  mReadLoc.cIndex = 0;
48  }
49  }
50  return nRead;
51 }
52 
53 } // namespace pp
54 
size_t cIndex
Definition: Input.h:32
size_t read(char *buf, size_t maxSize)
Definition: Input.cpp:32
png_sPLT_entryp pp
Definition: pngrutil.c:1375
GLenum GLsizei len
Definition: glew.h:7035
size_t sIndex
Definition: Input.h:31
GLsizei GLsizei * length
Definition: gl2ext.h:792
GLint GLsizei count
Definition: gl2ext.h:1011
Input()
Definition: Input.cpp:16
GLenum GLuint GLsizei const GLchar * buf
Definition: glew.h:2539
#define memcpy
Definition: SDL_malloc.c:634
#define min(x, y)
Definition: os.h:75
int i
Definition: pngrutil.c:1377
GLsizei size
Definition: gl2ext.h:1467