/***
 When removing a set from the partial solution
 1. Indicate that the column is no longer selected (x)
 2. Remove cost of column from partial cost (fx)
 3. Increment # of un-used columns (un_cols)
 4. Decrement # of columns covering each row (ncol_cover)
 5. Remove column from all columns covering row i (col_cover)
 6. If a row is now uncovered, increment un_rows
 7. If a row is now uncovered, indicate it (y)
 **/
void removeSet(instance_t* inst, solution_t* sol, int colidx) {
    sol->x[colidx] = 0;
    sol->fx -= inst->cost[colidx];
    sol->un_cols += 1;
    for (int i = 0; i < inst->nrow[colidx]; i++) {
        int rowidx = inst->row[colidx][i];
        for (int j = 0; j < sol->ncol_cover[rowidx]; j++) {
            if (sol->col_cover[rowidx][j] == colidx) {
                sol->col_cover[rowidx][j] = -1;
                shift(sol, rowidx, j);
                break;
            }
        }
        sol->ncol_cover[rowidx] -= 1;
        if (sol->ncol_cover[rowidx] <= 0) {
            sol->un_rows += 1;
            sol->y[rowidx] = 0;
        }
    }
}
Exemple #2
0
void conv_flaw(const cv::Mat& imgOriginal, const cv::Mat& kernel, cv::Mat& out, const bool& corr)
{
  cv::Mat source;
  imgOriginal.copyTo(source);
  cv::Mat kernelPadded = cv::Mat::zeros(source.size(), source.type());
  if(kernel.size().height > kernelPadded.size().height || kernel.size().width > kernelPadded.size().width)
  {
    throw CustomException("Kernel padded bigger than image.");
  }
  kernel.copyTo(selectCentralROI(kernelPadded, kernel.size()));
  //Divided by 2.0 instead of 2 to consider the result as double instead of as an int
  //The +1 in the shift changes slightly the finest plane in the wavelet,
  shift(kernelPadded, kernelPadded, std::ceil(kernelPadded.cols/2.0), std::ceil(kernelPadded.rows/2.0));

  cv::Mat kernelPadded_ft, input_ft, output_ft;
  cv::dft(kernelPadded, kernelPadded_ft, cv::DFT_COMPLEX_OUTPUT + cv::DFT_SCALE);
  cv::dft(source, input_ft, cv::DFT_COMPLEX_OUTPUT + cv::DFT_SCALE);
  cv::mulSpectrums(input_ft, kernelPadded_ft.mul(kernelPadded.total()), output_ft, cv::DFT_COMPLEX_OUTPUT, corr);
  cv::idft(output_ft, out, cv::DFT_REAL_OUTPUT);
}
Exemple #3
0
Score::Score(Alignment& alg){
	PRECISION = 15.;	// the default value of PRECISION
	LAMBDA = .125;
	alignment = alg;
	alpha_exponent = 1.;
	logR = calculate_logR();
	std::vector <std::vector<double> > temp = shift(logR);
	alpha_exponent = find_alpha_exponent(temp);
	rescaled_R = re_scale(temp, alpha_exponent);

	laplacian_determinant = calculate_determinant(laplacian_of(rescaled_R), rescaled_R.size() - 1);

	tf = "TF-Unknown";

	ParameterFile p;
	parameters = p;

	BackgroundModel bg (parameters.give_background());
	background = bg;
}
Exemple #4
0
bvt bv_utilst::shift(const bvt &op, const shiftt s, const bvt &dist)
{
  std::size_t d=1, width=op.size();
  bvt result=op;

  for(std::size_t stage=0; stage<dist.size(); stage++)
  {
    if(dist[stage]!=const_literal(false))
    {
      bvt tmp=shift(result, s, d);

      for(std::size_t i=0; i<width; i++)
        result[i]=prop.lselect(dist[stage], tmp[i], result[i]);
    }

    d=d<<1;
  }

  return result;
}
Exemple #5
0
bool funcPLUS(ParserParam &param, Token *tok){
	switch(param.stack.back()){
		case 78:
			shift(param,tok,81);
			break;
		case 83:
			if(!rule46(param)) return false;
			break;
		case 85:
			if(!rule45(param)) return false;
			break;
		case 86:
			if(!rule47(param)) return false;
			break;
		case 88:
			if(!rule48(param)) return false;
			break;
		case 91:
			if(!rule49(param)) return false;
			break;
		case 92:
			if(!rule50(param)) return false;
			break;
		case 95:
			if(!rule51(param)) return false;
			break;
		case 98:
			if(!rule52(param)) return false;
			break;
		case 99:
			if(!rule53(param)) return false;
			break;
		case 113:
			if(!rule68(param)) return false;
			break;
		default:
			return false;
		break;
	}
	return true;
}
/*
 * 加密
 *
 * @param key    密钥 { a, b }
 * @param src    待加密的字符串
 * @param dest   经过加密后的字符串
 */
