#include "shiftdatasource.hh"
#include "shiftpropagator.hh"


using namespace Gecode;


ShiftDataSource::ShiftDataSource (Space& home, DataSource& parent, int64_t block_offset) : 
  DataSource (home),
  m_parent (parent),
  m_unavailable (home, Int::Limits::min, Int::Limits::max),
  m_block_offset (-block_offset)
{
  shift (home, m_parent.unavailable (), m_unavailable, m_block_offset);
}


ShiftDataSource::ShiftDataSource (bool share, Space& home, DataSource& parent, ShiftDataSource& ds) : 
  DataSource (share, home, ds),
  m_parent (parent),
  m_block_offset (ds.m_block_offset)
{
  m_unavailable.update (home, share, ds.m_unavailable);
}


IntVar& ShiftDataSource::unavailable ()
{
  return m_unavailable;
}


unsigned char ShiftDataSource::read (int64_t offset) const
{
  // int block = offset / BLOCK_SIZE;
  // assert (!m_unavailable.in (block));
  return m_parent.read (offset - BLOCK_SIZE * m_block_offset);
}


void ShiftDataSource::read (int64_t block, unsigned char* buffer) const
{
  m_parent.read (block - m_block_offset, buffer);
}


void ShiftDataSource::print (std::ostream& os) const 
{
  os << "ShiftDataSource (";
  m_parent.print (os);
  os << ", " << m_unavailable << ")";
}
