WvStreams
Main Page
Modules
Classes
Files
File List
File Members
include
wvfunctorencoder.h
1
/* -*- Mode: C++ -*-
2
* Worldvisions Weaver Software:
3
* Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4
*
5
* Provides an encoder for applying a functor to data extracted
6
* from a buffer and stored in another.
7
* Assumes binary input is in machine order.
8
*/
9
#ifndef __WVFUNCTORENCODER_H
10
#define __WVFUNCTORENCODER_H
11
12
#include "wvtypedencoder.h"
13
30
template
<
class
IT,
class
OT,
class
FT>
31
class
WvFunctorEncoder
:
public
WvTypedEncoder
<IT, OT>
32
{
33
protected
:
34
FT f;
35
36
public
:
37
typedef
FT FType;
38
typedef
IT IType;
39
typedef
OT OType;
40
typedef
WvBufBase<IType>
IBuffer
;
41
typedef
WvBufBase<OType>
OBuffer
;
42
WvFunctorEncoder
(
const
FType &f) : f(f) { }
43
virtual
~
WvFunctorEncoder
() { }
44
45
protected
:
46
virtual
bool
_typedencode
(
IBuffer
&inbuf,
OBuffer
&outbuf,
47
bool
flush
)
48
{
49
size_t
count;
50
while
( (count = inbuf.
optgettable
()) )
51
{
52
size_t
avail = outbuf.
optallocable
();
53
if
(avail == 0)
54
return
!
flush
;
55
if
(avail < count)
56
count = avail;
57
const
IType *indata = inbuf.
get
(count);
58
OType *outdata = outbuf.
alloc
(count);
59
while
(count-- > 0)
60
*(outdata++) = f(*(indata++));
61
}
62
return
true
;
63
}
64
virtual
bool
_reset
()
65
{
66
// Assume most functor encoders will be stateless and therefore
67
// support reset() implicitly.
68
// If this is not the case, then override this method for
69
// particular subclasses to return false.
70
return
true
;
71
}
72
};
73
74
#endif // __WVFUNCTORENCODER_H
Generated on Thu Mar 14 2013 19:25:35 for WvStreams by
1.8.1.2