Scopira  20080306
bufferflow.h
1 
2 /*
3  * Copyright (c) 2003 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED_SCOPIRA_TOOL_BUFFERFLOW_H__
15 #define __INCLUDED_SCOPIRA_TOOL_BUFFERFLOW_H__
16 
17 #include <scopira/tool/flow.h>
18 #include <scopira/tool/export.h>
19 
20 #include <assert.h>
21 
22 #include <vector>
23 
24 namespace scopira
25 {
26  namespace tool
27  {
28  class bufferflow;
29  class bufferiflow;
30  class bufferoflow;
31  }
32 }
33 
41 {
42  public:
43  typedef std::vector<tool::flow_i::byte_t> byte_buffer_t;
44 
45  private:
47  bufferflow& operator=(const bufferflow& rhs) { assert(false); return *this; }
49  bufferflow(const bufferflow& rhs) { assert(false); }
50 
52  size_t dm_index;
54  byte_buffer_t dm_buffer;
55 
56  public:
57 
59  SCOPIRA_EXPORT bufferflow(void);
61  SCOPIRA_EXPORT virtual ~bufferflow(void);
62 
64  SCOPIRA_EXPORT virtual bool failed(void) const;
65 
67  SCOPIRA_EXPORT virtual size_t read(byte_t* buf, size_t maxsize);
68 
70  SCOPIRA_EXPORT virtual size_t write(const byte_t* buf, size_t size);
71 
74 
76  byte_t* c_array(void) { assert(size()>0); return &dm_buffer[0]; }
78  const byte_t* c_array(void) const { assert(size()>0); return &dm_buffer[0]; }
79 
81  size_t size(void) const { return dm_buffer.size(); }
82 
85  size_t capacity(void) const { return dm_buffer.capacity(); }
86 
88  SCOPIRA_EXPORT void reset(void);
90  SCOPIRA_EXPORT void reserve(size_t _size);
92  SCOPIRA_EXPORT void reset_resize(size_t _size);
93 };
94 
101 {
102  protected:
104  const byte_t *dm_data, *dm_cur, *dm_end;
105 
106  public:
108  SCOPIRA_EXPORT bufferiflow(const byte_t *data, size_t sz);
109 
111  SCOPIRA_EXPORT virtual bool failed(void) const;
112 
114  SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
115 };
116 
123 {
124  protected:
126  byte_t *dm_data, *dm_cur, *dm_end;
127 
128  public:
130  SCOPIRA_EXPORT bufferoflow(byte_t *data, size_t sz);
131 
133  SCOPIRA_EXPORT virtual bool failed(void) const;
134 
136  SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
137 };
138 
139 #endif
140 
Definition: flow.h:108
Definition: bufferflow.h:122
scopira::tool::byte_t byte_t
Definition: flow.h:73
virtual bool failed(void) const
are we in a failed state?
Definition: archiveflow.h:20
size_t size(void) const
return the size of the internal buffer
Definition: bufferflow.h:81
Definition: bufferflow.h:40
const byte_t * c_array(void) const
returns the buffer as a raw c array
Definition: bufferflow.h:78
byte_t * dm_data
the data string
Definition: bufferflow.h:126
void reset(void)
resets the buffer index
virtual size_t read(byte_t *buf, size_t maxsize)
read raw block data, returns num read in
size_t capacity(void) const
Definition: bufferflow.h:85
Definition: bufferflow.h:100
const byte_t * dm_data
the data string
Definition: bufferflow.h:104
virtual size_t write(const byte_t *buf, size_t size)
write a raw block of data
void reserve(size_t _size)
reserve an internal buffer
virtual ~bufferflow(void)
destructor
byte_t * c_array(void)
returns the buffer as a raw c array
Definition: bufferflow.h:76
bufferflow(void)
default constructor
void reset_resize(size_t _size)
resizes the internal buffer. this also resets the index pointer
Definition: flow.h:159