]> git.ipfire.org Git - thirdparty/squid.git/blame - src/StoreIOBuffer.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / StoreIOBuffer.h
CommitLineData
c8be6d7b 1/*
bbc27441 2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
c8be6d7b 3 *
bbc27441
AJ
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.
c8be6d7b 7 */
8
2512d159 9#ifndef SQUID_STOREIOBUFFER_H
10#define SQUID_STOREIOBUFFER_H
11
12/* TODO: move this and the range() method into a .cci */
d0df2779 13#include "MemBuf.h"
602d9612 14#include "Range.h"
c8be6d7b 15
62e76326 16class StoreIOBuffer
17{
18
528b2c61 19public:
967a359a 20 StoreIOBuffer():length(0), offset (0), data (NULL) {flags.error = 0;}
62e76326 21
47f6e231 22 StoreIOBuffer(size_t aLength, int64_t anOffset, char *someData) :
9e008dda 23 length (aLength), offset (anOffset), data (someData) {
63326655 24 flags.error = 0;
62e76326 25 }
26
d0df2779 27 /* Create a StoreIOBuffer from a MemBuf and offset */
28 /* NOTE that MemBuf still "owns" the pointers, StoreIOBuffer is just borrowing them */
47f6e231 29 StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset) :
d0df2779 30 length(aMemBuf->contentSize()),
31 offset (anOffset),
26ac0430 32 data(aMemBuf->content()) {
d0df2779 33 flags.error = 0;
34 }
35
0ad2b63b
CT
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
26ac0430 43 Range<int64_t> range() const {
47f6e231 44 return Range<int64_t>(offset, offset + length);
2512d159 45 }
46
26ac0430
AJ
47 void dump() const {
48 if (fwrite(data, length, 1, stderr)) {}
49 if (fwrite("\n", 1, 1, stderr)) {}
d0df2779 50 }
51
26ac0430 52 struct {
3d0ac046
HN
53 unsigned error:1;
54 } flags;
c8be6d7b 55 size_t length;
47f6e231 56 int64_t offset;
c8be6d7b 57 char *data;
58};
59
8822ebee
AR
60inline
61std::ostream &
62operator <<(std::ostream &os, const StoreIOBuffer &b)
63{
64 return os << "ioBuf(@" << b.offset << ", len=" << b.length << ", " <<
d9fc6862 65 (void*)b.data << (b.flags.error ? ", ERR" : "") << ')';
8822ebee
AR
66}
67
2512d159 68#endif /* SQUID_STOREIOBUFFER_H */