1
#ifndef _DATA_FILE_SEGMENT_H_
2
#define _DATA_FILE_SEGMENT_H_
16
* Identifies a data segment of a file. This segment is defined by an offset
17
* and a length (number of bytes), both of them with an unsigned integer of
18
* 64 bits. This class is serializable and can be printed.
23
uint64_t offset; ///< Offset of the data segment.
24
uint64_t length; ///< Length of the data segment.
28
* Identifies a null segment, with the offset as well as the length
31
static const FileSegment Null;
35
* Initializes all the member variables with zero, being a
44
* Initializes the segment with the given parameters.
45
* @param offset Offset of the segment.
46
* @param length Length of the segment.
48
FileSegment(uint64_t offset, uint64_t length)
50
this->offset = offset;
51
this->length = length;
57
FileSegment(const FileSegment& segment)
65
FileSegment& operator=(const FileSegment& segment)
67
offset = segment.offset;
68
length = segment.length;
74
* Removes the first bytes of the segment. Modifies the segment as
75
* if a number of bytes (specified by the parameter) was removed
76
* from the beginning of the segment.
77
* @param count Number of bytes to remove.
78
* @return <code>*this</code>.
80
FileSegment& RemoveFirst(int count)
82
assert((length - count) >= 0);
91
* Removes the last bytes of the segment. Modifies the segment as
92
* if a number of bytes (specified by the parameter) was removed
93
* from the end of the segment.
94
* @param count Number of bytes to remove.
95
* @return <code>*this</code>.
97
FileSegment& RemoveLast(int count)
99
assert((length - count) >= 0);
107
* Returns <code>true</code> if the segment is contiguous to
108
* another given segment, so the first byte of the given segment
109
* is just the next byte after the last byte of the segment.
111
bool IsContiguousTo(const FileSegment& segment) const
113
return ((offset + length) == segment.offset);
116
bool operator==(const FileSegment& segment) const
118
return ((offset == segment.offset) && (length == segment.length));
121
bool operator!=(const FileSegment& segment) const
123
return ((offset != segment.offset) || (length != segment.length));
126
template<typename T> T& SerializeWith(T& stream)
128
return (stream & offset & length);
131
friend ostream& operator << (ostream &out, const FileSegment &segment)
133
out << "[" << segment.offset << ":" << segment.length << "]";
137
virtual ~FileSegment()
146
#endif /* _DATA_FILE_SEGMENT_H_ */