char * encrypt(int* key, char* src, char* dest)
{
    char *pSrc  = src;
    char *pDest = dest;

    if (gcd(key[0], WIDTH) != 1)
    {
        printf("Error: a 与 m 不互素");
        exit(-1);
    }

    for (int i = 0; *pSrc; ++i, ++pSrc, ++pDest)
    {
        if (!isalpha(*pSrc))
            continue;

        *pDest = shift(key, toupper(*pSrc));
    }

    return dest;
}
Exemple #7
0
	void StateItem::move(const int & action) {
		switch (decodeAction(action)) {
		case NO_ACTION:
			return;
		case SHIFT:
			shift();
			return;
		case REDUCE:
			reduce();
			return;
		case ARC_LEFT:
			arcLeft(action - AL_FIRST + 1);
			return;
		case ARC_RIGHT:
			arcRight(action - AR_FIRST + 1);
			return;
		case POP_ROOT:
			popRoot();
			return;
		}
	}
Exemple #8
0
dem subst (int n, dem y, dem z)
{
    if (y == NULL)
        return NULL;
    if (node(y) == node_var)
    {
        if (level(y) == n)
        	return z;
	if (level(y) > n)
		return mkdem (node_var, level(y)-1, NULL, NULL, NULL);
    }
    if (node(y) == node_ap)
	return ap (subst (n, sd0(y), z),
		   subst (n, sd1(y), z));
    if (node(y) == node_lambda)
	return lambda (subst (n+1, sd0(y), shift (0, 1, z)));
    /* return y; */
    return mkdem (node(y), level(y), name(y),
			subst (n, sd0(y), z),
			subst (n, sd1(y), z));
}
bool LightColliderSphere::intersect(Vector3D start, Vector3D vec) {
    
    Vector3D shift(position - start);
    double a = vec.magnitudeSquared();
    double b = -2 * (vec * shift);
    double c = shift.magnitudeSquared() - radiusSquared;
    if(a == 0) {
        return false;
    }
    c = b * b - 4 * a * c;
    if(c < 0) {
        return false;
    }
    c = (-b - sqrt(c)) / (2 * a);

    if(c > 0 && c < 1) {
        
        return true;
    }
    return false;
}
/***************************************************************************
 PRIVATE FUNCTIONS
 ***************************************************************************/
