#include "interdatasource.hh"
#include "interdomainsubsetpropagator.hh"


using namespace Gecode;


InterDataSource::InterDataSource (Space& home, DataSource& parent, IntSet domain_restriction) : 
  DataSource (home),
  m_parent (parent),
  m_unavailable (home, Int::Limits::min, Int::Limits::max)
{
  inter_domain_subset (home, m_parent.unavailable (), m_unavailable, domain_restriction);
}


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


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


unsigned char InterDataSource::read (int64_t offset) const
{
  // int block = offset / BLOCK_SIZE;
  // assert (!m_unavailable.in (block));
  unsigned char result = m_parent.read (offset);
  // std::cout << "inter read: " << offset << " = " << (unsigned int) result << std::endl;
  return result;
}


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


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