Scopira  20080306
stringflow.h
1 
2 /*
3  * Copyright (c) 2004 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_STRINGFLOW_H__
15 #define __INCLUDED_SCOPIRA_TOOL_STRINGFLOW_H__
16 
17 #include <scopira/tool/flow.h>
18 #include <scopira/tool/export.h>
19 
20 namespace scopira
21 {
22  namespace tool
23  {
24  class stringflow;
25  class stringiflow;
26  class stringoflow;
27  }
28 }
29 
36 {
37  protected:
41  std::string dm_data;
43  size_t dm_index;
44 
45  public:
46 
48  enum {
49  append_c = 1024,
50  trunc_c = 2048
51  };
52 
54  SCOPIRA_EXPORT stringflow(void);
56  SCOPIRA_EXPORT explicit stringflow(size_t res);
58  SCOPIRA_EXPORT stringflow(const std::string& data, mode_t mode);
60  SCOPIRA_EXPORT virtual ~stringflow();
61 
63  SCOPIRA_EXPORT virtual bool failed(void) const;
64 
66  SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
68  SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
69 
71  SCOPIRA_EXPORT void open(void);
73  SCOPIRA_EXPORT void open(const std::string& data, mode_t mode);
75  SCOPIRA_EXPORT void close(void);
76 
78  SCOPIRA_EXPORT void reserve(size_t _size);
80  const std::string& str(void) const { return dm_data; }
81 };
82 
89 {
90  protected:
92  const std::string * dm_data;
93  std::string::size_type dm_idx;
94 
95  public:
102  SCOPIRA_EXPORT stringiflow(const std::string* data);
103 
105  SCOPIRA_EXPORT virtual bool failed(void) const;
106 
108  SCOPIRA_EXPORT virtual size_t read(byte_t* _buf, size_t _maxsize);
109 
111  SCOPIRA_EXPORT void open(const std::string *data);
112 };
113 
120 {
121  protected:
123  std::string * dm_data;
124 
125  public:
127  SCOPIRA_EXPORT stringoflow(std::string* data);
128 
130  SCOPIRA_EXPORT virtual bool failed(void) const { return false; }
131 
133  SCOPIRA_EXPORT virtual size_t write(const byte_t* _buf, size_t _size);
134 
136  SCOPIRA_EXPORT void open(std::string *data);
137 };
138 
139 #endif
140 
Definition: stringflow.h:88
Definition: flow.h:108
const std::string & str(void) const
get the current string contents
Definition: stringflow.h:80
scopira::tool::byte_t byte_t
Definition: flow.h:73
Definition: stringflow.h:35
virtual size_t write(const byte_t *_buf, size_t _size)
write a raw block of data
Definition: archiveflow.h:20
void reserve(size_t _size)
reserve an internal buffer
const std::string * dm_data
the data string
Definition: stringflow.h:92
std::string * dm_data
the data string
Definition: stringflow.h:123
virtual ~stringflow()
destructor
void close(void)
close the file
mode_t dm_mode
current modes, 0 for no-file
Definition: stringflow.h:39
Definition: stringflow.h:119
int mode_t
Definition: flow.h:78
virtual bool failed(void) const
are we in a failed state?
virtual size_t read(byte_t *_buf, size_t _maxsize)
read raw block data, returns num read in
virtual bool failed(void) const
are we in a failed state?
Definition: stringflow.h:130
std::string dm_data
the data string
Definition: stringflow.h:41
stringflow(void)
default, open for output with the given reserve
size_t dm_index
the current index
Definition: stringflow.h:43
Definition: flow.h:159
void open(void)
open for writing. uses truncation