コード例 #1
0
void MappingLevel::calculateMappings(IDefRecordElement const * diskRecord, unsigned numKeyedDisk, IDefRecordElement const * activityRecord, unsigned numKeyedActivity)
{
    if(diskRecord->getKind() != DEKrecord)
        throw makeFailure(IRecordLayoutTranslator::Failure::BadStructure)->append("Disk record metadata had unexpected structure (expected record)")->appendScopeDesc(topLevel ? NULL : scope.str());
    if(activityRecord->getKind() != DEKrecord)
        throw makeFailure(IRecordLayoutTranslator::Failure::BadStructure)->append("Activity record metadata had unexpected structure (expected record)")->appendScopeDesc(topLevel ? NULL : scope.str());

    unsigned numActivityChildren = activityRecord->numChildren();
    unsigned numDiskChildren = diskRecord->numChildren();
    bool activityHasInternalFpos = false;
    if(topLevel && (numActivityChildren > numKeyedActivity))
    {
        IDefRecordElement const * lastChild = activityRecord->queryChild(numActivityChildren-1);
        if((lastChild->queryName() == internalFposAtom) && (lastChild->queryType()->isInteger()))
            activityHasInternalFpos = true;
    }
    if((numActivityChildren - (activityHasInternalFpos ? 1 : 0)) > numDiskChildren) //if last activity field might be unmatched __internal_fpos__, should be more lenient by 1 as would fill that in (see below)
        throw makeFailure(IRecordLayoutTranslator::Failure::MissingDiskField)->append("Activity record requires more fields than index provides")->appendScopeDesc(topLevel ? NULL : scope.str());
    if(numKeyedActivity > numKeyedDisk)
        throw makeFailure(IRecordLayoutTranslator::Failure::UnkeyedDiskField)->append("Activity record requires more keyed fields than index provides")->appendScopeDesc(topLevel ? NULL : scope.str());

    BoolArray activityFieldMapped;
    activityFieldMapped.ensure(numActivityChildren);
    for(unsigned i=0; i<numActivityChildren; ++i)
        activityFieldMapped.append(false);

    FieldSearcher searcher(activityRecord);
    for(unsigned diskFieldNum = 0; diskFieldNum < numDiskChildren; ++diskFieldNum)
    {
        checkField(diskRecord, diskFieldNum, "Disk");
        bool diskFieldKeyed = (diskFieldNum < numKeyedDisk);
        unsigned activityFieldNum;
        if(searcher.search(diskRecord->queryChild(diskFieldNum)->queryName(), activityFieldNum))
        {
            bool activityFieldKeyed = (activityFieldNum < numKeyedActivity);
            if(activityFieldKeyed && !diskFieldKeyed)
                throw makeFailure(IRecordLayoutTranslator::Failure::UnkeyedDiskField)->append("Field ")->appendFieldName(topLevel ? NULL : scope.str(), activityRecord->queryChild(activityFieldNum))->append(" is keyed in activity but not on disk");
            checkField(activityRecord, activityFieldNum, "Activity");
            attemptMapping(diskRecord, diskFieldNum, diskFieldKeyed, activityRecord, activityFieldNum, activityFieldKeyed);
            activityFieldMapped.replace(true, activityFieldNum);
        }
        else
        {
            mappings.append(*new FieldMapping(FieldMapping::None, diskRecord, diskFieldNum, diskFieldKeyed, NULL, 0, false));
        }
    }

    for(unsigned activityFieldNum=0; activityFieldNum<numActivityChildren; ++activityFieldNum)
        if(!activityFieldMapped.item(activityFieldNum))
        {
            checkField(activityRecord, activityFieldNum, "Activity");
            if((activityFieldNum != numActivityChildren-1) || !activityHasInternalFpos) //if last activity field is unmatched __internal_fpos__, this is not an error, we need do nothing and it will get correctly set to zero
                throw makeFailure(IRecordLayoutTranslator::Failure::MissingDiskField)->append("Field ")->appendFieldName(topLevel ? NULL : scope.str(), activityRecord->queryChild(activityFieldNum))->append(" is required by activity but not present on disk index");
        }
}
コード例 #2
0
ファイル: adapt.c プロジェクト: rfajardo/devmech
static void adaptWriteAsRead(RegField * regField, unsigned int reg_read_value)
{
	unsigned int fieldValue;

	if ( checkField(regField, write_value_constraint, equal, true) &&
			checkField(regField, write_as_read, equal, true) )
	{
		DEVIF_DEBUG_ADAPT("SWITCH: from default adaptation to write as read for a field.\n");
		fieldValue = genFieldValue(regField, reg_read_value);
		updateParentRegister(regField, fieldValue);
	}
}
コード例 #3
0
int cpuColorSpinorField::Compare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, 
				  const int resolution) {
  int ret = 0;
  
  checkField(a, b);
  if (a.precision == QUDA_HALF_PRECISION || b.precision == QUDA_HALF_PRECISION) 
    errorQuda("Half precision not implemented");
  if (a.fieldOrder != b.fieldOrder || 
      (a.fieldOrder != QUDA_SPACE_COLOR_SPIN_FIELD_ORDER && a.fieldOrder != QUDA_SPACE_SPIN_COLOR_FIELD_ORDER))
    errorQuda("Field ordering not supported");
  
  if (a.precision == QUDA_DOUBLE_PRECISION) 
    if (b.precision == QUDA_DOUBLE_PRECISION)
      ret = compareSpinor((double*)a.v, (double*)b.v, a.volume, 2*a.nSpin*a.nColor, resolution);
    else
      ret = compareSpinor((double*)a.v, (float*)b.v, a.volume, 2*a.nSpin*a.nColor, resolution);
  else 
    if (b.precision == QUDA_DOUBLE_PRECISION)
      ret = compareSpinor((float*)a.v, (double*)b.v, a.volume, 2*a.nSpin*a.nColor, resolution);
    else
      ret =compareSpinor((float*)a.v, (float*)b.v, a.volume, 2*a.nSpin*a.nColor, resolution);


  return ret;
}
コード例 #4
0
ファイル: clover_field.cpp プロジェクト: yongchull/quda
  void cudaCloverField::copy(const CloverField &src, bool inverse) {

    checkField(src);
    
    if (typeid(src) == typeid(cudaCloverField)) {
      if (src.V(false))	copyGenericClover(*this, src, false, QUDA_CUDA_FIELD_LOCATION);
      if (src.V(true)) copyGenericClover(*this, src, true, QUDA_CUDA_FIELD_LOCATION);
    } else if (typeid(src) == typeid(cpuCloverField)) {
      resizeBufferPinned(bytes + norm_bytes);
      void *packClover = bufferPinned;
      void *packCloverNorm = (precision == QUDA_HALF_PRECISION) ? (char*)bufferPinned + bytes : 0;
      
      if (src.V(false)) {
	copyGenericClover(*this, src, false, QUDA_CPU_FIELD_LOCATION, packClover, 0, packCloverNorm, 0);
	cudaMemcpy(clover, packClover, bytes, cudaMemcpyHostToDevice);
	if (precision == QUDA_HALF_PRECISION) 
	  cudaMemcpy(norm, packCloverNorm, norm_bytes, cudaMemcpyHostToDevice);
      }
      
      if (src.V(true) && inverse) {
	copyGenericClover(*this, src, true, QUDA_CPU_FIELD_LOCATION, packClover, 0, packCloverNorm, 0);
	cudaMemcpy(cloverInv, packClover, bytes, cudaMemcpyHostToDevice);
	if (precision == QUDA_HALF_PRECISION) 
	  cudaMemcpy(invNorm, packCloverNorm, norm_bytes, cudaMemcpyHostToDevice);
      }
    } else {
      errorQuda("Invalid clover field type");
    }

    checkCudaError();
  }
