LCOV - code coverage report
Current view: top level - zerobuf - DynamicSubAllocator.cpp (source / functions) Hit Total Coverage
Test: ZeroBuf Lines: 14 18 77.8 %
Date: 2018-01-09 16:38:26 Functions: 6 12 50.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2015, Human Brain Project
       3             :  *                     Stefan.Eilemann@epfl.ch
       4             :  *                     grigori.chevtchenko@epfl.ch
       5             :  */
       6             : 
       7             : #include "DynamicSubAllocator.h"
       8             : #include <zerobuf/version.h>
       9             : 
      10             : #include <cstring>
      11             : 
      12             : namespace zerobuf
      13             : {
      14             : template <class A>
      15          92 : DynamicSubAllocatorBase<A>::DynamicSubAllocatorBase(A& parent,
      16             :                                                     const size_t headerIndex,
      17             :                                                     const size_t elementIndex,
      18             :                                                     const size_t size)
      19             :     : _parent(parent)
      20             :     , _header(headerIndex)
      21             :     , _element(elementIndex)
      22          92 :     , _size(size)
      23             : {
      24          92 : }
      25             : 
      26             : template <class A>
      27         184 : DynamicSubAllocatorBase<A>::~DynamicSubAllocatorBase()
      28             : {
      29         184 : }
      30             : 
      31             : template <class A>
      32          52 : uint8_t* DynamicSubAllocatorBase<A>::getData()
      33             : {
      34          52 :     return _parent.template getDynamic<uint8_t>(_header) + _element * _size;
      35             : }
      36             : 
      37             : template <>
      38           0 : uint8_t* DynamicSubAllocatorBase<const Allocator>::getData()
      39             : {
      40           0 :     throw std::runtime_error("Non-const data access on const data");
      41             : }
      42             : 
      43             : template <class A>
      44         312 : const uint8_t* DynamicSubAllocatorBase<A>::getData() const
      45             : {
      46             :     // need explicit const allocator to not drift to mutable getDynamic()
      47             :     // in case parent allocator is of type ConstAllocator.
      48         312 :     const auto& parent = const_cast<const A&>(_parent);
      49         312 :     return parent.template getDynamic<uint8_t>(_header) + _element * _size;
      50             : }
      51             : 
      52             : template <class A>
      53           4 : void DynamicSubAllocatorBase<A>::copyBuffer(const void* data, const size_t size)
      54             : {
      55           4 :     if (size != _size)
      56           0 :         throw std::runtime_error(
      57           0 :             "Can't copy buffer of different size into a static-sized member");
      58           4 :     ::memcpy(getData(), data, size);
      59           4 : }
      60             : 
      61             : template class DynamicSubAllocatorBase<Allocator>;
      62             : template class DynamicSubAllocatorBase<const Allocator>;
      63             : }

Generated by: LCOV version 1.11