1 | /* |
---|
2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
---|
3 | * |
---|
4 | * Squid software is distributed under GPLv2+ license and includes |
---|
5 | * contributions from numerous individuals and organizations. |
---|
6 | * Please see the COPYING and CONTRIBUTORS files for details. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef SQUID_STOREIOBUFFER_H |
---|
10 | #define SQUID_STOREIOBUFFER_H |
---|
11 | |
---|
12 | /* TODO: move this and the range() method into a .cci */ |
---|
13 | #include "MemBuf.h" |
---|
14 | #include "Range.h" |
---|
15 | |
---|
16 | class StoreIOBuffer |
---|
17 | { |
---|
18 | |
---|
19 | public: |
---|
20 | StoreIOBuffer():length(0), offset (0), data (NULL) {flags.error = 0;} |
---|
21 | |
---|
22 | StoreIOBuffer(size_t aLength, int64_t anOffset, char *someData) : |
---|
23 | length (aLength), offset (anOffset), data (someData) { |
---|
24 | flags.error = 0; |
---|
25 | } |
---|
26 | |
---|
27 | /* Create a StoreIOBuffer from a MemBuf and offset */ |
---|
28 | /* NOTE that MemBuf still "owns" the pointers, StoreIOBuffer is just borrowing them */ |
---|
29 | StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset) : |
---|
30 | length(aMemBuf->contentSize()), |
---|
31 | offset (anOffset), |
---|
32 | data(aMemBuf->content()) { |
---|
33 | flags.error = 0; |
---|
34 | } |
---|
35 | |
---|
36 | StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset, size_t anLength) : |
---|
37 | length(anLength), |
---|
38 | offset (anOffset), |
---|
39 | data(aMemBuf->content()) { |
---|
40 | flags.error = 0; |
---|
41 | } |
---|
42 | |
---|
43 | Range<int64_t> range() const { |
---|
44 | return Range<int64_t>(offset, offset + length); |
---|
45 | } |
---|
46 | |
---|
47 | void dump() const { |
---|
48 | if (fwrite(data, length, 1, stderr)) {} |
---|
49 | if (fwrite("\n", 1, 1, stderr)) {} |
---|
50 | } |
---|
51 | |
---|
52 | struct { |
---|
53 | unsigned error:1; |
---|
54 | } flags; |
---|
55 | size_t length; |
---|
56 | int64_t offset; |
---|
57 | char *data; |
---|
58 | }; |
---|
59 | |
---|
60 | inline |
---|
61 | std::ostream & |
---|
62 | operator <<(std::ostream &os, const StoreIOBuffer &b) |
---|
63 | { |
---|
64 | return os << "ioBuf(@" << b.offset << ", len=" << b.length << ", " << |
---|
65 | (void*)b.data << (b.flags.error ? ", ERR" : "") << ')'; |
---|
66 | } |
---|
67 | |
---|
68 | #endif /* SQUID_STOREIOBUFFER_H */ |
---|
69 | |
---|