Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BlockInStream.h
1 /*
2  * $Id$
3  * BlockInStream class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2005-09, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_IO_BLOCK_IN_STREAM_H
23 #define ELM_IO_BLOCK_IN_STREAM_H
24 
25 #include <elm/assert.h>
26 #include <elm/string/String.h>
27 #include <elm/string/CString.h>
28 #include <elm/io/InStream.h>
29 
30 namespace elm { namespace io {
31 
32 // BlockInStream class
33 class BlockInStream: public InStream {
34  const char *_block;
35  int _size, off;
36 public:
37 
38  BlockInStream(const void *block, int size);
39  BlockInStream(const char *str);
40  BlockInStream(const CString& str);
41  BlockInStream(const String& str);
42  inline const void *block(void) const;
43  inline int size(void) const;
44  inline int mark(void) const;
45  inline void move(int mark);
46  inline void moveForward(int size);
47  inline void moveBackward(int size);
48  inline void reset(void);
49 
50  // InStream overload
51  virtual int read(void *buffer, int size);
52  virtual int read(void);
53 };
54 
55 // Inlines
56 inline const void *BlockInStream::block(void) const {
57  return _block;
58 }
59 
60 inline int BlockInStream::size(void) const {
61  return _size;
62 }
63 
64 inline int BlockInStream::mark(void) const {
65  return off;
66 }
67 
68 inline void BlockInStream::move(int mark) {
69  ASSERT(mark < _size);
70  off = mark;
71 }
72 
73 inline void BlockInStream::moveForward(int size) {
74  ASSERTP(off + size <= _size, "move out of block");
75  off += _size;
76 }
77 
79  ASSERTP(off - size >= 0, "move out of block");
80  off -= size;
81 }
82 
83 inline void BlockInStream::reset(void) {
84  off = 0;
85 }
86 
87 } } // elm::io
88 
89 #endif // ELM_IO_BLOCK_IN_STREAM_H
Definition: CString.h:17
int size(void) const
Definition: BlockInStream.h:60
int mark(void) const
Definition: BlockInStream.h:64
void moveForward(int size)
Definition: BlockInStream.h:73
uint32 size
Definition: int.h:41
void moveBackward(int size)
Definition: BlockInStream.h:78
const void * block(void) const
Definition: BlockInStream.h:56
BlockInStream(const void *block, int size)
Definition: io_BlockInStream.cpp:41
virtual int read(void)
Definition: io_BlockInStream.cpp:138
Definition: BlockInStream.h:33
Definition: String.h:31
void move(int mark)
Definition: BlockInStream.h:68
Definition: InStream.h:30
void reset(void)
Definition: BlockInStream.h:83