コード例 #5
0
ファイル: field.cpp プロジェクト: bobolboris/TicTacToeQt
void Field::CellClick(Cell* cell){
    if(isLocked() || !cell->isEmpty()) return;
    cell->setState(state);
    cell->repaint();
    checkField();
    emit MadeMove(cell->getX(), cell->getY());
}
コード例 #6
0
 void cpuColorSpinorField::copy(const cpuColorSpinorField &src) {
   checkField(*this, src);
   if (fieldOrder == src.fieldOrder && bytes == src.Bytes()) {
     if (fieldOrder == QUDA_QOP_DOMAIN_WALL_FIELD_ORDER) 
       for (int i=0; i<x[nDim-1]; i++) memcpy(((void**)v)[i], ((void**)src.v)[i], bytes/x[nDim-1]);
     else 
       memcpy(v, src.v, bytes);
   } else {
     copyGenericColorSpinor(*this, src, QUDA_CPU_FIELD_LOCATION);
   }
 }
コード例 #7
0
ファイル: registration.cpp プロジェクト: mistrale/hub
void            GUI::Registration::registerEverywhere() {
    if (!checkField()) {
        return;
    }
    ui->warningText->setText("");
    _reply = _manager.registrationRequest(ui->emailEdit->text(), ui->usernameEdit->text(), ui->passwordEdit->text(),
                                          ui->firstnameEdit->text(), ui->lastnameEdit->text());
     connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError)));
     _background = new QMovie("C:/Everywhere/images/Ring.gif");
     ui->ring->setMovie(_background);
    _background->start();
}
コード例 #8
0
ファイル: calcasts.cpp プロジェクト: cyrusimap/icu4c
void CalendarCaseTest::doTestCases(const TestCase *cases, Calendar *cal) {
  static const int32_t  ONE_SECOND = 1000;
  static const int32_t  ONE_MINUTE = 60*ONE_SECOND;
  static const int32_t  ONE_HOUR   = 60*ONE_MINUTE;
  static const double ONE_DAY    = 24*ONE_HOUR;
  static const double JULIAN_EPOCH = -210866760000000.;   // 1/1/4713 BC 12:00
  int32_t i;
  UErrorCode status = U_ZERO_ERROR;
  cal->adoptTimeZone(TimeZone::getGMT()->clone());
  for(i=0;cases[i].era>=0;i++) {
    UDate t = (JULIAN_EPOCH+(ONE_DAY*cases[i].julian));

    logln("Test case %d:  julianday%f -> date %f\n", i, cases[i].julian, t);

    // Millis -> fields
    cal->setTime(t, status);

    logln(calToStr(*cal));

    checkField(cal, UCAL_ERA, cases[i].era, status);
    checkField(cal, UCAL_YEAR, cases[i].year,status);
    checkField(cal, UCAL_MONTH, cases[i].month - 1,status);
    checkField(cal, UCAL_DATE, cases[i].day,status);
    checkField(cal, UCAL_DAY_OF_WEEK, cases[i].dayOfWeek,status);
    checkField(cal, UCAL_HOUR, cases[i].hour,status);
    checkField(cal, UCAL_MINUTE, cases[i].min,status);
    checkField(cal, UCAL_SECOND, cases[i].sec,status);
    
    // Fields -> millis
    cal->clear();
    
    cal->set(UCAL_ERA, cases[i].era);
    cal->set(UCAL_YEAR, cases[i].year);
    cal->set(UCAL_MONTH, cases[i].month - 1);
    cal->set(UCAL_DATE, cases[i].day);
    cal->set(UCAL_DAY_OF_WEEK, cases[i].dayOfWeek);
    cal->set(UCAL_HOUR, cases[i].hour);
    cal->set(UCAL_MINUTE, cases[i].min);
    cal->set(UCAL_SECOND, cases[i].sec);

    UDate t2 = cal->getTime(status);
    
    if(t != t2) {
      errln("Field->millis: Expected %.0f but got %.0f\n", t, t2);
      logln(calToStr(*cal));
    }
  }
}
コード例 #9
0
void CompositeTypeBinding::setField( lua_State* L, const co::Any& instance )
{
	co::IField* field = checkField( L, -2 );
	co::IReflector* reflector = field->getOwner()->getReflector();
	co::Any value;
	LuaState::getAny( L, -1, field->getType(), value );
	reflector->setField( instance, field, value );
	lua_pop( L, 2 );
	
	// notify interceptors
	if( instance.getKind() == co::TK_INTERFACE )
	{
		for( co::Range<IInterceptor* const> r( sm_interceptors ); r; r.popFirst() )
			r.getFirst()->postSetField( instance.getState().data.service, field, value );
	}
}
コード例 #10
0
ファイル: IndexBuilder.cpp プロジェクト: sdgdsffdsfff/kingso
int IndexBuilder::addField(const char * fieldName, int maxOccNum)
{
    uint64_t fieldSign = 0;
    int ret = checkField(fieldName, fieldSign);
    if (ret < 0) {
        return ret;
    }

    IndexFieldBuilder* pFieldBuilder = new IndexFieldBuilder(fieldName, maxOccNum, _maxDocNum, NULL);
    if (NULL == pFieldBuilder) {
        return -4;
    }
    void* value = (void*)pFieldBuilder;
    if (_fieldMap.insert(fieldSign, value) == false) {
        return -5;
    }
    return 0;
}
コード例 #11
0
int cpuColorSpinorField::Compare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, 
				 const int tol) {
  checkField(a, b);

  int ret = 0;
  if (a.precision == QUDA_DOUBLE_PRECISION) 
    if (b.precision == QUDA_DOUBLE_PRECISION)
      ret = compareSpinor(*(a.order_double), *(b.order_double), tol);
    else
      ret = compareSpinor(*(a.order_double), *(b.order_single), tol);
  else 
    if (b.precision == QUDA_DOUBLE_PRECISION)
      ret = compareSpinor(*(a.order_single), *(b.order_double), tol);
    else
      ret =compareSpinor(*(a.order_single), *(b.order_single), tol);

  return ret;
}
コード例 #12
0
ファイル: codetests.cpp プロジェクト: JaceCearK1/wiiu-emu
bool executeCodeTest(ThreadState& state, uint32_t baseAddress, const TestData& test) {
   for (auto i = 0; i < TargetId::Max; ++i) {
      if (test.fields[i].hasInput) {
         setStateValue(state, i, test.fields[i].input);
      }
   }

   // Save the original state for comparison later
   ThreadState originalState = state;

   // Execute test
   gInterpreter.execute(&state, baseAddress + test.offset);

   bool result = true;
   for (auto i = 0; i < TargetId::Max; ++i) {
      result &= checkField(test.fields[i], i, state, originalState);
   }
   return result;
}
コード例 #13
0
void cpuColorSpinorField::copy(const cpuColorSpinorField &src) {
  checkField(*this, src);
  if (fieldOrder == src.fieldOrder) {
    memcpy(v, src.v, bytes);
  } else {
    if (precision == QUDA_DOUBLE_PRECISION) {
      if (src.precision == QUDA_DOUBLE_PRECISION) {
	genericCopy(*order_double, *(src.order_double));
      } else {
	genericCopy(*order_double, *(src.order_single));
      }
    } else {
      if (src.precision == QUDA_DOUBLE_PRECISION) {
	genericCopy(*order_single, *(src.order_double));
      } else {
	genericCopy(*order_single, *(src.order_single));
      }
    }
  }
}
コード例 #14
0
void DimensionedField<Type, GeoMesh>::operator=
(
    const DimensionedField<Type, GeoMesh>& df
)
{
    // Check for assignment to self
    if (this == &df)
    {
        FatalErrorIn
        (
            "DimensionedField<Type, GeoMesh>::operator="
            "(const DimensionedField<Type, GeoMesh>&)"
        )   << "attempted assignment to self"
            << abort(FatalError);
    }

    checkField(*this, df, "=");

    dimensions_ = df.dimensions();
    Field<Type>::operator=(df);
}
コード例 #15
0
void cpuColorSpinorField::copy(const cpuColorSpinorField &src) {
  checkField(*this, src);
  if (fieldOrder == src.fieldOrder) {
    if (fieldOrder == QUDA_QOP_DOMAIN_WALL_FIELD_ORDER) 
      for (int i=0; i<x[nDim-1]; i++) memcpy(((void**)v)[i], ((void**)src.v)[i], bytes);
    else 
      memcpy(v, src.v, bytes);
  } else {
    if (precision == QUDA_DOUBLE_PRECISION) {
      if (src.precision == QUDA_DOUBLE_PRECISION) {
	genericCopy(*order_double, *(src.order_double));
      } else {
	genericCopy(*order_double, *(src.order_single));
      }
    } else {
      if (src.precision == QUDA_DOUBLE_PRECISION) {
	genericCopy(*order_single, *(src.order_double));
      } else {
	genericCopy(*order_single, *(src.order_single));
      }
    }
  }
}
コード例 #16
0
void DimensionedField<Type, GeoMesh>::operator=
(
    const tmp<DimensionedField<Type, GeoMesh> >& tdf
)
{
    const DimensionedField<Type, GeoMesh>& df = tdf();

    // Check for assignment to self
    if (this == &df)
    {
        FatalErrorIn
        (
            "DimensionedField<Type, GeoMesh>::operator="
            "(const tmp<DimensionedField<Type, GeoMesh> >&)"
        )   << "attempted assignment to self"
            << abort(FatalError);
    }

    checkField(*this, df, "=");

    dimensions_ = df.dimensions();
    this->transfer(const_cast<DimensionedField<Type, GeoMesh>&>(df));
    tdf.clear();
}
コード例 #17
0
ファイル: cuda_gauge_field.cpp プロジェクト: mchengcit/quda
void cudaGaugeField::loadCPUField(const cpuGaugeField &cpu, const QudaFieldLocation &pack_location)
{

  checkField(cpu);

  if (pack_location == QUDA_CUDA_FIELD_LOCATION) {
    errorQuda("Not implemented"); // awaiting Guochun's new gauge packing
  } else if (pack_location == QUDA_CPU_FIELD_LOCATION) {
    // FIXME
    anisotropy_ = anisotropy;
    X_ = x;
    t_boundary_ = t_boundary;
    
#ifdef MULTI_GPU
    //FIXME: if this is MOM field, we don't need exchange data
    if(link_type != QUDA_ASQTAD_MOM_LINKS){ 
      cpu.exchangeGhost();
    }
#endif
    
    if (reconstruct != QUDA_RECONSTRUCT_10) { // gauge field
      if (precision == QUDA_DOUBLE_PRECISION) {
	
	if (cpu.Precision() == QUDA_DOUBLE_PRECISION) {
	  loadGaugeField((double2*)(even), (double2*)(odd), (double*)cpu.gauge, (double**)cpu.ghost,
			 cpu.Order(), reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
	} else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
	  loadGaugeField((double2*)(even), (double2*)(odd), (float*)cpu.gauge, (float**)cpu.ghost,
			 cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
	}
	
      } else if (precision == QUDA_SINGLE_PRECISION) {
	
	if (cpu.Precision() == QUDA_DOUBLE_PRECISION) {
	  if (reconstruct == QUDA_RECONSTRUCT_NO) {
	    loadGaugeField((float2*)(even), (float2*)(odd), (double*)cpu.gauge, (double**)cpu.ghost, 
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);	      
	  } else {
	    loadGaugeField((float4*)(even), (float4*)(odd), (double*)cpu.gauge, (double**)cpu.ghost,
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
	  }
	} else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
	  if (reconstruct == QUDA_RECONSTRUCT_NO) {
	    loadGaugeField((float2*)(even), (float2*)(odd), (float*)cpu.gauge, (float**)cpu.ghost,
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
	  } else {
	    loadGaugeField((float4*)(even), (float4*)(odd), (float*)cpu.gauge, (float**)cpu.ghost,
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
	  }
	}
	
      } else if (precision == QUDA_HALF_PRECISION) {
	
	if (cpu.Precision() == QUDA_DOUBLE_PRECISION){
	  if (reconstruct == QUDA_RECONSTRUCT_NO) {
	    loadGaugeField((short2*)(even), (short2*)(odd), (double*)cpu.gauge, (double**)cpu.ghost,
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
	  } else {
	    loadGaugeField((short4*)(even), (short4*)(odd), (double*)cpu.gauge, (double**)cpu.ghost,
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);	      
	  }
	} else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
	  if (reconstruct == QUDA_RECONSTRUCT_NO) {
	    loadGaugeField((short2*)(even), (short2*)(odd), (float*)cpu.gauge, (float**)cpu.ghost,
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
	  } else {
	    loadGaugeField((short4*)(even), (short4*)(odd), (float*)cpu.gauge, (float**)(cpu.ghost),
			   cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);	      
	  }
	}
      }
    } else { // momentum field
      if  (precision == QUDA_DOUBLE_PRECISION) {
	if (cpu.Precision() == QUDA_DOUBLE_PRECISION) {
	  loadMomField((double2*)(even), (double2*)(odd), (double*)cpu.gauge, bytes, volumeCB, pad);
	} else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
	  loadMomField((double2*)(even), (double2*)(odd), (float*)cpu.gauge, bytes, volumeCB, pad);
	} 
      } else {
	if (cpu.Precision() == QUDA_DOUBLE_PRECISION) {
	  loadMomField((float2*)(even), (float2*)(odd), (double*)cpu.gauge, bytes, volumeCB, pad);
	} else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
	  loadMomField((float2*)(even), (float2*)(odd), (float*)cpu.gauge, bytes, volumeCB, pad);
	} 
      }      
    } // gauge or momentum
  } else {
    errorQuda("Invalid pack location %d", pack_location);
  }
    
}
コード例 #18
0
/*
 * Check header option specified against packet
 *
 * Return 1 if check is true (e.g. data matches)
 * Return 0 if check is not true.
 */
ENGINE_LINKAGE int checkHdrOpt(void *p, HdrOptCheck *optData)
{
    SFSnortPacket *pkt = (SFSnortPacket *)p;
    /* Header field will be extracted from its native
     * 1 or 2 bytes, converted to host byte order,
     * and placed in a 4 byte value for easy comparison
     */
    uint32_t value = 0;

    if ((optData->hdrField & IP_HDR_OPTCHECK_MASK) && (!pkt->ip4_header))
        return RULE_NOMATCH;

    if ((optData->hdrField & TCP_HDR_OPTCHECK_MASK) &&
        (!pkt->ip4_header || !pkt->tcp_header))
        return RULE_NOMATCH;

    if ((optData->hdrField & ICMP_HDR_OPTCHECK_MASK) &&
        (!IPH_IS_VALID(pkt) || !pkt->icmp_header))
        return RULE_NOMATCH;

    switch (optData->hdrField)
    {
    /* IP Header Checks */
    case IP_HDR_ID:
        value = IS_IP6(pkt) ? ntohl(GET_IPH_ID(pkt)) : ntohs((uint16_t)GET_IPH_ID(pkt));
        break;
    case IP_HDR_PROTO:
        //value = pkt->ip4_header->proto;
        value = GET_IPH_PROTO(pkt);
        break;
    case IP_HDR_FRAGBITS:
        return checkBits(optData->value, optData->op, ((ntohs(GET_IPH_OFF(pkt)) & 0xe000) & ~optData->mask_value));
        break;
    case IP_HDR_FRAGOFFSET:
        value = ntohs(GET_IPH_OFF((pkt))) & 0x1FFF;
        break;
    case IP_HDR_TOS:
        //value = pkt->ip4_header->type_service;
        value = GET_IPH_TOS(pkt);
        break;
    case IP_HDR_TTL:
        //value = pkt->ip4_header->time_to_live;
        value = GET_IPH_TTL(pkt);
        break;
    case IP_HDR_OPTIONS:
        return checkOptions(optData->value, optData->op, pkt->ip_options, pkt->num_ip_options);
        break;

    /* TCP Header checks */
    case TCP_HDR_ACK:
        value = ntohl(pkt->tcp_header->acknowledgement);
        break;
    case TCP_HDR_SEQ:
        value = ntohl(pkt->tcp_header->sequence);
        break;
    case TCP_HDR_FLAGS:
        return checkBits(optData->value, optData->op, (pkt->tcp_header->flags & ~optData->mask_value));
        break;
    case TCP_HDR_WIN:
        value = ntohs(pkt->tcp_header->window);
        break;
    case TCP_HDR_OPTIONS:
        return checkOptions(optData->value, optData->op, pkt->tcp_options, pkt->num_tcp_options);
        break;

    /* ICMP Header checks */
    case ICMP_HDR_CODE:
        value = pkt->icmp_header->code;
        break;
    case ICMP_HDR_TYPE:
        value = pkt->icmp_header->type;
        break;
    case ICMP_HDR_ID:
        if ((pkt->icmp_header->code == ICMP_ECHO_REQUEST) ||
            (pkt->icmp_header->code == ICMP_ECHO_REPLY))
        {
            value = ntohs(pkt->icmp_header->icmp_header_union.echo.id);
        }
        else
        {
            return RULE_NOMATCH;
        }
        break;
    case ICMP_HDR_SEQ:
        if ((pkt->icmp_header->code == ICMP_ECHO_REQUEST) ||
            (pkt->icmp_header->code == ICMP_ECHO_REPLY))
        {
            value = ntohs(pkt->icmp_header->icmp_header_union.echo.seq);
        }
        else
        {
            return RULE_NOMATCH;
        }
        break;

    default:
        return RULE_NOMATCH;
        break;
    }

    return checkField(optData->op, value, optData->value);
}
コード例 #19
0
void cudaColorSpinorField::copy(const cudaColorSpinorField &src) {
  checkField(*this, src);
  copyCuda(*this, src);
}
コード例 #20
0
  int cpuColorSpinorField::Compare(const cpuColorSpinorField &a, const cpuColorSpinorField &b, 
				   const int tol) {    
    checkField(a,b);
    return genericCompare(a, b, tol);
  }
コード例 #21
0
void TextSerializer::write(unsigned char val) {
	cout << '\'' << (unsigned int)val << '\'';
	checkField();
}
コード例 #22
0
ファイル: field.cpp プロジェクト: bobolboris/TicTacToeQt
void Field::makeMove(int x, int y){
    if(x < 0 || x >= COUNT || y < 0 || y >= COUNT) return;
    cells[x][y]->setState(oState);
    cells[x][y]->repaint();
    checkField();
}
コード例 #23
0
ファイル: cuda_gauge_field.cpp プロジェクト: fwinter/quda
void cudaGaugeField::loadCPUField(const cpuGaugeField &cpu) {

  checkField(cpu);

  // FIXME
  anisotropy_ = anisotropy;
  X_ = x;
  t_boundary_ = t_boundary;

#ifdef MULTI_GPU
  cpu.exchangeGhost();
#endif

  if (precision == QUDA_DOUBLE_PRECISION) {

    if (cpu.Precision() == QUDA_DOUBLE_PRECISION) {
      loadGaugeField((double2*)(even), (double2*)(odd), (double*)cpu.gauge, (double*)cpu.ghost,
		     cpu.Order(), reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
    } else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
      loadGaugeField((double2*)(even), (double2*)(odd), (float*)cpu.gauge, (float*)cpu.ghost,
		     cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
    }

  } else if (precision == QUDA_SINGLE_PRECISION) {

    if (cpu.Precision() == QUDA_DOUBLE_PRECISION) {
      if (reconstruct == QUDA_RECONSTRUCT_NO) {
	loadGaugeField((float2*)(even), (float2*)(odd), (double*)cpu.gauge, (double*)cpu.ghost, 
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);	      
      } else {
	loadGaugeField((float4*)(even), (float4*)(odd), (double*)cpu.gauge, (double*)cpu.ghost,
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
      }
    } else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
      if (reconstruct == QUDA_RECONSTRUCT_NO) {
	loadGaugeField((float2*)(even), (float2*)(odd), (float*)cpu.gauge, (float*)cpu.ghost,
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
      } else {
	loadGaugeField((float4*)(even), (float4*)(odd), (float*)cpu.gauge, (float*)cpu.ghost,
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
      }
    }

  } else if (precision == QUDA_HALF_PRECISION) {

    if (cpu.Precision() == QUDA_DOUBLE_PRECISION){
      if (reconstruct == QUDA_RECONSTRUCT_NO) {
	loadGaugeField((short2*)(even), (short2*)(odd), (double*)cpu.gauge, (double*)cpu.ghost,
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
      } else {
	loadGaugeField((short4*)(even), (short4*)(odd), (double*)cpu.gauge, (double*)cpu.ghost,
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);	      
      }
    } else if (cpu.Precision() == QUDA_SINGLE_PRECISION) {
      if (reconstruct == QUDA_RECONSTRUCT_NO) {
	loadGaugeField((short2*)(even), (short2*)(odd), (float*)cpu.gauge, (float*)cpu.ghost,
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);
      } else {
	loadGaugeField((short4*)(even), (short4*)(odd), (float*)cpu.gauge, (float*)cpu.ghost,
		       cpu.order, reconstruct, bytes, volumeCB, surfaceCB, pad, nFace, link_type, fat_link_max);	      
      }
    }

  }

}
コード例 #24
0
void TextSerializer::write(int val) {
	cout << val;
	checkField();
}
コード例 #25
0
void TextSerializer::write(char val) {
	cout << '\'' << val << '\'';
	checkField();
}
コード例 #26
0
ファイル: json.cpp プロジェクト: byzhang/sfserialization
void jsonParserTest () {
	// shall pass
	const char * testEmpty = "{}";
	checkParser (testEmpty);
	// shall fail
	const char * testAdditional = "{}   \tBlgegjelgj}";
	checkParser (testAdditional, false);
	// shall pass
	const char * testString = "{\"name\":\"nosc\",\n\"Dude\":\"Yes, you said\\\"Dude?\\\"\",,,}";
	checkParser (testString);
	// shall fail
	const char * wrongBegin = "[{}]";
	checkParser (wrongBegin, false);
	// shall pass
	const char * allInArray = "{\"a\":[\"String\",1, 0.2, null, 0.5e-23, -0.23e24, [2,3], {\"x\", []}]}";
	checkParser (allInArray);
	{
		// shall fail
		const char * tooEarlyEnding1 = "{\"a\": {\"b\":{\"c\":5}}";
		const char * tooMuchEnding1  = "{\"a\": {\"b\"}}}";
		const char * tooEarlyEnding2 = "{\"a\": [b,[c,[d[e[}";
		const char * tooMuchEnding2  = "{\"a\": [b,[c,d]]]}";
		checkParser (tooEarlyEnding1, false);
		checkParser (tooMuchEnding1, false);
		checkParser (tooEarlyEnding2, false);
		checkParser (tooMuchEnding2, false);
	}
	{
		const char * test1 = 
			"{\"name\" : \"nosc\","
			"\"hardstring\":\"hard\\tTo \\\"parse\\\"\","
			"\"number1\": 13,"
			"\"number2\":-23.49e39, "
			"\"arraytype\" : [3,5,2,-34,\"text\", "
				"{\"id\":null\t"
			    ", \"stringtype\":\"this is a nice string with heavy quotes \\\"}]\"}],"
			"\"booleantype\": true,"
			"\"booleantype2\" : false,"
			"\"nulltype\" : null,"
			"\"objecttype\" : { \"a\":5, \"b\" : \"string\" }"
			"			}";
		checkParser (test1);
		sf::json::Object parser (test1);
		tassert ((!parser.error()), "Should not give an error");
		
		checkField (parser, "number1", 13);
		checkField (parser, "number2", -23.49e39);
		checkField (parser, "booleantype", true);
		checkField (parser, "booleantype2", false);
		checkField (parser, "name", std::string ("nosc"));
		
		tassert ((parser.get("nulltype").type()  == sf::json::NullType), "Wrong type");
		tassert ((parser.get("arraytype").type() == sf::json::ArrayType), "Wrong type");
		
		std::string withEscapes;
		bool ret = parser.get("hardstring").fetch (withEscapes, true);
		tassert (ret);
		tassert (withEscapes == "hard\tTo \"parse\"");
		
		// sub object
		sf::json::Object subParser;
		ret = parser.get("objecttype").fetch (subParser);
		tassert (ret);
		checkField (subParser, "a", 5);
		checkField (subParser, "b", std::string ("string"));

		// the array
		sf::json::Array arr;
		ret = parser.get("arraytype").fetch(arr);
		tassert (ret);
		checkField (arr, 0, 3);
		checkField (arr, 1, 5);
		checkField (arr, 3, -34);
		checkField (arr, 4, std::string ("text"));
		tassert ((arr.get(5).type() == sf::json::ObjectType), "Wrong type");

	}
	{
		// Empty objects
		const char * emptyObjects = "{\"emptySubObject\" : {}, \"emptyVector\" : [], \"emptyString\" : \"\"}";
		sf::json::Object parser (emptyObjects);
		tassert ((!parser.error()), "Should not give an error");
		
		// sub object
		sf::json::Object subObject;
		parser.get("emptySubObject").fetch(subObject);
		tassert (!subObject.error());
		tassert (subObject.entryCount() == 0);
		
		// empty vector
		sf::json::Array emptyVector;
		parser.get ("emptyVector").fetch(emptyVector);
		tassert (!emptyVector.error());
		tassert (emptyVector.count() == 0);
	
		// empty string
		sf::json::Value emptyString;
		std::string s;
		bool suc = parser.get ("emptyString").fetch(s);
		tassert (suc);
		tassert (s.empty());
	}

	{
		// test command parser
		std::string test = "MyCommand{\"arg\":\"ument\"}";
		std::string test2= "  XtraLong\n{\"x\":5}";
		std::string cmd;
		{
			sf::json::Object o (test.c_str(), cmd);
			tassert (cmd == "MyCommand");
			checkField (o, "arg", std::string("ument"));
		}
		{
			sf::json::Object o (test2.c_str(), cmd);
			tassert (cmd == "XtraLong");
			checkField (o, "x", 5);
		}
	}
}
コード例 #27
0
ファイル: vcard.cpp プロジェクト: soubok/libset
  VCard::VCard( Tag *vcard )
    : m_class( ClassNone ), m_prodid( "gloox" + GLOOX_VERSION ),
      m_N( false ), m_PHOTO( false ), m_LOGO( false )
  {
    checkField( vcard, "FN", m_formattedname );
    checkField( vcard, "NICKNAME", m_nickname );
    checkField( vcard, "URL", m_url );
    checkField( vcard, "BDAY", m_bday );
    checkField( vcard, "JABBERID", m_jabberid );
    checkField( vcard, "TITLE", m_title );
    checkField( vcard, "ROLE", m_role );
    checkField( vcard, "NOTE", m_note );
    checkField( vcard, "DESC", m_desc );
    checkField( vcard, "MAILER", m_mailer );
    checkField( vcard, "TZ", m_tz );
    checkField( vcard, "PRODID", m_prodid );
    checkField( vcard, "REV", m_rev );
    checkField( vcard, "SORT-STRING", m_sortstring );
    checkField( vcard, "UID", m_uid );

    Tag::TagList::const_iterator it = vcard->children().begin();
    for( ; it != vcard->children().end(); ++it )
    {
      if( (*it)->name() == "N" )
      {
        m_N = true;
        if( (*it)->hasChild( "FAMILY" ) )
          m_name.family = (*it)->findChild( "FAMILY" )->cdata();
        if( (*it)->hasChild( "GIVEN" ) )
          m_name.given = (*it)->findChild( "GIVEN" )->cdata();
        if( (*it)->hasChild( "MIDDLE" ) )
          m_name.middle = (*it)->findChild( "MIDDLE" )->cdata();
        if( (*it)->hasChild( "PREFIX" ) )
          m_name.prefix = (*it)->findChild( "PREFIX" )->cdata();
        if( (*it)->hasChild( "SUFFIX" ) )
          m_name.suffix = (*it)->findChild( "SUFFIX" )->cdata();
      }
      else if( (*it)->name() == "PHOTO" )
      {
        if( (*it)->hasChild( "EXTVAL" ) )
        {
          m_photo.extval = (*it)->findChild( "EXTVAL" )->cdata();
          m_PHOTO = true;
        }
        else if( (*it)->hasChild( "TYPE" ) && (*it)->hasChild( "BINVAL" ) )
        {
          std::string binval = (*it)->findChild( "BINVAL" )->cdata();
          std::string::size_type pos = 0;
          while( ( pos = binval.find( '\n' ) ) != std::string::npos )
            binval.erase( pos, 1 );
          m_photo.type = (*it)->findChild( "TYPE" )->cdata();
          m_photo.binval = Base64::decode64( binval );
          m_PHOTO = true;
        }
      }
      else if( (*it)->name() == "LOGO" )
      {
        if( (*it)->hasChild( "EXTVAL" ) )
        {
          m_logo.extval = (*it)->findChild( "EXTVAL" )->cdata();
          m_LOGO = true;
        }
        else if( (*it)->hasChild( "TYPE" ) && (*it)->hasChild( "BINVAL" ) )
        {
          std::string binval = (*it)->findChild( "BINVAL" )->cdata();
          std::string::size_type pos = 0;
          while( ( pos = binval.find( '\n' ) ) != std::string::npos )
            binval.erase( pos, 1 );
          m_logo.type = (*it)->findChild( "TYPE" )->cdata();
          m_logo.binval = Base64::decode64( binval );
          m_LOGO = true;
        }
      }
      else if( (*it)->name() == "EMAIL" && (*it)->hasChild( "USERID" ) )
      {
        Email item;
        item.userid = (*it)->findChild( "USERID" )->cdata();
        item.internet = (*it)->hasChild( "INTERNET" );
        item.x400 = (*it)->hasChild( "X400" );
        item.work = (*it)->hasChild( "WORK" );
        item.home = (*it)->hasChild( "HOME" );
        item.pref = (*it)->hasChild( "PREF" );
        m_emailList.push_back( item );
      }
      else if( (*it)->name() == "ADR" )
      {
        Address item;
        checkField( (*it), "POBOX", item.pobox );
        checkField( (*it), "EXTADD", item.extadd );
        checkField( (*it), "STREET", item.street );
        checkField( (*it), "LOCALITY", item.locality );
        checkField( (*it), "REGION", item.region );
        checkField( (*it), "PCODE", item.pcode );
        checkField( (*it), "CTRY", item.ctry );
        item.postal = (*it)->hasChild( "POSTAL" );
        item.parcel = (*it)->hasChild( "PARCEL" );
        item.work = (*it)->hasChild( "WORK" );
        item.home = (*it)->hasChild( "HOME" );
        item.pref = (*it)->hasChild( "PREF" );
        item.dom = (*it)->hasChild( "DOM" );
        item.intl = !item.dom && (*it)->hasChild( "INTL" );
        m_addressList.push_back( item );
      }
      else if( (*it)->name() == "LABEL" )
      {
        Label item;
        Tag::TagList::const_iterator it2 = (*it)->children().begin();
        for( ; it2 != (*it)->children().end(); ++it2 )
        {
          if( (*it2)->name() == "LINE" )
            item.lines.push_back( (*it)->cdata() );
          item.postal = (*it2)->name() == "POSTAL";
          item.parcel = (*it2)->name() == "PARCEL";
          item.work = (*it2)->name() == "WORK";
          item.home = (*it2)->name() == "HOME";
          item.pref = (*it2)->name() == "PREF";
          item.dom = (*it2)->name() == "DOM";
          item.intl = !item.dom && (*it2)->name() == "INTL";
        }
        m_labelList.push_back( item );
      }
      else if( (*it)->name() == "TEL" && (*it)->hasChild( "NUMBER" ) )
      {
        Telephone item;
        item.number = (*it)->findChild( "NUMBER" )->cdata();
        item.work = (*it)->hasChild( "WORK" );
        item.home = (*it)->hasChild( "HOME" );
        item.voice = (*it)->hasChild( "VOICE" );
        item.fax = (*it)->hasChild( "FAX" );
        item.pager = (*it)->hasChild( "PAGER" );
        item.msg = (*it)->hasChild( "MSG" );
        item.cell = (*it)->hasChild( "CELL" );
        item.video = (*it)->hasChild( "VIDEO" );
        item.bbs = (*it)->hasChild( "BBS" );
        item.modem = (*it)->hasChild( "MODEM" );
        item.isdn = (*it)->hasChild( "ISDN" );
        item.pcs = (*it)->hasChild( "PCS" );
        item.pref = (*it)->hasChild( "PREF" );
        m_telephoneList.push_back( item );
      }
      else if( (*it)->name() == "ORG" )
      {
        Tag::TagList::const_iterator ito = (*it)->children().begin();
        for( ; ito != (*it)->children().end(); ++ito )
        {
          if( (*ito)->name() == "ORGNAME" )
            m_org.name = (*ito)->cdata();
          else if( (*ito)->name() == "ORGUNIT" )
            m_org.units.push_back( (*ito)->cdata() );
        }
      }
      else if( (*it)->name() == "GEO" )
      {
        checkField( (*it), "LON", m_geo.longitude );
        checkField( (*it), "LAT", m_geo.latitude );
      }
      else if( (*it)->name() == "CLASS" )
      {
        if( (*it)->hasChild( "PRIVATE" ) )
          m_class = ClassPrivate;
        else if( (*it)->hasChild( "PUBLIC" ) )
          m_class = ClassPublic;
        else if( (*it)->hasChild( "CONFIDENTIAL" ) )
          m_class = ClassConfidential;
      }

    }

  }
コード例 #28
0
void TextSerializer::write(unsigned long val) {
	cout << val;
	checkField();
}
コード例 #29
0
ファイル: GameOfLife.cpp プロジェクト: Duality4Y/projects
int main(void)
{
	lcd.clearMarkers();
	//init analog if needed
	init_analog();
	srand(adc_read(0));
	
	//pin 0 on portb output. 
	//led stays on if iterations between fields are the same (same number of cells)
	DDRB |= _BV(PB0);
	
	//clear the buffer.
	clearArray(buffer);
	
	//if house define insert that.
	#ifdef PATTERN
		insert_pattern(field, Glider, 0,0);
	#endif
	//else random field.
	#ifdef RANDOM
		createRandomField(field);
	#endif
	
	//set contrast.
	lcd.setContrast(17);
	//make sure to start at location 0,0
	lcd.setCursor(0,0);
	
	//position is field size, I refresh the screen Backwards.
	position = fieldSize;
	while(position--)
	{
		//display field with current position
		showField(field, fieldSize-position);
		//here the rules of the game of life are checked.
		//if a position has a cell (1),
		//then look how many around,
		//if 2 or 3 around it lives, else it dies.
		//if(field[position])
		//{
		//	if(totalAround(field, position)==surviveAbility)
		//	{
		//		buffer[position]=1;
		//	}
		//	else if(totalAround(field, position)==surviveAbility+1)
		//	{
		//		buffer[position]=1;
		//	}
		//	else
		//	{
		//		buffer[position]=0;
		//	}
		//}
		//else
		//{
			//but if a position in the field is empty
			//and it has 3 around, that position becomes alife.
			
		//	if(totalAround(field, position)==reproductiveNumber)
		//	{
		//		buffer[position] = 1;
		//	}
		//	else
		//	{
		//		buffer[position] = 0;
		//	}
		//}
		//position keeps position in the field array,
		//and at the same time drawing location on
		//screen.
		if(position == 0)
		{
			//insert changes into the field.
			copy_buffer(buffer, field);
			//reset position to 0
			position = fieldSize;
			//set frame rate with a blocking delay..
			delay(adc_read(1));
			//check wether we are in a steady state or just still evolving.
			currentState = checkField(field);
			//set contrast with pot meter on analog pin 1 (not 0)
			lcd.setContrast(32/2);
			//change field if field the same a while, or iterations goes above a certain number which meens it's probaly in a loop
			//check if button is pressed and create a new field.
			if(changeCount == holdingNumber || (iterations > 1000) || (PINB & (1<<PB2)))
			{
				//reset changeCount
				changeCount = 0;
				//reset iteration count.
				iterations = 0;
				//create a random playing field.
				#ifdef PATTERN
					insert_pattern(field, Glider, 0,0);
				#endif
					//createRandomField(field);
				//put a pattern we created onto the field.
				//insert_field(stable, field);
				
			}
			//if the field states stay the same.
			else if(currentState == previousState)
			{
				PORTB |= (1<<PB0);
				changeCount++;
			}
			//if the field states are different.
			else
			{
				PORTB &= ~(1<<PB0);
				previousState = currentState;
				//that is why setting it to zero.
				iterations++;
				//changeCount shouldn't change if the inbetween states happen te be the same.
				changeCount = 0;
			}
		//set location and nicely print something.
		lcd.setCursor(0,5);
		writeFormated(iterations,changeCount,"Game of Life:");
		}
	}
	return 0;
}
コード例 #30
0
ファイル: field.cpp プロジェクト: bobolboris/TicTacToeQt
void Field::setCellState(int x, int y, int state){
    if(x < 0 || x >= COUNT || y < 0 || y >= COUNT) return;
    cells[x][y]->setState(state);
    cells[x][y]->repaint();
    checkField();
}