Sirikata
|
Range identifier -- specifies two segments of a file. More...
#include <Range.hpp>
Public Types | |
typedef cache_usize_type | base_type |
typedef cache_usize_type | length_type |
typedef length_type | size_type |
typedef cache_ssize_type | difference_type |
Public Member Functions | |
Range (bool wholeFile) | |
Pass in true for the whole file, and false for an empty range. | |
Range (base_type start, bool wholeFile) | |
Goes from a start byte for the rest of the file--false means an empty range. | |
Range (base_type start, base_type length, Initializer type, bool wholeFile=false) | |
Generic constructor for a partial range. | |
Range (const Range &other) | |
Copy constructor. | |
bool | goesToEndOfFile () const |
Ranges contain an additional boolean whether they extend throughout the file. | |
base_type | startbyte () const |
Returns the initial byte--will be 0 if this references the whole file. | |
length_type | length () const |
The length -- may not be accurate in the case that goesToEndOfFile() returns true. | |
length_type | size () const |
base_type | endbyte () const |
The ending byte--again, when goesToEndOfFile() is true, this may be undefined. | |
void | setLength (length_type l, bool wholeFile) |
Sets the length of the range. | |
void | setBase (base_type s) |
setter for startbyte(). | |
bool | operator< (const Range &other) const |
Ordering comparator. | |
template<class ListType > | |
bool | isContainedBy (const ListType &list) const |
Checks if one range is inside a list of ranges (or any class with begin() and end() whose elements are ranges. | |
bool | contains (const Range &other) const |
bool | isContainedBy (const Range &other) const |
template<class ListType > | |
void | addToList (const typename ListType::value_type &data, ListType &list) const |
Removes overlapping ranges if possible (assumes a list ordered by starting byte). | |
bool | operator== (const Range &other) const |
equality comparision | |
Static Public Member Functions | |
template<class ListType > | |
static std::ostream & | printRangeList (std::ostream &os, const ListType &cdata, Range checkFor=Range(false), bool exact=false) |
Private Member Functions | |
Range (base_type start, base_type end) | |
Cause an error for accidentally calling the (int,bool) constructor. | |
Private Attributes | |
base_type | mStart |
A 64-bit starting byte. | |
length_type | mLength |
Length should be 64-bit as ranges can apply to files on disk. | |
bool | mWholeFile |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Range &range) |
Printing a range. |
Range identifier -- specifies two segments of a file.
Cause an error for accidentally calling the (int,bool) constructor.
Sirikata::Transfer::Range::Range | ( | bool | wholeFile | ) | [inline, explicit] |
Pass in true for the whole file, and false for an empty range.
Sirikata::Transfer::Range::Range | ( | base_type | start, |
bool | wholeFile | ||
) | [inline] |
Goes from a start byte for the rest of the file--false means an empty range.
Sirikata::Transfer::Range::Range | ( | base_type | start, |
base_type | length, | ||
Initializer | type, | ||
bool | wholeFile = false |
||
) | [inline] |
Generic constructor for a partial range.
If type==LENGTH, specifies the start byte and the length. If type==BOUNDS, specifies the starting and the ending byte. Generally, the wholeFile flag will be false here.
Sirikata::Transfer::Range::Range | ( | const Range & | other | ) | [inline] |
Copy constructor.
void Sirikata::Transfer::Range::addToList | ( | const typename ListType::value_type & | data, |
ListType & | list | ||
) | const [inline] |
Removes overlapping ranges if possible (assumes a list ordered by starting byte).
References endbyte(), goesToEndOfFile(), length(), and startbyte().
Referenced by Sirikata::Transfer::DiskCacheLayer::unserializeRanges().
bool Sirikata::Transfer::Range::contains | ( | const Range & | other | ) | const [inline] |
References endbyte(), goesToEndOfFile(), and startbyte().
Referenced by isContainedBy().
base_type Sirikata::Transfer::Range::endbyte | ( | ) | const [inline] |
The ending byte--again, when goesToEndOfFile() is true, this may be undefined.
References mLength, and mStart.
Referenced by addToList(), contains(), Sirikata::Transfer::DenseDataList::dataAt(), Sirikata::Transfer::DenseData::dataAt(), isContainedBy(), Sirikata::Transfer::SparseData::const_iterator::setDataPtr(), and Sirikata::Transfer::Chunk::toString().
bool Sirikata::Transfer::Range::goesToEndOfFile | ( | ) | const [inline] |
Ranges contain an additional boolean whether they extend throughout the file.
This is not related to endbyte(), but endbyte() is often set to 0 if the length is unknown.
References mWholeFile.
Referenced by addToList(), contains(), Sirikata::Transfer::DenseDataList::dataAt(), isContainedBy(), and Sirikata::Transfer::Chunk::toString().
bool Sirikata::Transfer::Range::isContainedBy | ( | const ListType & | list | ) | const [inline] |
Checks if one range is inside a list of ranges (or any class with begin() and end() whose elements are ranges.
--such as SparseData)
References endbyte(), goesToEndOfFile(), and mStart.
Referenced by Sirikata::Transfer::DenseDataList::contains(), Sirikata::Transfer::DiskCacheLayer::CacheData::contains(), and Sirikata::Transfer::DenseDataList::contiguous().
bool Sirikata::Transfer::Range::isContainedBy | ( | const Range & | other | ) | const [inline] |
References contains().
length_type Sirikata::Transfer::Range::length | ( | ) | const [inline] |
The length -- may not be accurate in the case that goesToEndOfFile() returns true.
In the case of DenseData, this should be equal to the number of bytes in the DenseData.
References mLength.
Referenced by addToList(), Sirikata::Transfer::DenseData::append(), Sirikata::Transfer::DenseData::asString(), Sirikata::Transfer::DenseDataList::dataAt(), Sirikata::Transfer::DenseData::DenseData(), Sirikata::Transfer::DenseData::end(), and size().
bool Sirikata::Transfer::Range::operator< | ( | const Range & | other | ) | const [inline] |
Ordering comparator.
References mLength, mStart, and mWholeFile.
bool Sirikata::Transfer::Range::operator== | ( | const Range & | other | ) | const [inline] |
equality comparision
References mLength, mStart, and mWholeFile.
void Sirikata::Transfer::Range::setBase | ( | base_type | s | ) | [inline] |
setter for startbyte().
References mStart.
void Sirikata::Transfer::Range::setLength | ( | length_type | l, |
bool | wholeFile | ||
) | [inline] |
Sets the length of the range.
References mLength, and mWholeFile.
length_type Sirikata::Transfer::Range::size | ( | ) | const [inline] |
References length().
base_type Sirikata::Transfer::Range::startbyte | ( | ) | const [inline] |
Returns the initial byte--will be 0 if this references the whole file.
References mStart.
Referenced by addToList(), contains(), Sirikata::Transfer::DenseDataList::dataAt(), Sirikata::Transfer::DenseData::dataAt(), Sirikata::Transfer::SparseData::const_iterator::setDataPtr(), and Sirikata::Transfer::Chunk::toString().
std::ostream& operator<< | ( | std::ostream & | os, |
const Range & | range | ||
) | [friend] |
Printing a range.
The format is: "[1)" for empty, "[8,10)" for a two-byte-long range, and "[8,10 => eof)" for data with two bytes but will extend for the whole file. "[0 => eof)" for the whole file.
Length should be 64-bit as ranges can apply to files on disk.
Referenced by endbyte(), length(), operator<(), operator==(), and setLength().
base_type Sirikata::Transfer::Range::mStart [private] |
A 64-bit starting byte.
Referenced by endbyte(), isContainedBy(), operator<(), operator==(), setBase(), and startbyte().
bool Sirikata::Transfer::Range::mWholeFile [private] |
Referenced by goesToEndOfFile(), operator<(), operator==(), and setLength().