Scopira 20080306

bufferflow.h

00001 
00002 /*
00003  *  Copyright (c) 2003    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013  
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_BUFFERFLOW_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_BUFFERFLOW_H__
00016 
00017 #include <scopira/tool/flow.h>
00018 #include <scopira/tool/export.h>
00019 
00020 #include <assert.h>
00021 
00022 #include <vector>
00023 
00024 namespace scopira
00025 {
00026   namespace tool
00027   {
00028     class bufferflow;
00029     class bufferiflow;
00030     class bufferoflow;
00031   }
00032 }
00033 
00040 class scopira::tool::bufferflow : public scopira::tool::iflow_i, public scopira::tool::oflow_i
00041 {
00042   public:
00043     typedef std::vector<tool::flow_i::byte_t> byte_buffer_t;
00044 
00045   private:
00047     bufferflow& operator=(const bufferflow& rhs) { assert(false); return *this; }
00049     bufferflow(const bufferflow& rhs) { assert(false); }
00050 
00052     size_t dm_index;
00054     byte_buffer_t dm_buffer;
00055 
00056   public:
00057 
00059     SCOPIRA_EXPORT bufferflow(void);
00061     SCOPIRA_EXPORT virtual ~bufferflow(void);
00062 
00064     SCOPIRA_EXPORT virtual bool failed(void) const;
00065 
00067     SCOPIRA_EXPORT virtual size_t read(byte_t* buf, size_t maxsize);
00068 
00070     SCOPIRA_EXPORT virtual size_t write(const byte_t* buf, size_t size);
00071 
00074 
00076     byte_t* c_array(void) { assert(size()>0); return &dm_buffer[0]; }
00078     const byte_t* c_array(void) const { assert(size()>0); return &dm_buffer[0]; }
00079 
00081     size_t size(void) const { return dm_buffer.size(); }
00082 
00085     size_t capacity(void) const { return dm_buffer.capacity(); }
00086 
00088     SCOPIRA_EXPORT void reset(void);
00090     SCOPIRA_EXPORT void reserve(size_t _size);
00092     SCOPIRA_EXPORT void reset_resize(size_t _size);
00093 };
00094 
00100 class scopira::tool::bufferiflow : public scopira::tool::iflow_i
00101 {
00102   protected:
00104     const byte_t *dm_data, *dm_cur, *dm_end;
00105 
00106   public:
00108     SCOPIRA_EXPORT bufferiflow(const byte_t *data, size_t sz);
00109 
00111     SCOPIRA_EXPORT virtual bool failed(void) const;
00112 
00114     SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
00115 };
00116 
00122 class scopira::tool::bufferoflow : public scopira::tool::oflow_i
00123 {
00124   protected:
00126     byte_t *dm_data, *dm_cur, *dm_end;
00127 
00128   public:
00130     SCOPIRA_EXPORT bufferoflow(byte_t *data, size_t sz);
00131 
00133     SCOPIRA_EXPORT virtual bool failed(void) const;
00134 
00136     SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
00137 };
00138 
00139 #endif
00140