view interps/rail/src/Board.cpp @ 6558:4ad4b893c806

<b_jonas> learn links are one of the very few HTML renderers that don\'t try to store a full document tree with heavyweight objects for each node just in case javascript wants to modify it later, so it\'s the only engine that can render those HTMLs that are automatically converted from a PDF and put each letter to a separate element.
author HackBot
date Thu, 14 Jan 2016 11:54:35 +0000
parents 859f9b4339e6
children
line wrap: on
line source

// Board.cpp

#include "lib.h"
#include "Board.h"

using namespace std;

Board::Board()
{
}

Board::~Board()
{
}

Board::Board(string const & newName, list<string> const & newData)
{
  reset(newName, newData);
}

// This scheme makes maxX and maxY one greater than they have to
// be. But this doesn't matter.
void Board::reset(string const & newName, list<string> const & newData)
{
  maxX = 0;
  maxY = 0;
  name = newName;
  data.clear();
  data.reserve(newData.size());
  list<string>::const_iterator sourcePos = newData.begin();
  list<string>::const_iterator sourceLimit = newData.end();
  for (; sourcePos != sourceLimit; ++sourcePos)
  {
    data.push_back(*sourcePos);
    maxX = max(maxX, static_cast<int>(sourcePos->size()));
    ++maxY;
  }
}

char Board::at(Vec pos) const
{
  char result = ' ';
  if (pos.y >= 0 && pos.y < static_cast<int>(data.size()))
  {
    if (pos.x >= 0 && pos.x < static_cast<int>(data[pos.y].size()))
    {
      result = data[pos.y][pos.x];
    }
  }
  return result;
}

string const & Board::getName(void) const
{
  return name;
}

int Board::getMinX(void) const
{
  return 0;
}

int Board::getMaxX(void) const
{
  return maxX;
}

int Board::getMinY(void) const
{
  return 0;
}

int Board::getMaxY(void) const
{
  return maxY;
}