#include "workunit.h"

workunit::workunit()
{
}

workunit::~workunit()
{
}

int workunit::init( int tx, int ty , int s, int p )
{
  mytransx = tx;
  mytransy = ty;
  myslice = s;
  myparnum = p;

  return 0;
}

int workunit::pack( char **buf, int &size )
{
  size = 4*sizeof(int);
  *buf = new char[size];
  memcpy( *buf, &mytransx, sizeof(int) );
  memcpy( (*buf) + sizeof(int), &mytransy, sizeof(int) );
  memcpy( (*buf) + 2*sizeof(int), &myslice, sizeof(int) );
  memcpy( (*buf) + 3*sizeof(int), &myparnum, sizeof(int) );
  return 0;
}

int workunit::packresult( char **buf, int &size )
{
  //char *mtx;

  size = sizeof(double);
  *buf = new char[size];
  memcpy( *buf, &score, sizeof(double) );
  return 0;
}

int workunit::unpack( char *buf, int size )
{
  memcpy( &mytransx, buf, sizeof(int) );
  memcpy( &mytransy, buf + sizeof(int), sizeof(int) );
  memcpy( &myslice, buf + 2*sizeof(int), sizeof(int) );
  memcpy( &myparnum, buf + 3*sizeof(int), sizeof(int) );
  if( size != sizeof(int) * 4)
    {
      std::cout << "unexpected size work workunit\n";
    }
  return 0;
}

int workunit::setresult( double bscore )
{
  score = bscore;
  return 0;
}

int workunit::getresult( double &bscore )
{
  bscore = score;
  return 0;
}

int workunit::getinput( int &tx, int &ty, int &s, int &p )
{
  tx = mytransx;
  ty = mytransy;
  s = myslice;
  p = myparnum;
  return 0;
}