uint8_t lsm303_write8(byte address, byte reg, byte value)
{

  int ret;
  byte buf[1];
 
  buf[0] = value;
  ret = 0;
  ret = i2c_writeReg(address, reg, buf, 1);

  if(ret!=0)
    {
#ifdef DEBUG
      shift(0x7777);
      _delay_ms(1000);
#endif
      return 1;
    }

  return 0;
}
Exemple #11
0
cv::Mat crosscorrelation_direct(const cv::Mat& A, const cv::Mat& B)
{  //For testing pourposes only
  cv::Mat aPadded, bPadded;
  cv::copyMakeBorder(A, aPadded, 0, A.rows, 0, A.cols, cv::BORDER_CONSTANT, cv::Scalar(0.0, 0.0));
  cv::copyMakeBorder(B, bPadded, 0, B.rows, 0, B.cols, cv::BORDER_CONSTANT, cv::Scalar(0.0, 0.0));

  cv::Mat C = cv::Mat::zeros(aPadded.size(), aPadded.type());
  cv::Mat conjA = conjComplex(aPadded);
  for(int i=0; i < aPadded.cols; ++i)              // rows
  {
    for(int j=0; j < aPadded.rows; ++j)          // columns
    {
      cv::Mat shifted, prod;
      shift(conjA,shifted,aPadded.cols-i,aPadded.rows-j);
      cv::mulSpectrums(shifted,bPadded,prod, cv::DFT_COMPLEX_OUTPUT);
      cv::Scalar s = cv::sum(prod);
      C.at<std::complex<float> >(i,j) = std::complex<float>(s.val[0],s.val[1]);
    }
  }
  return C;
}
Exemple #12
0
void convolveDFT(const cv::Mat& imgOriginal, const cv::Mat& kernel, cv::Mat& out, const bool& corr, const bool& full)
{ //this method is also valid for complex image and kernel, set DFT_COMPLEX_OUTPUT then
  //convolution in fourier space, keep code for future use
  //CONVOLUTION_FULL: Return the full convolution, including border
  //to completeley emulate filter2D operation, image should be first double sized and then cut back to origianl size
  cv::Mat source, kernelPadded;
  const int marginSrcTop = corr ? std::ceil((kernel.rows-1)/2.0) : std::floor((kernel.rows-1)/2.0);
  const int marginSrcBottom = corr ? std::floor((kernel.rows-1)/2.0) : std::ceil((kernel.rows-1)/2.0);
  const int marginSrcLeft = corr ? std::ceil((kernel.cols-1)/2.0) : std::floor((kernel.cols-1)/2.0);
  const int marginSrcRight = corr ? std::floor((kernel.cols-1)/2.0) : std::ceil((kernel.cols-1)/2.0);
  cv::copyMakeBorder(imgOriginal, source, marginSrcTop, marginSrcBottom, marginSrcLeft, marginSrcRight, cv::BORDER_CONSTANT);

  const int marginKernelTop = std::ceil((source.rows-kernel.rows)/2.0);
  const int marginKernelBottom = std::floor((source.rows-kernel.rows)/2.0);
  const int marginKernelLeft = std::ceil((source.cols-kernel.cols)/2.0);
  const int marginKernelRight = std::floor((source.cols-kernel.cols)/2.0);
  cv::copyMakeBorder(kernel, kernelPadded, marginKernelTop, marginKernelBottom, marginKernelLeft, marginKernelRight, cv::BORDER_CONSTANT);

  //Divided by 2.0 instead of 2 to consider the result as double instead of as an int
  //The +1 in the shift changes slightly the finest plane in the wavelet,
  shift(kernelPadded, kernelPadded, std::ceil(kernelPadded.cols/2.0), std::ceil(kernelPadded.rows/2.0));

  cv::Mat kernelPadded_ft, input_ft, output_ft;
  cv::dft(kernelPadded, kernelPadded_ft, cv::DFT_COMPLEX_OUTPUT + cv::DFT_SCALE);
  cv::dft(source, input_ft, cv::DFT_COMPLEX_OUTPUT + cv::DFT_SCALE);
  cv::mulSpectrums(input_ft, kernelPadded_ft.mul(kernelPadded.total()), output_ft, cv::DFT_COMPLEX_OUTPUT, corr);
  
  if(imgOriginal.channels() == 1 && kernel.channels() == 1) cv::idft(output_ft, out, cv::DFT_REAL_OUTPUT);
  else cv::idft(output_ft, out, cv::DFT_COMPLEX_OUTPUT);
  
  if(!full)
  {
    //colRange and rowRange are semi-open intervals. first included, last is not
    //this frist option is what i think should be the correct one, but the next is what filter2D function gives for this inputs
//    out = out.colRange(marginSrcLeft, out.cols - marginSrcRight).
//              rowRange(marginSrcTop, out.rows - marginSrcBottom);
        out = out.colRange(marginSrcRight, out.cols - marginSrcLeft).
                  rowRange(marginSrcBottom, out.rows - marginSrcTop);
  }
}
Exemple #13
0
//---------------------------------------------------------------------------------------
void TableCellSizer::reposition_cells()
{
    //AWARE: row 0 is correctly positioned, so we start moving from row 1.
    //In horizontal cells are correctly positioned, so shift is only in vertical.

    int iH = m_iFirstRow * m_numColumns;
    USize shift(0.0f, 0.0f);
    for (int iRow=1; iRow < m_numRows; ++iRow)
    {
        shift.height += m_heights[iH];
        int iCell = (m_iFirstRow + iRow) * m_numColumns;
        for (int iCol=0; iCol < m_numColumns; ++iCol, ++iCell)
        {
            if (m_cellLayouters[iCell] != nullptr)
            {
                GmoBox* pCellBox = m_cellLayouters[iCell]->get_item_main_box();
                pCellBox->shift_origin(shift);
            }
        }
        iH += m_numColumns;
    }
}
Exemple #14
0
void turn() //обработка ходов
{
	int direction = 0;
	bool moved;
	while (true)
	{
		direction = controls();
		moved = shift(direction);
		int number = cells_check();
		if (!move_check() && !number)
		{
			lose();
			return;
		}
		if (moved)
		{
			add_2(number);
			printfield();
			Sleep(50);
		}
	}
}
Exemple #15
0
/* autolinking means that all inline html is <a href'ified>.   A
 * autolink url is alphanumerics, slashes, periods, underscores,
 * the at sign, colon, and the % character.
 */
