Welcome to mirror list, hosted at ThFree Co, Russian Federation.

intrusive_vector.hpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 30e5fad58018c6c9b4e4ef409cfecd8999effe7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include "../base/assert.hpp"

#include "../std/stdint.hpp"

namespace df
{

enum FillDirection
{
  Forward,
  Backward
};

template <typename T>
class IntrusiveVector
{
public:
  IntrusiveVector(void * memoryBuffer, uint32_t byteCount)
    : m_memory(reinterpret_cast<T *>(memoryBuffer))
    , m_direction(Forward)
  {
    ASSERT(byteCount % sizeof(T) == 0, ());
    m_capacity = byteCount / sizeof(T);
    m_size = 0;
  }

  void SetFillDirection(FillDirection direction)
  {
    ASSERT(m_size == 0, ());
    m_direction = direction;
  }

  void PushBack(T const & value)
  {
    ASSERT(m_size < m_capacity, ());
    if (m_direction == Forward)
      m_memory[m_size++] = value;
    else
    {
      m_memory[m_capacity - m_size - 1] = value;
      m_size++;
    }
  }

private:
  T * m_memory;
  FillDirection m_direction;
  uint32_t m_capacity;
  uint32_t m_size;
};

}