llvm::raw_ostream& EscapeSequence::encode(const char* const Start, size_t N, llvm::raw_ostream& Output) { const char* Ptr = Start; const char* const End = Start + N; bool isUtf8 = Start[0] != '\"'; if (!isUtf8) { bool isPrint = true; // A const char* string may not neccessarily be utf8. // When the locale can output utf8 strings, validate it as utf8 first. if (!m_Utf8Out) { while (isPrint && Ptr < End) isPrint = std::isprint(*Ptr++, m_Loc); } else isUtf8 = Validate(Ptr, N, m_Loc, isPrint); // Simple printable string, just return it now. if (isPrint) return Output << llvm::StringRef(Start, N); Ptr = Start; } else { assert((Start[0] == 'u' || Start[0] == 'U' || Start[0] == 'L') && "Unkown string encoding"); // Unicode string, assume valid isUtf8 = true; } ByteDumper Dump(*this, End, isUtf8); { // scope for llvm::raw_svector_ostream size_t LastGood = 0; HexState Hex = kText; llvm::raw_svector_ostream Strm(Dump.buf()); while ((Hex < kEnd) && (Ptr < End)) { const size_t LastPos = Ptr - Start; switch (Dump(Ptr, Strm, Hex==kHex)) { case kHex: // Printed hex char // Keep doing it as long as no escaped char have been printed Hex = (Hex == kEsc) ? kEnd : kHex; break; case kEsc: assert(Hex <= kEsc && "Escape code after hex shouldn't occur"); // Mark this as the last good character printed if (Hex == kText) LastGood = LastPos; Hex = kEsc; default: break; } } if (Hex != kEnd) return Output << Strm.str(); Ptr = Start + LastGood; Dump.buf().resize(LastGood); } // Force hex output for the rest of the string llvm::raw_svector_ostream Strm(Dump.buf()); while (Ptr < End) Dump(Ptr, Strm, true); return Output << Strm.str(); }
bool RoutingCondition::internalEvalFunction( RoutingMessage& message ) const { DEBUG( "Evaluating function" ); switch ( m_EvalFunction ) { case RoutingCondition::VALIDATE_TO_XSD : { // local case vars block // create an XSD filter XSDFilter myFilter; NameValueCollection headers; headers.Add( XSDFilter::XSDFILE, m_EvalFunctionParams[ 0 ] ); if ( m_EvalFunctionParams.size() > 1 ) headers.Add( XSDFilter::XSDNAMESPACE, m_EvalFunctionParams[ 1 ] ); bool valid = true; try { myFilter.ProcessMessage( message.getPayload()->getDoc(), headers, true ); } catch( const XSDValidationException& ex ) { TRACE( ex.getMessage() ); valid = false; } return m_Evaluator.EvaluateBool( valid ); } case RoutingCondition::VALIDATE : { bool valid = true; string options = ""; if ( m_EvalFunctionParams.size() > 0 ) options = m_EvalFunctionParams[ 0 ]; valid = Validate( options, message ); return m_Evaluator.EvaluateBool( valid ); } case RoutingCondition::IS_ACK : { if ( m_EvalFunctionParams.size() == 0 ) return m_Evaluator.EvaluateBool( message.isAck() ); // hack for dd : RoutingMessageEvaluator* evaluator = message.getPayloadEvaluator(); if ( ( evaluator != NULL ) && ( evaluator->CheckPayloadType( RoutingMessageEvaluator::ACHBLKACC ) ) ) { return m_Evaluator.EvaluateBool( evaluator->isAck( m_EvalFunctionParams[ 0 ] ) ); } DEBUG( "Condition failed because the message is not in the correct format for ACK(param) evaluation" ); return false; } case RoutingCondition::IS_NACK : { if ( m_EvalFunctionParams.size() == 0 ) return m_Evaluator.EvaluateBool( message.isNack() ); // hack for dd : RoutingMessageEvaluator* evaluator = message.getPayloadEvaluator(); if ( ( evaluator != NULL ) && ( evaluator->CheckPayloadType( RoutingMessageEvaluator::ACHBLKRJCT ) ) ) { return m_Evaluator.EvaluateBool( evaluator->isNack( m_EvalFunctionParams[ 0 ] ) ); } DEBUG( "Condition failed because the message is not in the correct format for NACK(param) evaluation" ); return false; } case RoutingCondition::IS_REPLY : return m_Evaluator.EvaluateBool( message.isReply() ); default : // this should not happen ( function is parsed in ctor ) throw runtime_error( "Invalid function requested for evaluation." ); break; } return false; }
///---------------------------------------------------------------------------- /// <summary> /// Executes the operation. /// </summary> /// /// <exceptions> /// MgException /// </exceptions> ///---------------------------------------------------------------------------- void MgOpGetConnectionPropertyValues::Execute() { ACE_DEBUG((LM_DEBUG, ACE_TEXT(" (%t) MgOpGetConnectionPropertyValues::Execute()\n"))); MG_LOG_OPERATION_MESSAGE(L"GetConnectionPropertyValues"); MG_FEATURE_SERVICE_TRY() MG_LOG_OPERATION_MESSAGE_INIT(m_packet.m_OperationVersion, m_packet.m_NumArguments); ACE_ASSERT(m_stream != NULL); if (3 == m_packet.m_NumArguments) { // Get provider name STRING providerName; m_stream->GetString(providerName); // Get property name STRING propertyName; m_stream->GetString(propertyName); // Get partialConnString name STRING partialConnString; m_stream->GetString(partialConnString); BeginExecution(); MG_LOG_OPERATION_MESSAGE_PARAMETERS_START(); MG_LOG_OPERATION_MESSAGE_ADD_STRING(providerName.c_str()); MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR(); MG_LOG_OPERATION_MESSAGE_ADD_STRING(propertyName.c_str()); MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR(); MG_LOG_OPERATION_MESSAGE_ADD_STRING(partialConnString.c_str()); MG_LOG_OPERATION_MESSAGE_PARAMETERS_END(); Validate(); // Execute the operation Ptr<MgStringCollection> strCol = m_service->GetConnectionPropertyValues(providerName, propertyName, partialConnString); // Write the response EndExecution((MgSerializable*)((MgStringCollection*)strCol)); } else { MG_LOG_OPERATION_MESSAGE_PARAMETERS_START(); MG_LOG_OPERATION_MESSAGE_PARAMETERS_END(); } if (!m_argsRead) { throw new MgOperationProcessingException(L"MgOpGetConnectionPropertyValues.Execute", __LINE__, __WFILE__, NULL, L"", NULL); } // Successful operation MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Success.c_str()); MG_FEATURE_SERVICE_CATCH(L"MgOpGetConnectionPropertyValues.Execute") if (mgException != NULL) { // Failed operation MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Failure.c_str()); } // Add access log entry for operation MG_LOG_OPERATION_MESSAGE_ACCESS_ENTRY(); MG_FEATURE_SERVICE_THROW() }
void Val_e_ticket::validate() { Validate(b); }
void wxGxObjectDialog::OnOK(wxCommandEvent& event) { m_nRetCode = wxID_OK; if ( Validate() && TransferDataFromWindow() ) { int nPos = m_WildcardCombo->GetCurrentSelection(); wxGxSelection* pSel = m_pwxGxContentView->GetSelectedObjects(); if(NULL == pSel) return; long nSelID = pSel->GetFirstSelectedObjectId(); wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(nSelID); //fill out data if(m_bIsSaveDlg) { if(pGxObject && pGxObject->IsKindOf(wxCLASSINFO(wxGxObjectContainer))) { GetGxSelection()->Select(nSelID, false, wxGxSelection::INIT_ALL); return; } if(nPos != m_FilterArray.GetCount()) { wxGISEnumSaveObjectResults Result = m_FilterArray[nPos]->CanSaveObject(GetLocation(), GetName()); if(!DoSaveObject(Result)) return; } else { for(size_t j = 0; j < m_FilterArray.GetCount(); ++j) { wxGISEnumSaveObjectResults Result = m_FilterArray[j]->CanSaveObject(GetLocation(), GetName()); if(DoSaveObject(Result)) break; } } } else { if (pGxObject && pGxObject->IsKindOf(wxCLASSINFO(wxGxObjectContainer)) && !m_FilterArray[nPos]->CanChooseObject(pGxObject)) { GetGxSelection()->Select(nSelID, false, wxGxSelection::INIT_ALL); return; } for (size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pSel->GetSelectedObjectId(i)); if(nPos == m_FilterArray.GetCount()) { for(size_t j = 0; j < m_FilterArray.size(); ++j) { bool bCanChooseObject = false; if(m_FilterArray[j]->CanChooseObject(pGxObject)) { m_ObjectList.Append(pGxObject); break; } else { if(pGxObject->IsKindOf(wxCLASSINFO(wxGxObjectContainer))) { GetGxSelection()->Select(pGxObject->GetId(), false, wxGxSelection::INIT_ALL); return; } } } } else { if(m_FilterArray[nPos]->CanChooseObject(pGxObject)) { m_ObjectList.Append(pGxObject); } else { if(pGxObject->IsKindOf(wxCLASSINFO(wxGxObjectContainer))) { GetGxSelection()->Select(pGxObject->GetId(), false, wxGxSelection::INIT_ALL); return; } } } } if(GetChildren().IsEmpty()) { wxMessageBox(_("Cannot choose item(s)"), _("Error"), wxICON_ERROR | wxOK, this); return; } } wxTreeItemId ItemId = m_PopupCtrl->GetSelection(); if(ItemId.IsOk()) { wxGxTreeItemData* pData = (wxGxTreeItemData*)m_PopupCtrl->GetItemData(ItemId); if(pData != NULL) { wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); wxGISAppConfig oConfig = GetConfig(); if (pGxObject && oConfig.IsOk()) { oConfig.Write(enumGISHKCU, GetAppName() + wxString(wxT("/lastpath/path")), pGxObject->GetFullName()); } } } if ( IsModal() ) EndModal(m_nRetCode); else { SetReturnCode(m_nRetCode); this->Show(false); } } }
///---------------------------------------------------------------------------- /// <summary> /// Executes the operation. /// </summary> /// /// <exceptions> /// MgException /// </exceptions> ///---------------------------------------------------------------------------- void MgOpUpdateRepository::Execute() { ACE_DEBUG((LM_DEBUG, ACE_TEXT(" (%t) MgOpUpdateRepository::Execute()\n"))); MG_LOG_OPERATION_MESSAGE(L"UpdateRepository"); MG_RESOURCE_SERVICE_TRY() MG_LOG_OPERATION_MESSAGE_INIT(m_packet.m_OperationVersion, m_packet.m_NumArguments); ACE_ASSERT(m_stream != NULL); if (3 == m_packet.m_NumArguments) { Ptr<MgResourceIdentifier> resource = (MgResourceIdentifier*)m_stream->GetObject(); Ptr<MgByteReader> content = (MgByteReader*)m_stream->GetObject(); Ptr<MgByteReader> header = (MgByteReader*)m_stream->GetObject(); BeginExecution(); MG_LOG_OPERATION_MESSAGE_PARAMETERS_START(); MG_LOG_OPERATION_MESSAGE_ADD_STRING((NULL == resource) ? L"MgResourceIdentifier" : resource->ToString().c_str()); MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR(); MG_LOG_OPERATION_MESSAGE_ADD_STRING(L"MgByteReader"); MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR(); MG_LOG_OPERATION_MESSAGE_ADD_STRING(L"MgByteReader"); MG_LOG_OPERATION_MESSAGE_PARAMETERS_END(); Validate(); m_service->UpdateRepository(resource, content, header); EndExecution(); } else { MG_LOG_OPERATION_MESSAGE_PARAMETERS_START(); MG_LOG_OPERATION_MESSAGE_PARAMETERS_END(); } if (!m_argsRead) { throw new MgOperationProcessingException(L"MgOpUpdateRepository.Execute", __LINE__, __WFILE__, NULL, L"", NULL); } // Successful operation MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Success.c_str()); MG_RESOURCE_SERVICE_CATCH(L"MgOpUpdateRepository.Execute") if (mgException != NULL) { // Failed operation MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Failure.c_str()); } // Add access log entry for operation MG_LOG_OPERATION_MESSAGE_ACCESS_ENTRY(); MG_RESOURCE_SERVICE_THROW() }
void Vis_v_ticket::validate() { Validate(b); }
int main () { printf("x = 0, y = 0, rule = B3/S23\n"); #pragma omp parallel { New(); LifeState* blck = NewState("2o$o$b3o$3bo!"); LifeState* gldL = NewState("3o$2bo$bo!"); LifeState* gldR = NewState("bo$o$3o!"); LifeIterator *iterL = NewIterator(gldL, -10, 5, 10, 1); LifeIterator *iterR1 = NewIterator(gldR, 0, -15, 10, 10, 4); LifeIterator *iterR2 = NewIterator(gldR, 0, -15, 10, 10, 4); int initPop = GetPop(blck); do{ #pragma omp single nowait { if(Validate(iterR1, iterR2) != FAIL) { New(); PutState(blck); PutState(iterL); PutState(iterR1); PutState(iterR2); int collide = NO; for(int i = 0; i < 4; i++) { if(GetPop() != 5 * 3 + initPop) { collide = YES; break; } Run(1); } if(collide != YES) { for(int i = 0; i < 300; i++) { Run(1); uint64_t gld = LocateAtX(GlobalState, _glidersTarget[0], 2); int found = NO; if(strlen(GlobalState->emittedGliders->value) != 0) break; int gen = GlobalState->gen; if(gld != 0 && GetPop() == 5) { found = YES; for(int j = 0; j < 4; j++) { if(GlobalState->gen%4 == 0) break; Run(1); } Capture(0); Move(Captures[0], (GlobalState->gen) / 4 + 4, (GlobalState->gen) / 4 + 4); Evolve(Captures[0], 2); New(); PutState(blck); PutState(iterL); PutState(iterR1); PutState(iterR2); PutState(Captures[0]); Run(gen); uint64_t gld = LocateAtX(GlobalState, _glidersTarget[0], 2); if(gld != 0 && GetPop() == 10) { New(); PutState(blck); PutState(iterL); PutState(iterR1); PutState(iterR2); PutState(Captures[0]); #pragma omp critical { printf(GetRLE(GlobalState)); printf("100$"); } } } if(found == YES) break; } } } } }while(Next(iterL, iterR1, iterR2, NO)); } printf("!"); printf("\n\nFINISH"); getchar(); }
BOOL mrShaderFilter::Validate(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex) { return Validate(v); }
///---------------------------------------------------------------------------- /// <summary> /// Executes the operation. /// </summary> /// /// <exceptions> /// MgException /// </exceptions> ///---------------------------------------------------------------------------- void MgOpDescribeSchemaAsXml::Execute() { ACE_DEBUG((LM_DEBUG, ACE_TEXT(" (%t) MgOpDescribeSchemaAsXml::Execute()\n"))); MG_LOG_OPERATION_MESSAGE(L"DescribeSchemaAsXml"); MG_FEATURE_SERVICE_TRY() MG_LOG_OPERATION_MESSAGE_INIT(m_packet.m_OperationVersion, m_packet.m_NumArguments); ACE_ASSERT(m_stream != NULL); if (3 == m_packet.m_NumArguments) { // Get the feature source Ptr<MgResourceIdentifier> resource = (MgResourceIdentifier*)m_stream->GetObject(); // Get the schema name STRING schemaName; m_stream->GetString(schemaName); // Get the class names Ptr<MgStringCollection> classNames = (MgStringCollection*)m_stream->GetObject(); BeginExecution(); MG_LOG_OPERATION_MESSAGE_PARAMETERS_START(); MG_LOG_OPERATION_MESSAGE_ADD_STRING((NULL == resource) ? L"MgResourceIdentifier" : resource->ToString().c_str()); MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR(); MG_LOG_OPERATION_MESSAGE_ADD_STRING(schemaName.c_str()); MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR(); MG_LOG_OPERATION_MESSAGE_ADD_STRING((NULL == classNames) ? L"MgStringCollection" : classNames->GetLogString().c_str()); MG_LOG_OPERATION_MESSAGE_PARAMETERS_END(); Validate(); // Execute the operation STRING schema= m_service->DescribeSchemaAsXml(resource, schemaName, classNames); // Write the response EndExecution(schema); } else { MG_LOG_OPERATION_MESSAGE_PARAMETERS_START(); MG_LOG_OPERATION_MESSAGE_PARAMETERS_END(); } if (!m_argsRead) { throw new MgOperationProcessingException(L"MgOpDescribeSchemaAsXml.Execute", __LINE__, __WFILE__, NULL, L"", NULL); } // Successful operation MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Success.c_str()); MG_FEATURE_SERVICE_CATCH(L"MgOpDescribeSchemaAsXml.Execute") if (mgException != NULL) { // Failed operation MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Failure.c_str()); } // Add access log entry for operation MG_LOG_OPERATION_MESSAGE_ACCESS_ENTRY(); MG_FEATURE_SERVICE_THROW() }
bool DIALOG_PAD_PROPERTIES::transferDataToPad( D_PAD* aPad ) { wxString msg; int x, y; if( !Validate() ) return true; if( !m_panelGeneral->Validate() ) return true; if( !m_localSettingsPanel->Validate() ) return true; m_OrientValidator.TransferFromWindow(); aPad->SetAttribute( code_type[m_PadType->GetSelection()] ); aPad->SetShape( code_shape[m_PadShape->GetSelection()] ); // Read pad clearances values: aPad->SetLocalClearance( ValueFromTextCtrl( *m_NetClearanceValueCtrl ) ); aPad->SetLocalSolderMaskMargin( ValueFromTextCtrl( *m_SolderMaskMarginCtrl ) ); aPad->SetLocalSolderPasteMargin( ValueFromTextCtrl( *m_SolderPasteMarginCtrl ) ); aPad->SetThermalWidth( ValueFromTextCtrl( *m_ThermalWidthCtrl ) ); aPad->SetThermalGap( ValueFromTextCtrl( *m_ThermalGapCtrl ) ); double dtmp = 0.0; msg = m_SolderPasteMarginRatioCtrl->GetValue(); msg.ToDouble( &dtmp ); // A -50% margin ratio means no paste on a pad, the ratio must be >= -50% if( dtmp < -50.0 ) dtmp = -50.0; // A margin ratio is always <= 0 // 0 means use full pad copper area if( dtmp > 0.0 ) dtmp = 0.0; aPad->SetLocalSolderPasteMarginRatio( dtmp / 100 ); switch( m_ZoneConnectionChoice->GetSelection() ) { default: case 0: aPad->SetZoneConnection( PAD_ZONE_CONN_INHERITED ); break; case 1: aPad->SetZoneConnection( PAD_ZONE_CONN_FULL ); break; case 2: aPad->SetZoneConnection( PAD_ZONE_CONN_THERMAL ); break; case 3: aPad->SetZoneConnection( PAD_ZONE_CONN_NONE ); break; } // Read pad position: x = ValueFromTextCtrl( *m_PadPosition_X_Ctrl ); y = ValueFromTextCtrl( *m_PadPosition_Y_Ctrl ); aPad->SetPosition( wxPoint( x, y ) ); aPad->SetPos0( wxPoint( x, y ) ); // Read pad drill: x = ValueFromTextCtrl( *m_PadDrill_X_Ctrl ); y = ValueFromTextCtrl( *m_PadDrill_Y_Ctrl ); if( m_DrillShapeCtrl->GetSelection() == 0 ) { aPad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE ); y = x; } else aPad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG ); aPad->SetDrillSize( wxSize( x, y ) ); // Read pad shape size: x = ValueFromTextCtrl( *m_ShapeSize_X_Ctrl ); y = ValueFromTextCtrl( *m_ShapeSize_Y_Ctrl ); if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) y = x; aPad->SetSize( wxSize( x, y ) ); // Read pad length die aPad->SetPadToDieLength( ValueFromTextCtrl( *m_LengthPadToDieCtrl ) ); // For a trapezoid, test delta value (be sure delta is not too large for pad size) // remember DeltaSize.x is the Y size variation bool error = false; if( aPad->GetShape() == PAD_SHAPE_TRAPEZOID ) { wxSize delta; // For a trapezoid, only one of delta.x or delta.y is not 0, depending on // the direction. if( m_trapDeltaDirChoice->GetSelection() == 0 ) delta.x = ValueFromTextCtrl( *m_ShapeDelta_Ctrl ); else delta.y = ValueFromTextCtrl( *m_ShapeDelta_Ctrl ); if( delta.x < 0 && delta.x <= -aPad->GetSize().y ) { delta.x = -aPad->GetSize().y + 2; error = true; } if( delta.x > 0 && delta.x >= aPad->GetSize().y ) { delta.x = aPad->GetSize().y - 2; error = true; } if( delta.y < 0 && delta.y <= -aPad->GetSize().x ) { delta.y = -aPad->GetSize().x + 2; error = true; } if( delta.y > 0 && delta.y >= aPad->GetSize().x ) { delta.y = aPad->GetSize().x - 2; error = true; } aPad->SetDelta( delta ); } // Read pad shape offset: x = ValueFromTextCtrl( *m_ShapeOffset_X_Ctrl ); y = ValueFromTextCtrl( *m_ShapeOffset_Y_Ctrl ); aPad->SetOffset( wxPoint( x, y ) ); aPad->SetOrientation( m_OrientValue * 10.0 ); msg = m_PadNumCtrl->GetValue().Left( 4 ); aPad->SetPadName( msg ); // Check if user has set an existing net name const NETINFO_ITEM* netinfo = m_board->FindNet( m_PadNetNameCtrl->GetValue() ); if( netinfo != NULL ) aPad->SetNetCode( netinfo->GetNet() ); else aPad->SetNetCode( NETINFO_LIST::UNCONNECTED ); // Clear some values, according to the pad type and shape switch( aPad->GetShape() ) { case PAD_SHAPE_CIRCLE: aPad->SetOffset( wxPoint( 0, 0 ) ); aPad->SetDelta( wxSize( 0, 0 ) ); x = aPad->GetSize().x; aPad->SetSize( wxSize( x, x ) ); break; case PAD_SHAPE_RECT: aPad->SetDelta( wxSize( 0, 0 ) ); break; case PAD_SHAPE_OVAL: aPad->SetDelta( wxSize( 0, 0 ) ); break; case PAD_SHAPE_TRAPEZOID: break; case PAD_SHAPE_ROUNDRECT: aPad->SetDelta( wxSize( 0, 0 ) ); break; default: ; } switch( aPad->GetAttribute() ) { case PAD_ATTRIB_STANDARD: break; case PAD_ATTRIB_CONN: case PAD_ATTRIB_SMD: // SMD and PAD_ATTRIB_CONN has no hole. // basically, SMD and PAD_ATTRIB_CONN are same type of pads // PAD_ATTRIB_CONN has just a default non technical layers that differs from SMD // and are intended to be used in virtual edge board connectors // However we can accept a non null offset, // mainly to allow complex pads build from a set of basic pad shapes aPad->SetDrillSize( wxSize( 0, 0 ) ); break; case PAD_ATTRIB_HOLE_NOT_PLATED: // Mechanical purpose only: // no offset, no net name, no pad name allowed aPad->SetOffset( wxPoint( 0, 0 ) ); aPad->SetPadName( wxEmptyString ); aPad->SetNetCode( NETINFO_LIST::UNCONNECTED ); break; default: DisplayError( NULL, wxT( "Error: unknown pad type" ) ); break; } if( aPad->GetShape() == PAD_SHAPE_ROUNDRECT ) { wxString value = m_tcCornerSizeRatio->GetValue(); double rrRadiusRatioPercent; if( value.ToDouble( &rrRadiusRatioPercent ) ) aPad->SetRoundRectRadiusRatio( rrRadiusRatioPercent / 100.0 ); } LSET padLayerMask; switch( m_rbCopperLayersSel->GetSelection() ) { case 0: padLayerMask.set( F_Cu ); break; case 1: padLayerMask.set( B_Cu ); break; case 2: padLayerMask |= LSET::AllCuMask(); break; case 3: // No copper layers break; } if( m_PadLayerAdhCmp->GetValue() ) padLayerMask.set( F_Adhes ); if( m_PadLayerAdhCu->GetValue() ) padLayerMask.set( B_Adhes ); if( m_PadLayerPateCmp->GetValue() ) padLayerMask.set( F_Paste ); if( m_PadLayerPateCu->GetValue() ) padLayerMask.set( B_Paste ); if( m_PadLayerSilkCmp->GetValue() ) padLayerMask.set( F_SilkS ); if( m_PadLayerSilkCu->GetValue() ) padLayerMask.set( B_SilkS ); if( m_PadLayerMaskCmp->GetValue() ) padLayerMask.set( F_Mask ); if( m_PadLayerMaskCu->GetValue() ) padLayerMask.set( B_Mask ); if( m_PadLayerECO1->GetValue() ) padLayerMask.set( Eco1_User ); if( m_PadLayerECO2->GetValue() ) padLayerMask.set( Eco2_User ); if( m_PadLayerDraft->GetValue() ) padLayerMask.set( Dwgs_User ); aPad->SetLayerSet( padLayerMask ); return error; }
//----------------------------------------------------------// // CPacket::Serialize //----------------------------------------------------------// CPacket::Error::Enum CPacket::Serialize(CPacketSerializer& serializer) { if (ISerializer::Mode::Serializing == serializer.GetMode()) { //-- Serializing m_nVersion = Version::Current; if (IS_ZERO(serializer.SerializeU8(m_nVersion, 'pktV'))) { return Error::Serializer; } //-- Serializer must have at least the size of the header in bytes free to proceed size_t nUnusedSize = serializer.GetSize() - serializer.GetOffset(); if (nUnusedSize < GetHeaderSize()) { //-- Not enough bytes in serializer. return Error::Serializer; } //-- Version::V1 if ( IS_ZERO(serializer.SerializeU8(m_HeaderV1.m_nFlags, 'flgs')) || IS_ZERO(serializer.SerializeU16(m_HeaderV1.m_nMessages, 'mess')) ) { return Error::Serializer; } if (IS_TRUE(IsEncrypted())) { size_t nEncodedSize = SysString::Base64EncodedSize(m_DataBuffer.UsedSize()); if (IS_ZERO(nEncodedSize)) { //-- Failed. //-- Something went wrong with the Encode. return Error::EncryptionFailed; } m_HeaderV1.m_nDataSize = nEncodedSize; if (IS_ZERO(serializer.SerializeU16(m_HeaderV1.m_nDataSize, 'size'))) { return Error::Serializer; } //-- We need a spare byte for null terminating the encoded base64 string. //-- This is blegh! //-- Test for unused space in serializer. size_t nUnusedSize = serializer.GetSize() - serializer.GetOffset(); if (nUnusedSize < ((size_t)m_HeaderV1.m_nDataSize + 1)) { //-- Not enough bytes in serializer. return Error::Serializer; } //-- Notice we do not include the extra byte when we reserve space. u8* pReserved = serializer.SerializeReserve(m_HeaderV1.m_nDataSize); if (IS_NULL_PTR(pReserved)) { //-- Failed. return Error::Serializer; } //-- Valid encryption key? if (SysString::INVALID_KEY == m_Key) { return Error::EncryptionFailed; } //-- NOTE: this will actually put a null terminator beyond the end //-- of the pReserved block! But should be ok because we checked //-- if there was room enough in the unused size of the serializer //-- for it. //-- Whatever gets serialized next will overwrite the null terminator, //-- which is ok. nEncodedSize = SysString::KeyEncode( (s8*)pReserved, m_HeaderV1.m_nDataSize + 1, m_DataBuffer.Buffer(), m_DataBuffer.UsedSize(), m_Key); if (IS_ZERO(nEncodedSize)) { //-- Failed. //-- Something went wrong with the Encode. return Error::EncryptionFailed; } if (IS_NULL_PTR(m_DataBuffer.StripHead(NULL, m_DataBuffer.UsedSize()))) { //-- Failed. //-- DataBuffer wasn't full enough return Error::DataBufferEmpty; } } else { //-- Write directly into serializer. m_HeaderV1.m_nDataSize = m_DataBuffer.UsedSize(); if (IS_ZERO(serializer.SerializeU16(m_HeaderV1.m_nDataSize, 'size'))) { return Error::Serializer; } u8* pReserved = serializer.SerializeReserve(m_HeaderV1.m_nDataSize); if (IS_NULL_PTR(pReserved)) { //-- Failed. return Error::Serializer; } if (IS_NULL_PTR(SysMemory::Memcpy(pReserved, m_HeaderV1.m_nDataSize, m_DataBuffer.Buffer(), m_HeaderV1.m_nDataSize))) { //-- Failed. return Error::CopyFailed; } if (IS_NULL_PTR(m_DataBuffer.StripHead(NULL, m_HeaderV1.m_nDataSize))) { //-- Failed. //-- DataBuffer wasn't full enough return Error::DataBufferEmpty; } } //-- DataBuffer should now be empty. assert(IS_ZERO(m_DataBuffer.UsedSize())); assert(m_HeaderV1.m_nMessages > 0); assert(m_HeaderV1.m_nDataSize > 0); //-- End. } else { //-- Deserializing. SysMemory::Memclear(&m_HeaderV1, sizeof(m_HeaderV1)); m_DataBuffer.Clear(); //-- Read version number. if (IS_ZERO(serializer.SerializeU8(m_nVersion, 'pktV'))) { //-- Failed to read version number. return Error::Serializer; } //-- Serializer must be at least the size of the header in bytes to proceed size_t nUnreadSize = serializer.GetSize() - serializer.GetOffset(); if (nUnreadSize < GetHeaderSize()) { //-- Not enough bytes in serializer. return Error::Serializer; } //-- Read the header switch (m_nVersion) { case Version::V1: { if ( IS_ZERO(serializer.SerializeU8(m_HeaderV1.m_nFlags, 'flgs')) || IS_ZERO(serializer.SerializeU16(m_HeaderV1.m_nMessages, 'mess')) || IS_ZERO(serializer.SerializeU16(m_HeaderV1.m_nDataSize, 'size')) ) { return Error::Serializer; } if (Version::Unknown == Validate()) { return Error::ProtocolMismatch; } u8* pDataSrc = serializer.SerializeReserve(m_HeaderV1.m_nDataSize); if (IS_NULL_PTR(pDataSrc)) { //-- Failed. return Error::Serializer; } //-- Is packet encrypted? if (IS_TRUE(IsEncrypted())) { //-- Decrypt packet payload data to DataBuffer size_t nDecodedSize = SysString::Base64DecodedSize((const s8*)pDataSrc, m_HeaderV1.m_nDataSize); if (IS_ZERO(nDecodedSize)) { //-- Failed. //-- Something went wrong with the Decode. return Error::EncryptionFailed; } assert(m_DataBuffer.Size() >= nDecodedSize); u8* pDataDest = m_DataBuffer.InsTail(NULL, nDecodedSize); if (IS_NULL_PTR(pDataDest)) { //-- Failed. //-- DataBuffer is too full. return Error::DataBufferFull; } //-- Valid encryption key? if (SysString::INVALID_KEY == m_Key) { return Error::EncryptionFailed; } nDecodedSize = SysString::KeyDecode( pDataDest, nDecodedSize, (const s8*)pDataSrc, m_HeaderV1.m_nDataSize, m_Key); if (IS_ZERO(nDecodedSize)) { //-- Failed. //-- Something went wrong with the Decode. return Error::EncryptionFailed; } } else { //-- Read directly into buffer. assert(m_DataBuffer.Size() >= m_HeaderV1.m_nDataSize); if (IS_NULL_PTR(m_DataBuffer.InsTail(pDataSrc, m_HeaderV1.m_nDataSize))) { //-- Failed. //-- DataBuffer is too full. return Error::DataBufferFull; } } //-- DataBuffer should now have exactly m_HeaderV1.m_nMessages inside it. //-- End. } break; default: { //-- Unexpected version return Error::UnknownVersion; } break; } } return Error::Ok; }