static int
maybe_autolink(MMIOT *f)
{
    register int c;
    int size;

    /* greedily scan forward for the end of a legitimate link.
     */
    for ( size=0; (c=peek(f, size+1)) != EOF; size++ )
	if ( c == '\\' ) {
	     if ( peek(f, size+2) != EOF )
		++size;
	}
	else if ( isspace(c) || strchr("'\"()[]{}<>`", c) )
	    break;

    if ( (size > 1) && process_possible_link(f, size) ) {
	shift(f, size);
	return 1;
    }
    return 0;
}
Exemple #16
0
vector<Shift> ShiftRepo::getWeeklyShifts(string start_date, string end_date, int type_selected)
{
    db.open();

    stringstream sqlQuery;

    sqlQuery << "SELECT * FROM Shifts WHERE (date BETWEEN '" << start_date << "'";
    sqlQuery << " AND '" << end_date << "') AND (shiftID BETWEEN 1 AND 13) AND type = " << type_selected;
    sqlQuery << " ORDER BY date ASC";

    QSqlQuery query(db);

    bool success = query.exec(QString::fromStdString(sqlQuery.str()));
    qDebug() << query.lastQuery();
    if(!success)
    {
        qDebug() << "Error in getting weekly shifts";
        qDebug() << query.lastError().text();
    }

    vector<Shift> shifts;

    while(query.next())
    {
        QString raw_date = query.value("date").toString();
        QDate date = stringToDate(raw_date);
        int id = query.value("shiftID").toInt();
        bool type = query.value("type").toBool();
        QString name = query.value("name").toString();
        double hours = query.value("hours").toDouble();
        double wages = query.value("wages").toDouble();

        Shift shift(date, id, type, name, hours, wages);
        shifts.push_back(shift);
    }

    return shifts;
}
Exemple #17
0
inline _queue_t _bucketsort_q(_queue_t src, size_t depth,
			      keyaccessor_t key, indexer_t idx,
			      comparator_t cmp)
{
    list_t head = src.head;
    if (!head)
	return src;
    if (!key)
	key = identity;
    if (!idx)
	idx = charAt;
    if (!cmp)
	cmp = stringcmp;
    if (depth > BUCKETSORT_DEPTH) {
	src.head = mergesort_l(head, cmp);
	for (src.tail = src.head; src.tail->cdr; src.tail = src.tail->cdr);
	return src;
    }
    _queue_t buckets[BUCKETSIZ];
    size_t i;
    for (i = 0; i < BUCKETSIZ; i++)
	buckets[i].head = NULL;
    while (head) {
	list_t l = shift(&head);
	int c = idx(key(l->car), depth);
	enqueue(&buckets[c], l, NULL);
    }
    _queue_t dst = { NULL, NULL };
    for (i = 0; i < BUCKETSIZ; i++) {
	_queue_t b = buckets[i];
	if (b.head) {
	    if (!allthesame(b, cmp))
		b = _bucketsort_q(b, depth + 1, key, idx, cmp);
	    enqueue(&dst, b.head, b.tail);
	}
    }
    return dst;
};
Exemple #18
0
int main()
{
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		char a[1000],b[1000];
		int k;
		scanf("%s %d",a,&k);
		int len=strlen(a);
		int j,h=0;
		for(j=0;j<len;j++)
		{
			if(a[j]!='a'&&a[j]!='e'&&a[j]!='i'&&a[j]!='o'&&a[j]!='u')
			{
				b[h]=a[j];
				h++;
			}
		}	
		for(j=0;j<k;j++)
		{
			shift(b,len);
			printf("%s heel\n",b);
		}
		printf("hello\n");
		int x=0;
		for(j=0;j<len;j++)
		{
			if(a[j]!='a'&&a[j]!='e'&&a[j]!='i'&&a[j]!='o'&&a[j]!='u')
			{
				a[j]=b[x];
				x++;
			}
		}
	//	printf("%s\n",a);
	}
	return 0;
}
Exemple #19
0
/* a < may be just a regular character, the start of an embedded html
 * tag, or the start of an <automatic link>.    If it's an automatic
 * link, we also need to know if it's an email address because if it
 * is we need to mangle it in our futile attempt to cut down on the
 * spaminess of the rendered page.
 */
