~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to NuxCore/StreamBuffer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-12-17 13:59:57 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101217135957-5gvg6fkjxaa252i0
Tags: upstream-0.9.12
ImportĀ upstreamĀ versionĀ 0.9.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of both the GNU Lesser General Public
 
15
 * License version 3 along with this program.  If not, see
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "NuxCore.h"
 
24
#include "StreamBuffer.h"
 
25
#include <functional>
 
26
#include <cassert>
 
27
#include <cstring>
 
28
 
 
29
namespace nux
 
30
{
 
31
 
 
32
  NStreamBuffer::NStreamBuffer (const BYTE *begin, const BYTE *end) :
 
33
    begin_ (begin),
 
34
    end_ (end),
 
35
    current_ (begin_)
 
36
  {
 
37
    assert (std::less_equal<const BYTE *>() (begin_, end_) );
 
38
  }
 
39
 
 
40
  NStreamBuffer::NStreamBuffer (const BYTE *str, int size) :
 
41
    begin_ (str),
 
42
    end_ (begin_ + size),
 
43
    current_ (begin_)
 
44
  {
 
45
  }
 
46
 
 
47
  NStreamBuffer::~NStreamBuffer()
 
48
  {
 
49
    delete begin_;
 
50
  }
 
51
 
 
52
  NStreamBuffer::int_type NStreamBuffer::underflow()
 
53
  {
 
54
    if (current_ == end_)
 
55
      return traits_type::eof();
 
56
 
 
57
    return *current_;
 
58
  }
 
59
 
 
60
  NStreamBuffer::int_type NStreamBuffer::uflow()
 
61
  {
 
62
    if (current_ == end_)
 
63
      return traits_type::eof();
 
64
 
 
65
    return *current_++;
 
66
  }
 
67
 
 
68
  NStreamBuffer::int_type NStreamBuffer::pbackfail (int_type ch)
 
69
  {
 
70
    if (current_ == begin_ || (ch != traits_type::eof() && ch != current_[-1]) )
 
71
      return traits_type::eof();
 
72
 
 
73
    return *--current_;
 
74
  }
 
75
 
 
76
  std::streamsize NStreamBuffer::showmanyc()
 
77
  {
 
78
    assert (std::less_equal<const BYTE *>() (current_, end_) );
 
79
    return end_ - current_;
 
80
  }
 
81
 
 
82
}
 
 
b'\\ No newline at end of file'