Bitstream Interpretation Library (BIL)  0.1
TileLookup2D.cpp
Go to the documentation of this file.
1 
6 #include <xdlrc/model/Device.hpp>
8 
9 using namespace bil;
10 
11 
13  m_rowCount(0),
14  m_columnCount(0),
15  m_tiles()
16 {
17 
18 }
19 
20 
21 unsigned TileLookup2D::rowCount() const
22 {
23  return m_rowCount;
24 }
25 
26 
27 unsigned TileLookup2D::columnCount() const
28 {
29  return m_columnCount;
30 }
31 
32 
33 const Tile* TileLookup2D::lookup(unsigned row, unsigned column) const
34 {
35  if (row >= m_rowCount) return 0;
36  if (column >= m_columnCount) return 0;
37  return m_tiles[(row * m_columnCount) + column];
38 }
39 
40 
41 void TileLookup2D::reset(const Device& device)
42 {
43  // get device row and col count
44  unsigned rowCount = device.maxRowIndex() + 1;
45  unsigned columnCount = device.maxColumnIndex() + 1;
46 
47  // set lookup size according to row and col count
48  m_tiles.clear();
49  m_tiles.resize(rowCount * columnCount, 0);
50  m_rowCount = rowCount;
51  m_columnCount = columnCount;
52 
53  // set pointers to tiles
54  const Tiles& tiles = device.tiles();
55  size_t tilesSize = tiles.size();
56  for (size_t i = 0; i < tilesSize; ++i)
57  {
58  const Tile& tile = tiles[i];
59  size_t index = (tile.row() * m_columnCount) + tile.column();
60  m_tiles[index] = &tile;
61  }
62 }
63 
64 
66 {
67  m_rowCount = 0;
68  m_columnCount = 0;
69  m_tiles.clear();
70 }