12#ifndef ALGORITHM_PAGEPARSER_H
13#define ALGORITHM_PAGEPARSER_H
37typename std::enable_if<std::is_void<T>::value,
size_t>
::type
45typename std::enable_if<std::is_integral<T>::value, T>
::type
51template <
typename GroupT>
58 using ReturnType = size_t;
59 using T =
typename std::remove_pointer<
decltype(groupdata)>
::type;
61 static_assert(std::is_integral<T>::value || std::is_void<T>::value,
62 "A function for extracting the number of elements from the "
63 "group header must be specified for non-trivial types");
158template <
typename PageHeaderT,
161 typename GroupT =
void,
162 typename GetNElementsFctT = pageparser::DefaultGetNElementsFctT<GroupT>>
175 "Page Header and at least one element have to fit into page");
182 template <
typename T>
185 : mBuffer(nullptr), mBufferIsConst(
std::is_const<T>::
value), mSize(
size), mGetNElementsFct(getNElementsFct), mNPages(
size > 0 ? ((
size - 1) /
page_size) + 1 : 0), mGroupHeader(pageparser::alloc<
GroupType>())
187 static_assert(
sizeof(T) ==
sizeof(
BufferType),
188 "buffer required to be byte-type");
199 template <
typename T>
217 mPosition = position;
218 size_t argument = mPosition;
219 if (!mParent->
getElement(argument, mElement)) {
221 mPosition = argument;
223 mNextPosition = argument;
235 mPosition = mNextPosition;
236 size_t argument = mPosition;
237 if (!mParent->
getElement(argument, mElement)) {
239 mPosition = argument;
241 mNextPosition = argument;
260 return mPosition == rh.mPosition;
265 return mPosition != rh.mPosition;
275 template <
typename U =
void>
276 typename std::enable_if<!std::is_const<value_type>::value, U>
::type sync()
278 if (std::memcmp(&mElement, &mBackup,
sizeof(
value_type)) != 0) {
285 template <
typename U =
void>
286 typename std::enable_if<std::is_const<value_type>::value, U>
::type sync()
291 template <
typename U =
void>
292 typename std::enable_if<!std::is_const<value_type>::value, U>
::type backup()
298 template <
typename U =
void>
299 typename std::enable_if<std::is_const<value_type>::value, U>
::type backup()
314 assert(std::is_void<GroupType>::value);
316 if (position >= mSize) {
317 assert(position == mSize);
328 auto target = mBuffer + position;
332 template <
typename T>
336 if (std::is_void<T>::value) {
340 memcpy(groupHeader, mBuffer + position, pageparser::sizeofGroupHeader<T>());
341 return mGetNElementsFct(groupHeader);
348 if (position >= mSize) {
349 assert(position == mSize);
355 if (!std::is_void<GroupType>::value) {
356 if (mNGroupElements == 0) {
365 if (position > mSize) {
374 position += pageparser::sizeofGroupHeader<GroupType>();
375 }
while (mNGroupElements == 0);
378 size_t required = pageparser::sizeofGroupHeader<GroupType>() + mNGroupElements *
sizeof(
value_type);
385 required -=
sizeof(
PageHeaderType) + pageparser::sizeofGroupHeader<GroupType>();
386 if (position + required > mSize) {
387 throw std::runtime_error(
388 "format error: the number of group elements "
389 "does not fit into the remaining buffer");
393 const_cast<PageParser*
>(
this)->mNGroupElements -= 1;
406 auto source = mBuffer + position;
415 template <
typename SwitchT>
428 if (copySize > pageCapacity) {
431 copySize = pageCapacity;
435 position += copySize;
446 position += copySize;
471 if (mBufferIsConst) {
475 throw std::runtime_error(
"the underlying buffer is not writeable");
487 bool mBufferIsConst =
false;
492 size_t mNGroupElements = 0;
Class for time synchronization of RawReader instances.
const GroupType * getGroupHeader() const
bool operator==(const SelfType &rh) const
std::ptrdiff_t difference_type
bool operator!=(const SelfType &rh) const
Iterator(ParentType const *parent, size_t position=0)
typename std::remove_const< value_type >::type ElementType
std::forward_iterator_tag iterator_category
static const size_t page_size
Iterator< value_type > iterator
const_iterator begin() const
const GroupType getGroupHeader() const
size_t copy(const BufferType *source, BufferType *target, size_t pageCapacity) const
bool getElement(size_t &position, value_type &element) const
retrieve an object at position
PageHeaderT PageHeaderType
GetNElementsFctT GetNElements
Iterator< const value_type > const_iterator
PageParser(T *buffer, size_t size, GetNElements getNElementsFct=pageparser::defaultGetNElementsFct)
const_iterator end() const
size_t readGroupHeader(size_t position, T *groupHeader) const
size_t setElement(size_t position, const value_type &element) const
set an object at position
std::true_type TargetInPageBuffer
std::false_type SourceInPageBuffer
GLsizei GLsizei GLchar * source
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum GLenum type
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
std::enable_if< std::is_void< T >::value, size_t >::type extractNElements(T *v)
auto defaultGetNElementsFct
void set< void >(void *, size_t)
void free< void >(void *)
size_t sizeofGroupHeader< void >()
size_t sizeofGroupHeader()
size_t(*)(const GroupT *) DefaultGetNElementsFctT
constexpr size_t PageSize
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.