xref: /aoo42x/main/autodoc/inc/cosv/bstream.hxx (revision 8a106958)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef CSV_BSTREAM_HXX
25 #define CSV_BSTREAM_HXX
26 
27 #include <string.h>
28 #include <cosv/string.hxx>
29 
30 
31 namespace csv
32 {
33 
34 
35 enum seek_dir
36 {
37     beg = 0,
38     cur = 1,
39     end = 2
40 };
41 
42 
43 class bistream
44 {
45   public:
46 	// LIFECYCLE
~bistream()47 	virtual				~bistream() {}
48 
49 	//	OPERATIONS
50 		/// @return Number of actually read bytes.
51 	uintt 		        read(
52 							void *	        out_pDest,
53 							uintt           i_nNrofBytes);
54 	// INQUIRY
55 		/**  @return True, if already one try to read had failed.
56 			 There is no guarantee, that it returns true, if end of data
57 			 is just reached.
58 			 Though it will return false, if there is still somemething
59 			 to read.
60 		*/
61 	bool		        eod() const;
62 
63   private:
64 	virtual uintt 		do_read(
65 							void *	        out_pDest,
66 							uintt           i_nNrofBytes) = 0;
67 	virtual bool		inq_eod() const = 0;
68 };
69 
70 
71 class bostream
72 {
73   public:
74 	// LIFECYCLE
~bostream()75 	virtual				~bostream() {}
76 
77 	//	OPERATIONS
78 		/// @return Number of actually written bytes.
79 	uintt 		        write(
80 							const void *   	i_pSrc,
81 							uintt           i_nNrofBytes);
82 		/// @return Number of actually written bytes.
83 	uintt 				write(
84 							const char *   	i_pSrc );
85 		/// @return Number of actually written bytes.
86 	uintt 				write(
87 							const String &	i_pSrc );
88   private:
89 	virtual uintt 		do_write(
90 							const void *   	i_pSrc,
91 							uintt           i_nNrofBytes) = 0;
92 };
93 
94 
95 class bstream : public bistream,
96 				public bostream
97 {
98   public:
99 	uintt 		        seek(
100 							intt 			i_nDistanceFromBegin,
101                             seek_dir        i_eStartPoint = ::csv::beg );
102 	uintt 		        position() const;
103 
104   private:
105 	virtual uintt 		do_seek(
106 							intt 			i_nDistance,
107                             seek_dir        i_eStartPoint = ::csv::beg ) = 0;
108 	virtual uintt 		inq_position() const = 0;
109 };
110 
111 
112 // IMPLEMENTATION
113 inline uintt
read(void * o_pDest,uintt i_nNrofBytes)114 bistream::read( void *	       o_pDest,
115 			   uintt           i_nNrofBytes)
116     { return do_read(o_pDest, i_nNrofBytes); }
117 inline bool
eod() const118 bistream::eod() const
119     { return inq_eod(); }
120 
121 inline uintt
write(const void * i_pSrc,uintt i_nNrofBytes)122 bostream::write( const void *   i_pSrc,
123 				 uintt          i_nNrofBytes)
124     { return do_write( i_pSrc, i_nNrofBytes ); }
125 inline uintt
write(const char * i_sSrc)126 bostream::write( const char * i_sSrc )
127     { return write( i_sSrc, strlen(i_sSrc) ); }
128 inline uintt
write(const String & i_sSrc)129 bostream::write( const String &	i_sSrc )
130     { return write( i_sSrc.c_str(), i_sSrc.length() ); }
131 
132 inline uintt
seek(intt i_nDistance,seek_dir i_eStartPoint)133 bstream::seek( intt     i_nDistance,
134                seek_dir i_eStartPoint )
135     { return do_seek( i_nDistance, i_eStartPoint ); }
136 inline uintt
position() const137 bstream::position() const
138     { return inq_position(); }
139 
140 
141 
142 }   // namespace csv
143 
144 
145 #endif
146 
147