Scopira 20080306

stringflow.h

00001 
00002 /*
00003  *  Copyright (c) 2004    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_STRINGFLOW_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_STRINGFLOW_H__
00016 
00017 #include <scopira/tool/flow.h>
00018 #include <scopira/tool/export.h>
00019 
00020 namespace scopira
00021 {
00022   namespace tool
00023   {
00024     class stringflow;
00025     class stringiflow;
00026     class stringoflow;
00027   }
00028 }
00029 
00035 class scopira::tool::stringflow : public scopira::tool::iflow_i, public scopira::tool::oflow_i
00036 {
00037   protected:
00039     mode_t dm_mode;
00041     std::string dm_data;
00043     size_t dm_index;
00044 
00045   public:
00046 
00048     enum {
00049       append_c = 1024,
00050       trunc_c = 2048
00051     };
00052 
00054     SCOPIRA_EXPORT stringflow(void);
00056     SCOPIRA_EXPORT explicit stringflow(size_t res);
00058     SCOPIRA_EXPORT stringflow(const std::string& data, mode_t mode);
00060     SCOPIRA_EXPORT virtual ~stringflow();
00061 
00063     SCOPIRA_EXPORT virtual bool failed(void) const;
00064 
00066     SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
00068     SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
00069 
00071     SCOPIRA_EXPORT void open(void);
00073     SCOPIRA_EXPORT void open(const std::string& data, mode_t mode);
00075     SCOPIRA_EXPORT void close(void);
00076 
00078     SCOPIRA_EXPORT void reserve(size_t _size);
00080     const std::string& str(void) const { return dm_data; }
00081 };
00082 
00088 class scopira::tool::stringiflow : public scopira::tool::iflow_i
00089 {
00090   protected:
00092     const std::string * dm_data;
00093     std::string::size_type dm_idx;
00094 
00095   public:
00102     SCOPIRA_EXPORT stringiflow(const std::string* data);
00103 
00105     SCOPIRA_EXPORT virtual bool failed(void) const;
00106 
00108     SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
00109 
00111     SCOPIRA_EXPORT void open(const std::string *data);
00112 };
00113 
00119 class scopira::tool::stringoflow : public scopira::tool::oflow_i
00120 {
00121   protected:
00123     std::string * dm_data;
00124 
00125   public:
00127     SCOPIRA_EXPORT stringoflow(std::string* data);
00128 
00130     SCOPIRA_EXPORT virtual bool failed(void) const { return false; }
00131 
00133     SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
00134 
00136     SCOPIRA_EXPORT void open(std::string *data);
00137 };
00138 
00139 #endif
00140