static int
maybe_tag_or_link(MMIOT *f)
{
    int c, size;
    int maybetag = 1;

    if ( f->flags & INSIDE_TAG )
	return 0;

    for ( size=0; (c = peek(f, size+1)) != '>'; size++) {
	if ( c == EOF )
	    return 0;
	else if ( c == '\\' ) {
	    maybetag=0;
	    if ( peek(f, size+2) != EOF )
		size++;
	}
	else if ( isspace(c) )
	    break;
	else if ( ! (c == '/' || isalnum(c) ) )
	    maybetag=0;
    }

    if ( size ) {
	if ( maybetag || (size >= 3 && strncmp(cursor(f), "!--", 3) == 0) ) {
	    Qstring(forbidden_tag(f) ? "&lt;" : "<", f);
	    while ( ((c = peek(f, 1)) != EOF) && (c != '>') )
		cputc(pull(f), f);
	    return 1;
	}
	else if ( !isspace(c) && process_possible_link(f, size) ) {
	    shift(f, size+1);
	    return 1;
	}
    }
    
    return 0;
}
Exemple #20
0
int send_all(Buffer &b) {
   int len = send(conn, (const char*)b.get_buf(), b.size(), 0);
   if (len == SOCKET_ERROR) {
      int error = WSAGetLastError();
      if (error == WSAEWOULDBLOCK) {
         sendBuf << b;
         return 0;
      }
      else {
         cleanup();
         killWindow();
         msg(PLUGIN_NAME": Failed to send requested data. %d != %d. Error: %x, %d\n", len, b.size(), error, error);
         return -1;
      }
   }
   else if (len != b.size()) {
      //move the remainder into sendBuf
      shift(b, len);
      sendBuf << b;
      //msg(PLUGIN_NAME": Short send. %d != %d.", len, out.size());
   }
   return len;
}
Exemple #21
0
ResultAlign2D get_translational_alignment_no_preprocessing(const cv::Mat &M1,
                                                           const cv::Mat &M2) {
  IMP_LOG_TERSE("starting 2D translational alignment with no preprocessing"
                << std::endl);
  IMP_USAGE_CHECK(((M1.rows == M2.rows) && (M1.cols == M2.cols)),
                  "get_translational_alignment_no_preprocessing: "
                  "Matrices have different size.");

  cv::Mat corr;
  corr.create(M1.rows, M1.cols, CV_64FC1);
  get_correlation2d_no_preprocessing(M1, M2, corr);  // corr must be allocated!
  // Find the peak of the cross_correlation
  double max_cc;
  algebra::Vector2D peak = internal::get_peak(corr, &max_cc);

  // Convert the pixel with the maximum to a shift respect to the center
  algebra::Vector2D shift(peak[0] - static_cast<double>(corr.cols) / 2.,
                          peak[1] - static_cast<double>(corr.rows) / 2.);
  algebra::Transformation2D t(shift);
  IMP_LOG_VERBOSE(" Translational Transformation = "
                  << t << " cross_correlation = " << max_cc << std::endl);
  return ResultAlign2D(t, max_cc);
}
Exemple #22
0
int merge_n_into_2n(int **a, int **b, int n)
{
	int *array_a = *a;
	int *array_b = *b;

	int i = 0;
	int j = 0;
	
	while (i < n && j < 2*n) {
		if (array_a[i] >= array_b[j]) {
			j++;
		} else {
			shift(array_b, j, 2 * n - 2);
			array_b[j++] = array_a[i++];
		}
	}

	while (i < n) {
		array_b[j++] = array_a[i++];
	}

	return 1;
}
unsigned int Psx::poll()
{
	digitalWrite(_attPin, LOW);

	shift(0x01);
	Controller_mode = ~shift(0x42);
	shift(0x00);

	digital_buttons = (~shift(Motorsmall) & 0x00FF); //motor (change value to FF to turn on motor in dualshock controller) 
	digital_buttons |= (~shift(Motorlarge) << 8); //motor (Large motor, will turn on for values over 40)
        Right_x = shift(0x00);
	Right_y = shift(0x00);
        Left_x = shift(0x00);
	Left_y = shift(0x00);
	digitalWrite(_attPin, HIGH);

	return digital_buttons;
}
void
xf4bppBitBlt(WindowPtr pWin, int alu, int writeplanes, int x0, int y0,
	     int x1, int y1, int w, int h)
{
    IOADDRESS REGBASE;
    int plane, bit;

    if ( !w || !h ) return;

    if ( ! xf86Screens[((DrawablePtr)pWin)->pScreen->myNum]->vtSema ) {
        xf4bppOffBitBlt(pWin,alu,writeplanes,x0,y0,x1,y1,w,h);
        return;
    }

    REGBASE =
	xf86Screens[((DrawablePtr)pWin)->pScreen->myNum]->domainIOBase + 0x300;

    /* 0x7, not WMASK: it is hardware dependant */
    if ( ((x0 - x1) & 0x7) || (alu != GXcopy) ) {
	/* Use slow copy */
	SetVideoGraphics(Enb_Set_ResetIndex, 0); /* All from CPU */
	SetVideoGraphics(Bit_MaskIndex, 0xFF); /* All bits */
	SetVideoGraphics(Graphics_ModeIndex, 0); /* Write mode 0 */
	SetVideoGraphics(Data_RotateIndex, 0); /* Don't rotate, replace */

	for ( plane = HIGHPLANEMASK, bit = HIGHPLANEINDEX ;
		plane ; plane >>= 1, bit-- )
	{

		if ( writeplanes & plane) {
			SetVideoGraphics(Read_Map_SelectIndex, bit);
			SetVideoSequencer(Mask_MapIndex, plane);

			shift(pWin,x0,x1,y0,y1,w,h,alu);
		}
	}
    } else {
Exemple #25
0
/*  4 2 2 2 2 2  
 *  3 2 1 1 1 2
 *  2 2 1 0 1 2
 *  1 2 1 1 1 2
 *  0 2 2 2 2 2 
 *    0 1 2 3 4 
 */
void movingArrows() {
     unsigned char x, y, cnt, cnt2 = 0;
	 color colors[4] = {{255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 0}};
     color curColor = {0,0,0};
	 for (cnt = 0; cnt < 100; cnt++) {
         shift(up);
         for (x = 0; x < MAX_X; x++) {
             for (y = 0; y < MAX_Y; y++) {
				switch (cnt % 3) {
					case 0:
						if (x == 2 && y == 2) {
							curColor = colors[cnt2++ % 4];
							setVoxel((voxel) {x, y, 0}, curColor);
						} 
						break;
					case 1:
						if ((x == 1 || x == 3) && (y == 1 || y == 3)) {
							setVoxel((voxel) {x, y, 0}, 
									 (color) {curColor.r/2, curColor.g/2, 
											  curColor.b/2});
						}
						break;
					case 2:
						if ((x == 0 || x == 4) && (y == 0 || y == 4)) {
							setVoxel((voxel) {x, y, 0}, 
									 (color) {curColor.r/4, curColor.g/4, 
											  curColor.b/4});
						}
						break;
				}
			 }	
         }
         fade(10, 10);
     }
     clearImage(black);
	 fade(10, 50);
}
Exemple #26
0
void shifty::updateShifts()
{
    int weekday = current_date_selected.dayOfWeek();
    int difference = 1 - weekday;
    QDate week_start = current_date_selected.addDays(difference);

    int row_count = ui->table_display_shifts->rowCount();
    int col_count = 7;

    vector<Shift> update_shifts;

    for(int row = 0; row < row_count; row++)
    {
        for(int col = 0; col < col_count; col++)
        {
            // Grab column header for date.
            QDate date = week_start.addDays(col);

            QString employee_name = ui->table_display_shifts->item(row, col+3)->text();

            double hours = sService.getLength(row);
            double wages;

            Shift shift(date, row, bakers_currently_selected, employee_name, hours, wages);

            update_shifts.push_back(shift);
        }
    }

    bool success = sService.updateShifts(update_shifts);

    if(!success)
    {
        // Let the user know that something failed!
    }

}
Exemple #27
0
/*;*<*>********************************************************
  * hw_analog_set
  *
  * This function sets the hardware registers on the analog board.
  *
  * The "value" byte is sent to the 'type' register on the analog
  * board. 
  *
  * Algorithm for writing to AG_TEST
  *   Disable interrupts
  *   send 'value' to test shift register
  *   Write anything to LAT-TEST
  *   Enable interrupts
  *
  * Algorithm for writing to AG_LEFT_CTL, AG_RIGHT_CTL & AG_TEST
  *   Disable interrupts
  *   send 'value' to other shift registers
  *   Write anything to LAT-L    for AG_LEFT_CTL
  *                      LAT-R    for AG_RIGHT_CTL
  *   Enable interrupts
  *
  * Algorithm for the DACs (Digital-to-Analog-Converters)
  *   Disable interrupts
  *   setup DAC control register including address bit
  *   Write anything to LAT-DAC
  *   send 'value' to other shift registers
  *   Write anything to LAT-COM
  *   send write bit to DAC control register
  *   Write anything to LAT-DAC
  *   Setup DAC control register to inactive data
  *   Write anything to LAT-DAC
  *   Enable interrupts
  *
  *  Note: 1) Initial B002 rev 3 hardware is not stuffed with the TEST ics
  *   U85 & U84. Instead R83 is stuffed so that EMG-RIGHT goes to TEST.
  *        2) DACs have been removed from b002-3 hardware, however one
  *           control bit for the test points is still used.
  **start*/
 void hw_analog_set(int type, int value)
 {
 int dac_addr;

#ifndef SIMULATING 
 disable();
#endif

 switch(type) {
 case AG_TEST:          /* Control of test cct                 */
    send_to_test(value);
    shift(lat_test);    /* B002-2 U65  */
    break;

 case AG_LEFT_CTL:      /* Control of left cct                 */
    send_to_other(value);
    shift(lat_l);       /* B002-2 U67 */
    break;

 case AG_RIGHT_CTL:     /* Control of right cct                */
    send_to_other(value);
    shift(lat_r);       /*  B002-2 U68 */
    break;

 default:
    dac_addr = get_dac_addr(type);
    send_to_other(dac_addr);
    shift(lat_dac);
    send_to_other(value);
    shift(lat_com);
    send_to_other(dac_addr & DAC_WR_MASK);
    shift(lat_dac);
    send_to_other(INACTIVE_DAC_CTL_REG);
    shift(lat_dac);
 }
#ifndef SIMULATING
 enable();
#endif
 } /*end analog_set*/
Exemple #28
0
/** Open a file for lexical processing.
 * new_flp and name must point into storage and will live
 * at least until the file is closed.
 *
 * @param new_flp file position
 * @param name filename
 * @param bool optional
 * @return bool True if successful
 */
bool lexopen(struct file_lex_position *new_flp, const char *name,
	     bool optional)
{
	FILE *f = fopen(name, "r");

	if (f == NULL) {
		if (!optional || errno != ENOENT)
			log_errno((e, "could not open \"%s\"", name));
		return FALSE;
	} else {
		new_flp->previous = flp;
		flp = new_flp;
		flp->filename = name;
		flp->fp = f;
		flp->lino = 0;
		flp->bdry = B_none;

		flp->cur = flp->buffer; /* nothing loaded yet */
		flp->under = *flp->cur = '\0';

		(void) shift(); /* prime tok */
		return TRUE;
	}
}
Exemple #29
0
int run(Grid grid, char ch, int* score, bool ai = false)
{
	if(!over(grid))
	{
		if (ai)
		{
			ch = aI(grid);
		}
		if (shift(grid, ch, score))
		{
			randPut(grid);
            if(win(grid))
            {
                return WIN;
            }
	    }
        else
        {
            return NONE;
        }
    }
    else
        return FAIL;
}
Exemple #30
0
/**
* Convert terrain from one thing to another near other terrain.
* 
* @param int from Terrain to convert from.
* @param int to Terrain to convert to.
* @param int near Terrain it must be near.
* @param int dist Distance it must be within.
*/
void replace_near(int from, int to, int near, int dist) {
	int x, y, hor, ver, at, loc;
	int found;
	
	for (x = 0; x < USE_WIDTH; ++x) {
		for (y = 0; y < USE_HEIGHT; ++y) {
			at = MAP(x, y);
			
			if (grid[at].type == from) {
				found = 0;
				for (hor = -dist; hor <= dist && !found; ++hor) {
					for (ver = -dist; ver <= dist && !found; ++ver) {
						loc = shift(at, hor, ver);
						
						if (loc != -1 && grid[loc].type == near && compute_distance(X_COORD(at), Y_COORD(at), X_COORD(loc), Y_COORD(loc)) <= dist) {
							change_grid(at, to);
							found = 1;
						}
					}
				}
			}
		}
	}
}