12 #ifndef THRILL_DATA_BLOCK_READER_HEADER 13 #define THRILL_DATA_BLOCK_READER_HEADER 41 template <
typename BlockSource>
96 size_t code = GetRaw<size_t>();
97 if (code !=
typeid(
T).hash_code()) {
98 die(
"BlockReader::Next() attempted to retrieve item " 99 "with different typeid! - expected " 109 template <
typename T>
129 template <
typename ItemType>
131 std::vector<ItemType> out;
132 while (
HasNext()) out.emplace_back(Next<ItemType>());
139 template <
typename ItemType>
141 static constexpr
bool debug =
false;
143 std::vector<Block> out;
144 if (n == 0)
return out;
171 sLOG <<
"partial first:" << out.back();
181 sLOG <<
"exit1 after batch.";
190 out.emplace_back(std::move(next_block));
191 sLOG <<
"middle:" << out.back();
193 next_block =
source_.NextBlockUnpinned();
196 sLOG <<
"exit2 after batch.";
229 std::vector<PinnedBlock> out_pinned;
245 out.emplace_back(std::move(pb).MoveToBlock());
250 sLOG <<
"partial last:" << out.back();
252 sLOG <<
"exit3 after batch:" 267 Byte* cdata =
reinterpret_cast<Byte*
>(outdata);
272 std::copy(current_, current_ + partial_size, cdata);
274 cdata += partial_size;
275 size -= partial_size;
278 throw std::runtime_error(
"Data underflow in BlockReader.");
292 Read(const_cast<char*>(out.data()), out.size());
304 throw std::runtime_error(
"Data underflow in BlockReader.");
317 throw std::runtime_error(
"Data underflow in BlockReader.");
324 template <
typename Type>
328 "You only want to GetRaw() POD types as raw values.");
338 Read(&ret,
sizeof(ret));
375 block_ = source_.NextBlock();
378 if (!block_.IsValid())
return false;
381 block_collect_->emplace_back(block_);
383 current_ = block_.data_begin();
384 end_ = block_.data_end();
385 num_items_ = block_.num_items();
386 typecode_verify_ = block_.typecode_verify();
392 block_ = std::move(block);
405 #endif // !THRILL_DATA_BLOCK_READER_HEADER Block combines a reference to a read-only ByteBlock and book-keeping information. ...
std::vector< Block > GetItemBatch(size_t n)
bool typecode_verify() const
return typecode_verify from Block
#define sLOG
Default logging method: output if the local debug variable is true.
std::vector< ItemType > ReadComplete()
#define TLX_ATTRIBUTE_ALWAYS_INLINE
size_t num_items() const
return number of items beginning in this block
size_t first_item_absolute() const
accessor to first_item_ (absolute in ByteBlock)
const Byte * data_end() const
return pointer to end of valid data
std::string Read(size_t datalen)
PinnedBlock CopyBlock() const
return current block for debugging
TLX_ATTRIBUTE_ALWAYS_INLINE T Next()
Next() reads a complete item T.
BlockReader & Read(void *outdata, size_t size)
BlockReader(BlockSource &&source)
Start reading a BlockSource.
A non-pinned counting pointer to a ByteBlock.
#define die(msg)
Instead of std::terminate(), throw the output the message via an exception.
BlockReader & operator=(const BlockReader &)=delete
non-copyable: delete assignment operator
bool NextBlock()
Call source_.NextBlock with appropriate parameters.
size_t num_items_
remaining number of items starting in this block
static constexpr bool g_self_verify
void Reset()
release pin on block and reset Block pointer to nullptr
#define sLOG0
Override default output: never or always output log.
uint8_t Byte
type of underlying memory area
BlockReader()=default
default constructor
BlockReader takes Block objects from BlockSource and allows reading of a) serializable Items or b) ar...
ByteBlockPtr byte_block() const
return current ByteBlock
BlockSource & source()
Return reference to enclosed BlockSource.
Byte GetByte()
Fetch a single byte from the current block, advancing the cursor.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
static constexpr bool debug
const ByteBlockPtr & byte_block() const
access to byte_block_
TLX_ATTRIBUTE_ALWAYS_INLINE T NextNoSelfVerify()
static const size_t bytes
number of bytes in uint_pair
const Byte * end_
pointer to end of current block.
size_t num_items() const
return number of items beginning in this block
const Byte * current_
current read pointer into current block of file.
std::string hexdump_type(const Type &t)
Dump a (binary) item as a sequence of uppercase hexadecimal pairs.
A pinned / pin-counted derivative of a Block.
std::vector< PinnedBlock > * block_collect_
pointer to vector to collect blocks in GetItemRange.
TLX_ATTRIBUTE_ALWAYS_INLINE bool HasNext()
HasNext() returns true if at least one more item is available.
BlockReader & Skip(size_t items, size_t bytes)
Advance the cursor given number of bytes without reading them.
static constexpr bool self_verify
PinnedByteBlockPtr CopyPinnedByteBlock() const
void LoadBlock(PinnedBlock &&block)
Load Block into Reader.
PinnedBlock block_
The current block being read, this holds a shared pointer reference.
bool IsValid() const
Return whether the enclosed ByteBlock is valid.
const Byte * data_begin() const
return pointer to beginning of valid data
size_t typecode_verify() const
Returns typecode_verify_.
bool IsValid() const
Return whether the enclosed ByteBlock is valid.
TLX_ATTRIBUTE_ALWAYS_INLINE Type GetRaw()