void MSOptionMenu::showMenu(unsigned long eventTime_) { if (optionMenu()!=0) { // If option menu has never been mapped, call calculateNaturalSize & placeMenuItems // to compute its size and positions of individual items. int w,h; if (optionMenu()->firstMap()==MSFalse) { optionMenu()->calculateNaturalSize(w,h); optionMenu()->placeMenuItems(); } else { w=optionMenu()->width(); h=optionMenu()->height(); } int rootx,rooty,xx,yy; rootXY(rootx,rooty); yy=rooty+fieldValue()->y()-optionMenu()->menuItemYOffset(selectedItem()); if (yy<0) yy=0; else if (yy+h>server()->height()) { yy=server()->height()-h; } xx=rootx+fieldValue()->x()-optionMenu()->menuItemXOffset(selectedItem()); if (xx<0) xx=0; else if (xx+w>server()->width()) { xx=server()->width()-w; } optionMenu()->moveTo(xx,yy); optionMenu()->popup(MSTrue,eventTime_); // Always warp the pointer } }
bool straightLineHasOnlyOneOpponent(struct field *f, int player_id, int src_x, int src_y, int dst_x, int dst_y, int *opp_x, int *opp_y) { int dx, dy, cx = src_x, cy = src_y; bool opponent_found = false; dx = sgn(dst_x - src_x); dy = sgn(dst_y - src_y); DEBUG("straightLineHasOnlyOneOpponent: %d %d %d %d %d %d\n", cx, cy, dst_x, dst_y, dx, dy); do { cx += dx; cy += dy; DEBUG("straightLineHasOnlyOneOpponent: %d %d %d\n", cx, cy, fieldValue(f, cx, cy)); if(fieldValue(f, cx, cy) != 1) { if(fieldIsOpponent(f, cx, cy) && opponent_found == false) { // found the first opponent DEBUG("straightLineHasOnlyOneOpponent: first opponent found ...\n"); *opp_x = cx; *opp_y = cy; opponent_found = true; } else if(fieldIsOpponent(f, cx, cy) && opponent_found == true) { // found a second opponent ... DEBUG("straightLineHasOnlyOneOpponent: unfortunately found a second opponent ...\n"); return false; } else { // found one of my own Steins or Dames DEBUG("straightLineHasOnlyOneOpponent: found one of my own steins or dames ...\n"); return false; } } } while(cx != dst_x && cy != dst_y); if(!opponent_found) { return false; } return true; }
QString SysIBM::featureRead(const QString &id) { printf("Feature Read: '%s'\n\n", id.ascii()); if (id == LAPSUS_FEAT_BACKLIGHT_ID) return fieldValue("level", IBM_BACKLIGHT_PATH); if (id == IBM_LIGHT_ID) { if (fieldValue("status", IBM_LIGHT_PATH) == IBM_ON) return LAPSUS_FEAT_ON; return LAPSUS_FEAT_OFF; } // TODO - add (un)mute command if (id == LAPSUS_FEAT_VOLUME_ID) return fieldValue("level", IBM_VOLUME_PATH); if (id == LAPSUS_FEAT_BLUETOOTH_ID) { QString val = fieldValue("status", IBM_BLUETOOTH_PATH); // Enabled/disabled - lets 'translate' it if (val == IBM_ENABLED) return LAPSUS_FEAT_ON; else return LAPSUS_FEAT_OFF; } QString tmp; if (isDisplayFeature(id, tmp)) { QString val = fieldValue(tmp, IBM_DISPLAY_PATH); // Enabled/disabled - lets 'translate' it if (val == IBM_ENABLED) return LAPSUS_FEAT_ON; else return LAPSUS_FEAT_OFF; } if (isLEDFeature(id, tmp)) { // There is no way to READ LED status. So we return // what we wrote, or OFF it we haven't written anything QString val = _leds[tmp]; if (val.length() < 1) return LAPSUS_FEAT_OFF; return val; } return ""; }
TEST_F(SimpleDynamicObjectTests, test4) { rs::jsapi::Value fieldValue(rt_); auto context = rt_.NewContext(); rs::jsapi::Value obj(*context); rs::jsapi::DynamicObject::Create( *context, nullptr, [&](const char* name, const rs::jsapi::Value& value) { fieldValue.set(value); }, nullptr, nullptr, obj); ASSERT_TRUE(!!obj); rt_.Evaluate("var myfunc=function(o){ o.test = 'world';};"); rs::jsapi::FunctionArguments args(rt_); args.Append(obj); rt_.Call("myfunc", args); ASSERT_TRUE(fieldValue.isString()); ASSERT_STREQ("world", fieldValue.ToString().c_str()); }
TEST_F(SimpleDynamicObjectTests, test5) { std::string longFieldName(384, '1'); rs::jsapi::Value fieldValue(rt_); auto context = rt_.NewContext(); rs::jsapi::Value obj(*context); rs::jsapi::DynamicObject::Create( *context, nullptr, [&](const char* name, const rs::jsapi::Value& value) { fieldValue.set(value); }, nullptr, nullptr, obj); ASSERT_TRUE(!!obj); std::stringstream script; script << "var myfunc=function(o){ o['" << longFieldName << "'] = 'world';};"; rt_.Evaluate(script.str().c_str()); rs::jsapi::FunctionArguments args(rt_); args.Append(obj); rt_.Call("myfunc", args); ASSERT_TRUE(fieldValue.isString()); ASSERT_STREQ("world", fieldValue.ToString().c_str()); }
void CppSQLite3Table::fillRowValues(std::vector<std::string>& _row, const std::vector<int> fields) { for (std::vector<int>::const_iterator fld = fields.begin(); fld!=fields.end(); fld++) { if (!fieldIsNull(*fld)) _row.push_back(fieldValue(*fld)); else _row.push_back(""); } }
int CppSQLite3Table::getIntField(int nField, int nNullValue/*=0*/) { if (fieldIsNull(nField)) { return nNullValue; } else { return atoi(fieldValue(nField)); } }
CString CppSQLite3Query::getStringField(int nField, const CString& szNullValue/*=""*/) { if (fieldDataType(nField) == SQLITE_NULL) { return szNullValue; } else { return CString::fromUtf8(fieldValue(nField)); } }
int CppSQLite3Table::getIntField(const char* szField, int nNullValue/*=0*/) { if (fieldIsNull(szField)) { return nNullValue; } else { return atoi(fieldValue(szField)); } }
double CppSQLite3Table::getFloatField(int nField, double fNullValue/*=0.0*/) { if (fieldIsNull(nField)) { return fNullValue; } else { return atof(fieldValue(nField)); } }
double CppSQLite3Table::getFloatField(const char* szField, double fNullValue/*=0.0*/) { if (fieldIsNull(szField)) { return fNullValue; } else { return atof(fieldValue(szField)); } }
const char* CppSQLite3Table::getStringField(const char* szField, const char* szNullValue/*=""*/) { if (fieldIsNull(szField)) { return szNullValue; } else { return fieldValue(szField); } }
void nextMove(ucontext_t *my_context, ucontext_t *caller_context, int player_id, struct field *old_field, struct field *current_field, char *current_move, int *current_rating) { int cx = 0; int cy = 0; for(cy = 0; cy <= 7; cy++) { for(cx = 0; cx <= 7; cx++) { int cf = fieldValue(old_field, cx, cy); int dx, dy, lx, ly; // cx = current x, cy = current y if((cf == 5 && player_id == 1) || (cf == 3 && player_id == 2)) { // Stein, correct player // dx = destination x, dy = destination y dx = fieldAheadLeftX(cx); dy = fieldAheadLeftY(cy); yieldMoveMoveIfPossible(); dx = fieldAheadRightX(cx); dy = fieldAheadRightY(cy); yieldMoveMoveIfPossible(); // dx = opponent x, dy = opponent y, lx = destination x, ly = destination y dx = fieldAheadLeftX(cx); dy = fieldAheadLeftY(cy); lx = fieldAheadLeftX(dx); ly = fieldAheadLeftY(dy); yieldKillMoveIfPossible(); dx = fieldAheadRightX(cx); dy = fieldAheadRightY(cy); lx = fieldAheadRightX(dx); ly = fieldAheadRightY(dy); yieldKillMoveIfPossible(); dx = fieldBackLeftX(cx); dy = fieldBackLeftY(cy); lx = fieldBackLeftX(dx); ly = fieldBackLeftY(dy); yieldKillMoveIfPossible(); dx = fieldBackRightX(cx); dy = fieldBackRightY(cy); lx = fieldBackRightX(dx); ly = fieldBackRightY(dy); yieldKillMoveIfPossible(); } else if((cf == 9 && player_id == 1) || (cf == 7 && player_id == 2)) { // Dame, correct player int i = 0, j = 0; for(j = 0; j < 2; j++) { for(i = -8; i <= 8; i++) { if(j == 1) { dx = cx + i; dy = cy - i; } else { dx = cx - i; dy = cy - i; } if(!fieldExists(dx, dy) || !fieldIsEmpty(old_field, dx, dy)) { continue; } // dx = destination x, dy = destination y if(straightLineIsFree(old_field, cx, cy, dx, dy)) { yieldMoveMoveIfPossible(); } else { lx = dx; ly = dy; // dx = opponent x, dy = opponent y, lx = destination x, ly = destination y if(straightLineHasOnlyOneOpponent(old_field, player_id, cx, cy, lx, ly, &dx, &dy)) { yieldKillMoveIfPossible(); } } } } } } } }
void MSEntryFieldCombo::drawTextButton(MSBoolean armed_) { if(frozen()==MSFalse&&mapped()==MSTrue) { drawBevel(buttonRect(),(armed_==MSTrue)?MSSunken:MSRaised,2); XFillRectangle(display(),window(), (armed_==MSTrue)?selectShadowGC():backgroundShadowGC(), buttonRect().x()+2,buttonRect().y()+2, buttonRect().width()-4,buttonRect().height()-4); int offset = 2 + 1; int x = buttonRect().x() + offset; int y = buttonRect().y() + 2; XDrawString(display(), window(), fieldValue()->textGC(), fieldValue()->textFontStruct(), x, y + fieldValue()->textAscent(), comboButtonLabel().string(), comboButtonLabel().length()); } }
char * CMysqlRow::fieldValue(const std::string &fieldName) { std::map<std::string, unsigned int>::iterator itr; itr = m_pQuery->m_field_index.find(fieldName); if(itr != m_pQuery->m_field_index.end()) { return fieldValue(itr->second); } fprintf(stderr, "[CMysqlRow::fieldValue]field name(%s) error\n", fieldName.c_str()); return NULL; }
bool straightLineIsFree(struct field *f, int src_x, int src_y, int dst_x, int dst_y) { int dx, dy, cx = src_x, cy = src_y; dx = sgn(dst_x - src_x); dy = sgn(dst_y - src_y); do { cx += dx; cy += dy; if(fieldValue(f, cx, cy) != 1) { return false; } } while(cx != dst_x && cy != dst_y); return true; }
TEST_F(TestQuery, QueryByNameAndValue) { { vmf::MetadataStream newStream; newStream.open(TEST_FILE, vmf::MetadataStream::ReadOnly); newStream.load(TEST_SCHEMA_NAME); for (int i = 0; i < n; i++) { vmf::Variant value(2*i); vmf::FieldValue fieldValue(TEST_FIELD_NAME2, value); auto set = newStream.queryByNameAndValue(TEST_PROPERTY_NAME1, fieldValue); ASSERT_EQ(set.size(), 1); } newStream.close(); } }
void MSOptionMenu::placement(void) { if (fieldValue()!=0&&fieldLabel()!=0) { int offset=highlightThickness()+shadowThickness(); int offset2=offset<<1; int vh=fieldValue()->textHeight()+ 2*(marginHeight()+fieldValue()->shadowThickness()+fieldValue()->highlightThickness()); int lh=fieldLabel()->textHeight()+ 2*(fieldLabel()->shadowThickness()+fieldLabel()->highlightThickness()); int lw=fieldLabel()->width(); int vw=fieldValue()->width(); int trueWidth=width()-offset2; if (labelAlignment()==MSTop) { fieldLabel()->moveTo(offset,offset); fieldValue()->moveTo(offset,offset+lh+labelSpacing()); fieldLabel()->width(lw); fieldValue()->width(vw); } else { vw=trueWidth-fieldLabel()->width(); int h=(vh>lh)?vh:lh; if (vh==lh) height(h+offset2); else if (h+offset2>height()) height(h+offset2); fieldLabel()->height(h); fieldValue()->resize(vw,h); fieldLabel()->moveTo(offset,offset); fieldValue()->moveTo(offset+fieldLabel()->width(),offset); } redraw(); } }
void MSOptionMenu::buttonPress(const XEvent *pEvent_) { if (isProtected()==MSFalse) { if (pEvent_->xbutton.x>=fieldValue()->x()&& pEvent_->xbutton.x<=fieldValue()->x()+fieldValue()->width()&& pEvent_->xbutton.y>=fieldValue()->y()&& pEvent_->xbutton.y<=fieldValue()->y()+fieldValue()->height()) { if (acceptFocus()==MSFalse||traverseFocus(this)==MSTrue) { showMenu(pEvent_->xbutton.time); } } } }
/* * Common routime to free a CSSM_X509_EXTENSIONS. Used to free * CSSM_X509_TBS_CERTLIST.extensions and * CSSM_X509_REVOKED_CERT_ENTRY.extensions. * We just cook up a CssmOid and a CssmOwnedData for each extension * and pass to CL_freeCrlFieldData(). */ static void CL_freeCssmExtensions( CSSM_X509_EXTENSIONS &extens, Allocator &alloc) { for(uint32 dex=0; dex<extens.numberOfExtensions; dex++) { CSSM_X509_EXTENSION_PTR exten = &extens.extensions[dex]; const CSSM_OID *fieldOid; /* * The field OID is either the same as the extension's OID (if we parsed * it) or CSSMOID_X509V3CertificateExtensionCStruct (if we didn't). */ switch(exten->format) { case CSSM_X509_DATAFORMAT_ENCODED: fieldOid = &CSSMOID_X509V3CertificateExtensionCStruct; break; case CSSM_X509_DATAFORMAT_PARSED: case CSSM_X509_DATAFORMAT_PAIR: fieldOid = &exten->extnId; break; default: clErrorLog("CL_freeCssmExtensions: bad exten->format (%d)", (int)exten->format); CssmError::throwMe(CSSMERR_CL_INVALID_FIELD_POINTER); } const CssmOid &fieldId = CssmOid::overlay(*fieldOid); if (exten->extnId.Data != NULL) // if this is null, something threw when it was instantiated { CssmData cData((uint8 *)exten, sizeof(CSSM_X509_EXTENSION)); CssmRemoteData fieldValue(alloc, cData); CL_freeCrlFieldData(fieldId, fieldValue, false); fieldValue.release(); // but no free (via reset() */ } } alloc.free(extens.extensions); memset(&extens, 0, sizeof(CSSM_X509_EXTENSIONS)); }
bool CppSQLite3Table::fieldIsNull(const char* szField) { checkResults(); return (fieldValue(szField) == 0); }
bool CppSQLite3Table::fieldIsNull(int nField) { checkResults(); return (fieldValue(nField) == 0); }
QTSS_Error RTSPRequest::ParseDigestHeader(StringParser *inParsedAuthLinePtr) { QTSS_Error theErr = QTSS_NoErr; fAuthScheme = qtssAuthDigest; inParsedAuthLinePtr->ConsumeWhitespace(); StrPtrLen *authLine = inParsedAuthLinePtr->GetStream(); if (NULL != authLine) { StringParser digestAuthLine(authLine); digestAuthLine.GetThru(NULL, '='); digestAuthLine.ConsumeWhitespace(); fAuthDigestResponse.Set(authLine->Ptr, authLine->Len); } while(inParsedAuthLinePtr->GetDataRemaining() != 0) { StrPtrLen fieldNameAndValue(""); inParsedAuthLinePtr->GetThru(&fieldNameAndValue, ','); StringParser parsedNameAndValue(&fieldNameAndValue); StrPtrLen fieldName(""); StrPtrLen fieldValue(""); //Parse name="value" pair fields in the auth line parsedNameAndValue.ConsumeUntil(&fieldName, '='); parsedNameAndValue.ConsumeLength(NULL, 1); parsedNameAndValue.GetThruEOL(&fieldValue); StringParser::UnQuote(&fieldValue); // fieldValue.Ptr below is a pointer to a part of the qtssAuthorizationHeader // as GetValue returns a pointer // Since the header attribute remains for the entire time the request is alive // we don't need to make copies of the values of each field into the request // object, and can just keep pointers to the values // Thus, no need to delete memory for the following fields when the request is deleted: // fAuthRealm, fAuthNonce, fAuthUri, fAuthNonceCount, fAuthResponse, fAuthOpaque if(fieldName.Equal(sUsernameStr)) { // Set the qtssRTSPReqUserName attribute in the Request object (void) this->SetValue(qtssRTSPReqUserName, 0, fieldValue.Ptr , fieldValue.Len, QTSSDictionary::kDontObeyReadOnly); // Also set the qtssUserName attribute in the qtssRTSPReqUserProfile object attribute of the Request Object (void) fUserProfile.SetValue(qtssUserName, 0, fieldValue.Ptr, fieldValue.Len, QTSSDictionary::kDontObeyReadOnly); } else if(fieldName.Equal(sRealmStr)) { fAuthRealm.Set(fieldValue.Ptr, fieldValue.Len); } else if(fieldName.Equal(sNonceStr)) { fAuthNonce.Set(fieldValue.Ptr, fieldValue.Len); } else if(fieldName.Equal(sUriStr)) { fAuthUri.Set(fieldValue.Ptr, fieldValue.Len); } else if(fieldName.Equal(sQopStr)) { if(fieldValue.Equal(sQopAuthStr)) fAuthQop = RTSPSessionInterface::kAuthQop; else if(fieldValue.Equal(sQopAuthIntStr)) fAuthQop = RTSPSessionInterface::kAuthIntQop; } else if(fieldName.Equal(sNonceCountStr)) { fAuthNonceCount.Set(fieldValue.Ptr, fieldValue.Len); } else if(fieldName.Equal(sResponseStr)) { fAuthResponse.Set(fieldValue.Ptr, fieldValue.Len); } else if(fieldName.Equal(sOpaqueStr)) { fAuthOpaque.Set(fieldValue.Ptr, fieldValue.Len); } inParsedAuthLinePtr->ConsumeWhitespace(); } return theErr; }
const char* CppSQLite3Query::fieldValue(const CString& szField) { int nField = fieldIndex(szField); return fieldValue(nField); }
void SysIBM::detect() { QString path, val; path = IBM_BACKLIGHT_PATH; if (QFile::exists(path) && testR(path)) { val = fieldValue("level", path); if (val.length() > 0) { bool ok; val.toInt(&ok); if (ok) _hasBacklight = true; } } path = IBM_VOLUME_PATH; if (QFile::exists(path) && testR(path)) { val = fieldValue("level", path); if (val.length() > 0) { bool ok; val.toInt(&ok); if (ok) _hasVolume = true; } } path = IBM_BLUETOOTH_PATH; if (QFile::exists(path) && testR(path)) { val = fieldValue("status", path); if (val == "enabled" || val == "disabled") _hasBluetooth = true; } path = IBM_LIGHT_PATH; if (QFile::exists(path) && testR(path)) { val = fieldValue("status", path); if (val == "on" || val == "off") _hasLight = true; } path = IBM_LED_PATH; if (QFile::exists(path) && testR(path)) { val = fieldValue("status", path); if (val == "supported") { _hasLEDs = true; setFeature(LAPSUS_FEAT_LED_ID_PREFIX "0", "", I18N_NOOP("Power LED")); setFeature(LAPSUS_FEAT_LED_ID_PREFIX "1", "", I18N_NOOP("Orange Battery LED")); setFeature(LAPSUS_FEAT_LED_ID_PREFIX "2", "", I18N_NOOP("Green Battery LED")); setFeature(LAPSUS_FEAT_LED_ID_PREFIX "3", "", I18N_NOOP("UltraBase LED")); setFeature(LAPSUS_FEAT_LED_ID_PREFIX "4", "", I18N_NOOP("UltraBay LED")); setFeature(LAPSUS_FEAT_LED_ID_PREFIX "5", "", I18N_NOOP("5th LED")); setFeature(LAPSUS_FEAT_LED_ID_PREFIX "6", "", I18N_NOOP("6th LED")); setFeature(LAPSUS_FEAT_LED_ID_PREFIX "7", "", I18N_NOOP("Standby LED")); } } path = IBM_DISPLAY_PATH; if (QFile::exists(path) && testR(path)) { val = fieldValue("status", path); if (val == "supported") _hasDisplay = true; } }
void QgsLabel::renderLabel( QgsRenderContext &renderContext, QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes ) { Q_UNUSED( classAttributes ); if ( mLabelAttributes->selectedOnly() && !selected ) return; QPen pen; QFont font; QString value; QString text; /* Calc scale (not nice) */ QgsPoint point; point = renderContext.mapToPixel().transform( 0, 0 ); double x1 = point.x(); point = renderContext.mapToPixel().transform( 1000, 0 ); double x2 = point.x(); double scale = ( x2 - x1 ) * 0.001; /* Text */ value = fieldValue( Text, feature ); if ( value.isEmpty() ) { text = mLabelAttributes->text(); } else { text = value; } /* Font */ value = fieldValue( Family, feature ); if ( value.isEmpty() ) { font.setFamily( mLabelAttributes->family() ); } else { font.setFamily( value ); } double size; value = fieldValue( Size, feature ); if ( value.isEmpty() ) { size = mLabelAttributes->size(); } else { size = value.toDouble(); } int sizeType; value = fieldValue( SizeType, feature ); if ( value.isEmpty() ) sizeType = mLabelAttributes->sizeType(); else { value = value.toLower(); if ( value.compare( "mapunits" ) == 0 ) sizeType = QgsLabelAttributes::MapUnits; else sizeType = QgsLabelAttributes::PointUnits; } if ( sizeType == QgsLabelAttributes::MapUnits ) { size *= scale; } else //point units { double sizeMM = size * 0.3527; size = sizeMM * renderContext.scaleFactor(); } //Request font larger (multiplied by rasterScaleFactor) as a workaround for the Qt font bug //and scale the painter down by rasterScaleFactor when drawing the label size *= renderContext.rasterScaleFactor(); if (( int )size <= 0 ) // skip too small labels return; font.setPixelSize( size ); value = fieldValue( Color, feature ); if ( value.isEmpty() ) { pen.setColor( mLabelAttributes->color() ); } else { pen.setColor( QColor( value ) ); } value = fieldValue( Bold, feature ); if ( value.isEmpty() ) { font.setBold( mLabelAttributes->bold() ); } else { font.setBold(( bool ) value.toInt() ); } value = fieldValue( Italic, feature ); if ( value.isEmpty() ) { font.setItalic( mLabelAttributes->italic() ); } else { font.setItalic(( bool ) value.toInt() ); } value = fieldValue( Underline, feature ); if ( value.isEmpty() ) { font.setUnderline( mLabelAttributes->underline() ); } else { font.setUnderline(( bool ) value.toInt() ); } value = fieldValue( StrikeOut, feature ); if ( value.isEmpty() ) { font.setStrikeOut( mLabelAttributes->strikeOut() ); } else { font.setStrikeOut(( bool ) value.toInt() ); } // QgsPoint overridePoint; bool useOverridePoint = false; value = fieldValue( XCoordinate, feature ); if ( !value.isEmpty() ) { overridePoint.setX( value.toDouble() ); useOverridePoint = true; } value = fieldValue( YCoordinate, feature ); if ( !value.isEmpty() ) { overridePoint.setY( value.toDouble() ); useOverridePoint = true; } /* Alignment */ int alignment; QFontMetrics fm( font ); int width, height; if ( mLabelAttributes->multilineEnabled() ) { QStringList texts = text.split( "\n" ); width = 0; for ( int i = 0; i < texts.size(); i++ ) { int w = fm.width( texts[i] ); if ( w > width ) width = w; } height = fm.height() * texts.size(); } else { width = fm.width( text ); height = fm.height(); } int dx = 0; int dy = 0; value = fieldValue( Alignment, feature ); if ( value.isEmpty() ) { alignment = mLabelAttributes->alignment(); } else { value = value.toLower(); alignment = 0; if ( value.contains( "left" ) ) alignment |= Qt::AlignLeft; else if ( value.contains( "right" ) ) alignment |= Qt::AlignRight; else alignment |= Qt::AlignHCenter; if ( value.contains( "bottom" ) ) alignment |= Qt::AlignBottom; else if ( value.contains( "top" ) ) alignment |= Qt::AlignTop; else alignment |= Qt::AlignVCenter; } if ( alignment & Qt::AlignLeft ) { dx = 0; } else if ( alignment & Qt::AlignHCenter ) { dx = -width / 2; } else if ( alignment & Qt::AlignRight ) { dx = -width; } if ( alignment & Qt::AlignBottom ) { dy = 0; } else if ( alignment & Qt::AlignVCenter ) { dy = height / 2; } else if ( alignment & Qt::AlignTop ) { dy = height; } // Offset double xoffset, yoffset; value = fieldValue( XOffset, feature ); if ( value.isEmpty() ) { xoffset = mLabelAttributes->xOffset(); } else { xoffset = value.toDouble(); } value = fieldValue( YOffset, feature ); if ( value.isEmpty() ) { yoffset = mLabelAttributes->yOffset(); } else { yoffset = value.toDouble(); } // recalc offset to pixels if ( mLabelAttributes->offsetType() == QgsLabelAttributes::MapUnits ) { xoffset *= scale; yoffset *= scale; } else { xoffset = xoffset * 0.3527 * renderContext.scaleFactor(); yoffset = yoffset * 0.3527 * renderContext.scaleFactor(); } // Angle double ang; value = fieldValue( Angle, feature ); if ( value.isEmpty() ) { ang = mLabelAttributes->angle(); } else { ang = value.toDouble(); } // Work out a suitable position to put the label for the // feature. For multi-geometries, put the same label on each // part. if ( useOverridePoint ) { renderLabel( renderContext, overridePoint, text, font, pen, dx, dy, xoffset, yoffset, ang, width, height, alignment ); } else { std::vector<labelpoint> points; labelPoint( points, feature ); for ( uint i = 0; i < points.size(); ++i ) { renderLabel( renderContext, points[i].p, text, font, pen, dx, dy, xoffset, yoffset, mLabelAttributes->angleIsAuto() ? points[i].angle : ang, width, height, alignment ); } } }
void CUPnPHeaderReader::DecodeManL(RHeaderField& aHeader) const { TPtrC8 rawData; aHeader.RawDataL(rawData); TInt remaining = rawData.Length(); TPtrC8 token; TInt tokensFound = 0; while (remaining > 0) { remaining -= InetProtTextUtils::ExtractNextTokenFromList(rawData, token, KCommaChar); TInt pos = token.Locate(KSemiColonChar); if (pos < 0) { // No parameters. Just store the field value InetProtTextUtils::RemoveWhiteSpace(token, InetProtTextUtils::ERemoveBoth); SetNewFStringPartL(aHeader, tokensFound, token); } else if (pos==0) { // No valid ns-value. Just store the parameter. User::Leave(KErrUPnPDecodeMAN); } else { // parameter value(s) exist. if (pos==token.Length()) // if no field value exists. i.e. an invalid header User::Leave(KErrUPnPDecodeMAN); // store the field TPtrC8 fieldValue(token.Left(pos)); TPtrC8 parameters(token.Mid(pos+1)); InetProtTextUtils::RemoveWhiteSpace(fieldValue, InetProtTextUtils::ERemoveBoth); CHeaderFieldPart* part = SetNewFStringPartL(aHeader, tokensFound, fieldValue); TPtrC8 thisParam; do { // check if there is another parameter pos = parameters.Locate(KSemiColonChar); if (pos > 0) { if (pos==token.Length()) // if no field value exists. i.e. an invalid header User::Leave(KErrUPnPDecodeMAN); thisParam.Set(parameters.Left(pos)); parameters.Set(parameters.Mid(pos+1)); } else thisParam.Set(parameters); TInt pPos = thisParam.Locate(KEqualsChar); if (pPos <= 0 || pPos==thisParam.Length()) // Invalid parameter, missing '=' char, or missing field value. User::Leave(KErrUPnPDecodeMAN); TPtrC8 paramField(thisParam.Left(pPos)); TPtrC8 paramData(thisParam.Mid(pPos + 1)); SetNewFStringParamL(*part, paramField, paramData); } while (pos > 0); } ++tokensFound; } }
int AuthorizeDotNetProcessor::handleResponse(const QString &presponse, const int pccardid, const QString &ptype, const double pamount, const int pcurrid, QString &pneworder, QString &preforder, int &pccpayid, ParameterList &pparams) { if (DEBUG) qDebug("AN::handleResponse(%s, %d, %s, %f, %d, %s, %d, pparams)", presponse.toAscii().data(), pccardid, ptype.toAscii().data(), pamount, pcurrid, preforder.toAscii().data(), pccpayid); // if we got an error msg very early on if (presponse.startsWith("<HTML>")) { _errorMsg = errorMsg(-207).arg(presponse); return -207; } QString delim = _metrics->value("CCANDelim").isEmpty() ? "," : _metrics->value("CCANDelim"); QString encap = _metrics->value("CCANEncap"); QString r_approved; QString r_avs; QString r_code; QString r_cvv; QString r_error; QString r_message; QString r_ordernum; QString r_reason; // not stored QString r_ref; QString r_shipping; QString r_tax; QString status; // TODO: explore using encap here and code from CSV Import to properly split /* add an extra field at the beginning. otherwise we'll be off by one because the Advanced Integration Method (AIM) Implementation Guide numbers fields starting at 1 but QString::split() creates a list starting at 0. */ QStringList responseFields = presponse.split(delim); QString r_response; int returnValue = fieldValue(responseFields, 1, r_response); if (returnValue < 0) return returnValue; if (r_response.toInt() == 1) r_approved = "APPROVED"; else if (r_response.toInt() == 2) r_approved == "DECLINED"; else if (r_response.toInt() == 3) r_approved == "ERROR"; else if (r_response.toInt() == 4) r_approved == "HELDFORREVIEW"; // fieldValue(responseFields, 2); // subcode returnValue = fieldValue(responseFields, 3, r_reason); // reason code if (returnValue < 0) return returnValue; returnValue = fieldValue(responseFields, 4, r_message); // reason text if (returnValue < 0) return returnValue; returnValue = fieldValue(responseFields, 5, r_code); // approval code if (returnValue < 0) return returnValue; returnValue = fieldValue(responseFields, 6, r_avs); // avs result if (returnValue < 0) return returnValue; returnValue = fieldValue(responseFields, 7, r_ordernum); // transaction id if (returnValue < 0) return returnValue; // fieldValue(responseFields, 8-10); // echo invoice_number description amount // fieldValue(responseFields, 11-13); // echo method type cust_id // fieldValue(responseFields, 14-24); // echo name, company, and address info // fieldValue(responseFields, 25-32); // echo ship_to fields returnValue = fieldValue(responseFields, 33, r_tax); // echo x_tax if (returnValue < 0) return returnValue; // fieldValue(responseFields, 34); // echo x_duty returnValue = fieldValue(responseFields, 35, r_shipping); // echo x_freight if (returnValue < 0) return returnValue; // fieldValue(responseFields, 36); // echo x_tax_exempt // fieldValue(responseFields, 37); // echo x_po_num returnValue = fieldValue(responseFields, 39, r_cvv); // ccv response code if (returnValue < 0) return returnValue; // fieldValue(responseFields, 40); // cavv response code // fieldValue(responseFields, 41-68); // reserved for future use // fieldValue(responseFields, 69+); // echo of merchant-defined fields /* treat heldforreview as approved because the AIM doc says response reason codes 252 and 253 are both approved but being reviewed. the intent of the other heldforreview, 193, is ambiguous. */ if (r_approved == "APPROVED" || r_approved == "HELDFORREVIEW") { _errorMsg = errorMsg(0).arg(r_code); if (ptype == "A") status = "A"; // Authorized else if (ptype == "V") status = "V"; // Voided else status = "C"; // Completed/Charged } else if (r_approved == "DECLINED") { _errorMsg = errorMsg(12).arg(r_message); returnValue = 12; status = "D"; } else if (r_approved == "ERROR") { r_error = r_message; _errorMsg = errorMsg(-12).arg(r_error); returnValue = -12; } else if (r_approved.isEmpty() && ! r_message.isEmpty()) { _errorMsg = errorMsg(-95).arg(r_message); returnValue = -95; status = "X"; } else if (r_approved.isEmpty()) { _errorMsg = errorMsg(-100).arg(r_error).arg(r_message).arg(presponse); returnValue = -100; status = "X"; } // always use the AVS checking configured on the gateway _passedAvs = ((r_reason.toInt() != 27) && (r_reason.toInt() != 127)); // always use the CVV checking configured on the gateway _passedCvv = (r_reason.toInt() != 78); if (DEBUG) qDebug("AN:%s _passedAvs %d\t%s _passedCvv %d", r_avs.toAscii().data(), _passedAvs, r_cvv.toAscii().data(), _passedCvv); pparams.append("ccard_id", pccardid); pparams.append("currid", pcurrid); pparams.append("auth_charge", ptype); pparams.append("type", ptype); pparams.append("reforder", (preforder.isEmpty()) ? pneworder : preforder); pparams.append("status", status); pparams.append("avs", r_avs); pparams.append("ordernum", pneworder); pparams.append("xactionid", r_ordernum); pparams.append("error", r_error); pparams.append("approved", r_approved); pparams.append("code", r_code); pparams.append("shipping", r_shipping); pparams.append("tax", r_tax); pparams.append("ref", r_ref); pparams.append("message", r_message); if (ptype == "A") pparams.append("auth", QVariant(true, 0)); else pparams.append("auth", QVariant(false, 1)); if (DEBUG) qDebug("AN:r_error.isEmpty() = %d", r_error.isEmpty()); if (returnValue == 0) pparams.append("amount", pamount); else pparams.append("amount", 0); // no money changed hands this attempt // don't bother checking MD5 if we hit a bigger problem if (returnValue == 0 && _metrics->boolean("CCANMD5HashSetOnGateway")) { QString expected_hash; QString r_hash; returnValue = fieldValue(responseFields, 38, r_hash); // md5 hash XSqlQuery anq; anq.prepare("SELECT UPPER(MD5(:inputstr)) AS expected;"); anq.bindValue(":inputstr", _metricsenc->value("CCANMD5Hash") + _metricsenc->value("CCLogin") + r_ordernum + QString::number(pamount, 'f', 2)); anq.exec(); if (anq.first()) expected_hash = anq.value("expected").toString(); else if (q.lastError().type() != QSqlError::None) { _errorMsg = errorMsg(-1).arg(anq.lastError().databaseText()); returnValue = -1; } if (DEBUG) qDebug("AN:handleResponse expected md5 %s and got %s", expected_hash.toAscii().data(), r_hash.toAscii().data()); if (_metrics->value("CCANMD5HashAction") == "F" && expected_hash != r_hash) { _errorMsg = errorMsg(-206); returnValue = -206; } else if (_metrics->value("CCANMD5HashAction") == "W" && expected_hash != r_hash) { _errorMsg = errorMsg(206); returnValue = 206; } } if (DEBUG) qDebug("AN::handleResponse returning %d %s", returnValue, errorMsg().toAscii().data()); return returnValue; }
void Communicator::makeFieldValue() { FieldValuePacket fieldValue(buffer); }
int rateMove(struct field *f, int player_id) { int white_score = 0; int black_score = 0; int x, y, ox, oy, px, py; for (y=0; y < (f->height); y++) { for (x=0; x < (f->width); x++) { switch (fieldValue(f, x, y)) { case 3: // black Stein // 100 points for having the Stein black_score += 100; // 2 points for each row closer to enemy home row (white's home row is at i=0) black_score += (f->height - y) * 2; // 1 point for most left / most right column if (x == 0 || (x+1) == f->width) { black_score += 1; } // 1000 points for protecting the home row // (we should never ever give it up as long as we can avoid it ...) if ((y+1) == f->height) { black_score += 1000; } // -70 points for being about to be taken (by enemy Stein) // ox = opponent x, oy = opponent y, px = protection x, py = protection y ox = fieldAheadLeftX(x); oy = fieldAheadLeftY(y); px = fieldBackRightX(x); py = fieldBackRightY(y); penaltyForBeingAboutToBeTakenStein(black_score); ox = fieldAheadRightX(x); oy = fieldAheadRightY(y); px = fieldBackLeftX(x); py = fieldBackLeftY(y); penaltyForBeingAboutToBeTakenStein(black_score); ox = fieldBackLeftX(x); oy = fieldBackLeftY(y); px = fieldAheadRightX(x); py = fieldAheadRightY(y); penaltyForBeingAboutToBeTakenStein(black_score); ox = fieldBackRightX(x); oy = fieldBackRightY(y); px = fieldAheadLeftX(x); py = fieldAheadLeftY(y); penaltyForBeingAboutToBeTakenStein(black_score); break; case 5: // white Stein // 100 points for having the Stein white_score += 100; // 2 points for each row closer to enemy home row (white's home row is at i=0) white_score += y * 2; // 1 point for most left / most right column if (x == 0 || (x+1) == f->width) { white_score += 1; } // 1000 points for protecting the home row // (we should never ever give it up as long as we can avoid it ...) if (y == 0) { white_score += 1000; } // -70 points for being about to be taken (by enemy Stein) // ox = opponent x, oy = opponent y, px = protection x, py = protection y ox = fieldAheadLeftX(x); oy = fieldAheadLeftY(y); px = fieldBackRightX(x); py = fieldBackRightY(y); penaltyForBeingAboutToBeTakenStein(white_score); ox = fieldAheadRightX(x); oy = fieldAheadRightY(y); px = fieldBackLeftX(x); py = fieldBackLeftY(y); penaltyForBeingAboutToBeTakenStein(white_score); ox = fieldBackLeftX(x); oy = fieldBackLeftY(y); px = fieldAheadRightX(x); py = fieldAheadRightY(y); penaltyForBeingAboutToBeTakenStein(white_score); ox = fieldBackRightX(x); oy = fieldBackRightY(y); px = fieldAheadLeftX(x); py = fieldAheadLeftY(y); penaltyForBeingAboutToBeTakenStein(white_score); break; case 7: // black Dame // 500 points for having a Dame black_score += 500; // -250 points for being about to be taken (by enemy Stein) // ox = opponent x, oy = opponent y, px = protection x, py = protection y ox = fieldAheadLeftX(x); oy = fieldAheadLeftY(y); px = fieldBackRightX(x); py = fieldBackRightY(y); penaltyForBeingAboutToBeTakenDame(black_score); ox = fieldAheadRightX(x); oy = fieldAheadRightY(y); px = fieldBackLeftX(x); py = fieldBackLeftY(y); penaltyForBeingAboutToBeTakenDame(black_score); ox = fieldBackLeftX(x); oy = fieldBackLeftY(y); px = fieldAheadRightX(x); py = fieldAheadRightY(y); penaltyForBeingAboutToBeTakenDame(black_score); ox = fieldBackRightX(x); oy = fieldBackRightY(y); px = fieldAheadLeftX(x); py = fieldAheadLeftY(y); penaltyForBeingAboutToBeTakenDame(black_score); break; case 9: // white Dame // 500 points for having a Dame white_score += 500; // -250 points for being about to be taken (by enemy Stein) // ox = opponent x, oy = opponent y, px = protection x, py = protection y ox = fieldAheadLeftX(x); oy = fieldAheadLeftY(y); px = fieldBackRightX(x); py = fieldBackRightY(y); penaltyForBeingAboutToBeTakenDame(white_score); ox = fieldAheadRightX(x); oy = fieldAheadRightY(y); px = fieldBackLeftX(x); py = fieldBackLeftY(y); penaltyForBeingAboutToBeTakenDame(white_score); ox = fieldBackLeftX(x); oy = fieldBackLeftY(y); px = fieldAheadRightX(x); py = fieldAheadRightY(y); penaltyForBeingAboutToBeTakenDame(white_score); ox = fieldBackRightX(x); oy = fieldBackRightY(y); px = fieldAheadLeftX(x); py = fieldAheadLeftY(y); penaltyForBeingAboutToBeTakenDame(white_score); break; } } } if(player_id == 1) { // I am white return white_score - black_score; } else { // I am black return black_score - white_score; } }