void StocksPrefs::serialize(Serializer& ser) { ser (currentPortfolio) (downloadedPortfolio); uint_t size = portfolios_.size(); ser(size); for (uint_t i = size; i < portfolios_.size(); ++i) delete portfolios_[i]; portfolios_.resize(size); for (uint_t i = 0; i < size; ++i) { if (Serializer::directionInput == ser.direction()) { if (NULL == portfolios_[i] && NULL == (portfolios_[i] = new_nt StocksPortfolio())) { portfolios_.resize(i); ErrThrow(memErrNotEnoughSpace); } } ser(*portfolios_[i]); } }
Boolean SaveFlightDialogHandleEvent(EventPtr event) { Boolean handled = false; Boolean savedOk = false; char *inputName; switch (PFEventGetType(event)) { case frmOpenEvent: InitDialog(); GUIFormDraw(); handled = true; break; case ctlSelectEvent: switch (PFEventGetControlSelectID(event)) { case SaveFlightOKButton: inputName = GUIFieldGetText(SaveFlightFileNameField); if (inputName && StrLen(inputName)) { savedOk = FlightDBSaveFlight(GUIFieldGetText(SaveFlightFileNameField), FlightPlan, FpStackPeek(FlightPlanStackB, 0), false); if (!savedOk && GUIAlertShow(FlightExistsAlert) == 0) { savedOk = FlightDBSaveFlight(GUIFieldGetText(SaveFlightFileNameField), FlightPlan, FpStackPeek(FlightPlanStackB,0), true); if (!savedOk) ErrThrow(1966); } } if (savedOk) { StrNCopy(Preferences.FlightPlanName, inputName, sizeof(Preferences.FlightPlanName)); GUIFormReturn(); } handled = true; break; case SaveFlightCancelButton: handled = true; GUIFormReturn(); break; } break; default: break; } return handled; }
/* Populate document list with records */ static void UpdateDocList( void ) /* THROWS */ { /* no automatic update if user has selected to handle it manually or if we have a low power situation */ if ( Prefs()->syncPolicy == SYNC_MANUAL || ! HasEnoughPower() ) return; SpeedFaster(); /* create list for documents that have been deleted since the last session */ CreateRemoveList(); ErrTry { /* find all Plucker documents in RAM */ EnumerateRAM(); /* ... and on mounted external cards */ if ( Prefs()->syncPolicy != SYNC_IGNORE_CARD ) { #ifdef SUPPORT_VFS_FONTS if ( ! ScannedVFSFonts() ) { EnumerateCards( ENUMERATECARD_DOCS | ENUMERATECARD_FONTS ); PostprocessVFSFonts(); } else #endif { EnumerateCards( ENUMERATECARD_DOCS ); } } /* clean up */ DeactivateDocuments(); DmInsertionSort( plkrDocList, CompareDocumentNames, 0 ); } ErrCatch( err ) { ReleaseDeactivateList(); ErrThrow( err ); } ErrEndCatch SpeedRestore(); }
void StocksPortfolio::serialize(Serializer& ser, ulong_t version) { ser.text(name_); if (1 == version) { char_t* value = NULL; ser.text(value); free(value); } uint_t size = entries_.size(); ser(size); for (uint_t i = size; i < entries_.size(); ++i) delete entries_[i]; entries_.resize(size); for (uint_t i = 0; i < size; ++i) { if (Serializer::directionInput == ser.direction()) { if (NULL == entries_[i] && NULL == (entries_[i] = new_nt Entry())) { entries_.resize(i); ErrThrow(memErrNotEnoughSpace); } } Entry& e = *entries_[i]; ser.text(e.symbol); ser(e.quantity); if (version > 1) { ser(e.change); ser(e.percentChange); ser(e.trade); ser.narrow(e.url); ser.text(e.data); uint_t s = e.status; ser(s); e.status = StocksEntry::Status(s); } } }
/* Create database for list of documents */ static void CreateDocList( void ) /* THROWS */ { UInt16 cardNo; Err err; LocalID dbID; UInt16 version; /* list is always put on first card in RAM */ cardNo = 0; err = errNone; err = DmCreateDatabase( cardNo, PlkrDocListName, ViewerAppID, PlkrDocListType, false ); THROW_IF( err != errNone, memErrNotEnoughSpace ); dbID = DmFindDatabase( cardNo, PlkrDocListName ); version = PlkrDocListVersion; err = DmSetDatabaseInfo( cardNo, dbID, NULL, NULL, &version, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); plkrDocList = DmOpenDatabaseByTypeCreator( PlkrDocListType, ViewerAppID, dmModeReadWrite ); ErrTry { InitPlkrAppInfo( plkrDocList ); } ErrCatch( UNUSED_PARAM( err ) ) { LocalID dbID; DmOpenDatabaseInfo( plkrDocList, &dbID, NULL, NULL, &cardNo, NULL ); CloseDatabase( plkrDocList ); DmDeleteDatabase( cardNo, dbID ); MSG( "Couldn't initialize Plkr document list [ appInfo ]\n" ); ErrThrow( memErrNotEnoughSpace ); } ErrEndCatch }
static AirspaceType *ImportRecord(PFFileRef f, Int16 *lat1, Int16 *lon1, Int16 *lat3, Int16 *lon3, void (*cb)(const char *)) { char line[256], name[256]; char *description = PFMalloc(4096); char *segStr = PFMalloc(2400); Int16 segCount; AirspaceType *as = PFMalloc(2400+2400*sizeof(LineSegmentType)); void *segStart = PFMalloc(2400*sizeof(LineSegmentType)); void *segPtr = segStart; void *writePtr; double blat1, blon1, blat2, blon2; LOGENTRY; ModErrThrowIf(!description); ModErrThrowIf(!segStr); ModErrThrowIf(!as); ModErrThrowIf(!segStart); /* * type & class: * * A-G = class A to G * * S[ADMPRTW]= Special Use (SUAS) * * W[LHB] = Airway, (L)ow level, (H)igh level or Both * * O= Other * */ if (!PFReadLine(f,line)) { PFMemFree(as); PFMemFree(description); PFMemFree(segStart); PFMemFree(segStr); LOGEXIT; return NULL; } switch (line[0]) { case 'A': as->type = asTypeClassA; break; case 'B': as->type = asTypeClassB;break; case 'C': as->type = asTypeClassC;break; case 'D': as->type = asTypeClassD;break; case 'E': as->type = asTypeClassE;break; case 'F': as->type = asTypeClassF;break; case 'G': as->type = asTypeClassG;break; case 'S': switch (line[1]) { case 'A': as->type = suasAlert; break; case 'D': as->type = suasDanger; break; case 'M': as->type = suasMoa; break; case 'P': as->type = suasProhibited; break; case 'R': as->type = suasRestricted; break; case 'T': as->type = suasTra; break; case 'W': as->type = suasWarning; break; } as->type |= asTypeSUAS; break; case 'W': switch(line[1]) { case 'L': as->type = asTypeLowAirway; break; case 'H': as->type = asTypeHighAirway; break; case 'B': as->type = asTypeHighAirway | asTypeLowAirway; break; default:ErrThrow(113); break; } break; case 'O': as->type = asTypeOther; break; default: ErrThrow(114); break; } LOGINT16(as->type); /* * name * */ PFReadLine(f, line); StrCopy(name, line); (*cb)(name); /* * description * */ *description = 0; while (line[0] != '-') { StrCat(description, line); StrCat(description, "\n"); PFReadLine(f, line); LOGSTR(line); } /* * frequency or RNP * */ PFReadLine(f,line); if (as->type & asTypeAirway) { as->extra = StrAToI(line); } else { as->extra = (StrAToI(line)*256+StrAToI(&line[4])); } LOGINT16(as->extra); /* * lower & upper altitude * */ PFReadLine(f,line); ImportAltitude(line, &as->lowerAltRef, &as->lowerAlt); PFReadLine(f,line); ImportAltitude(line, &as->upperAltRef, &as->upperAlt); LOGINT16(as->lowerAlt); LOGINT16(as->upperAlt); /* * boundary segments follow: * * L = Line: * * L<lat> <lon> * * A = Arc: * * A[LR]<lat2> <lon2> <lat3> <lon3> <lat1> <lon1> * * (L=left arc, R=right arc) * * (point 1 is centre, 2 and 3 are start and end points) * * C = Circle: * * C<lat> <lon> <radius> * * segStr is built and the bounding limits of the airspace (blat1 etc) * are updated as the segments are read and processed * */ blat1 = -PI/2; blon1 = -PI; blat2 = PI/2; blon2 = PI; segCount = 0; PFReadLine(f,line); while (line[0] != 'X') { const char *s = line+1; if (line[0] == 'L') { LineSegmentType l; double lat, lon; lat = StrToDouble(s); l.lat = DEG_TO_INT32(lat); SKIP_FIELD(s); lon = 0-StrToDouble(s); l.lon = DEG_TO_INT32(lon); //LOGINT32(l.lat); LOGINT32(l.lon); segStr[segCount] = 'l'; *(LineSegmentType*)segPtr = l; segPtr += sizeof(LineSegmentType); blat1 = MAX(blat1, DEG_TO_RAD(lat)); blon1 = MAX(blon1, DEG_TO_RAD(lon)); blat2 = MIN(blat2, DEG_TO_RAD(lat)); blon2 = MIN(blon2, DEG_TO_RAD(lon)); } else if (line[0] == 'A') { double lat1, lon1; double lat2, lon2; double lat3, lon3; double radius,bearing; ArcSegmentType ar; s+=1; /* * end points * */ lat2 = DEG_TO_RAD(StrToDouble(s)); SKIP_FIELD(s); lon2 = 0-DEG_TO_RAD(StrToDouble(s)); SKIP_FIELD(s); lat3 = DEG_TO_RAD(StrToDouble(s)); SKIP_FIELD(s); lon3 = 0-DEG_TO_RAD(StrToDouble(s)); /* * centre * */ SKIP_FIELD(s); lat1 = DEG_TO_RAD(StrToDouble(s)); SKIP_FIELD(s); lon1 = 0-DEG_TO_RAD(StrToDouble(s)); ar.lat = RAD_TO_INT32(lat1); ar.lon = RAD_TO_INT32(lon1); /* * note to self: * * Because 0 < bearing < 2*PI (check AvCalcs), * RAD_TO_INT16(bearing) can return under/overflow Int16 but * luckily it doesn't matter - only under PalmOS though! Under * CygWin it definetely needs handling. * * During the porting process, this should be addressed * */ bearing = AvCalcGreatCircleCourse(lat1, lon1, lat2, lon2, &radius); ar.radius = RAD_TO_INT32(radius); ar.start = RAD_TO_INT16(bearing); bearing = AvCalcGreatCircleCourse(lat1, lon1, lat3, lon3, &radius); ar.end = RAD_TO_INT16(bearing); if (line[1] == 'L') ar.radius = -ar.radius; //LOGINT32(ar.radius); //LOGINT16(ar.start); //LOGINT16(ar.end); segStr[segCount] = 'a'; *(ArcSegmentType*)segPtr = ar; segPtr += sizeof(ArcSegmentType); /* * assume arc is a complete circle, and calculate * bounding box accordingly * * latitude limits are easy - just add the * radian-radius, and limit the max to +-90 degrees * */ blat1 = MAX(blat1, MIN(PI/2, lat1+radius)); blat2 = MIN(blat2, MAX(-PI/2,lat1-radius)); /* * longitude is more complicated, as it needs to wrap * around. * * scale the radius according to our latitude * * remember west is +ve!!! * * Wrap around at 180deg W/E * */ radius /= cos(lat1); lon1 += radius; if (lon1 > PI) lon1 -= 2*PI; blon1 = MAX(blon1, lon1); blon2 = MIN(blon2, lon1); lon1 -= 2*radius; if (lon1 < -PI) lon1 += 2*PI; blon1 = MAX(blon1, lon1); blon2 = MIN(blon2, lon1); } else if (line[0] == 'C') { double lat1, lon1; double radius; ArcSegmentType ar; /* * centre * */ lat1 = DEG_TO_RAD(StrToDouble(s)); SKIP_FIELD(s); lon1 = 0-DEG_TO_RAD(StrToDouble(s)); ar.lat = RAD_TO_INT32(lat1); ar.lon = RAD_TO_INT32(lon1); /* * radius in nm * */ SKIP_FIELD(s); radius = NM_TO_RAD(StrToDouble(s)); ar.radius = RAD_TO_INT32(radius); ar.start = 0; ar.end = 0; //LOGINT32(ar.lat);LOGINT32(ar.lon); //LOGINT32(ar.radius); segStr[segCount] = 'a'; *(ArcSegmentType*)segPtr = ar; segPtr += sizeof(ArcSegmentType); /* * latitude limits are easy - just add the * radian-radius, and limit the max to +-90 degrees * */ blat1 = MAX(blat1, MIN(PI/2, lat1+radius)); blat2 = MIN(blat2, MAX(-PI/2,lat1-radius)); /* * longitude is more complicated, as it needs to wrap * around. * * scale the radius according to our latitude * * remember west is +ve!!! * * Wrap around at 180deg W/E * */ radius /= cos(lat1); lon1 += radius; if (lon1 > PI) lon1 -= 2*PI; blon1 = MAX(blon1, lon1); blon2 = MIN(blon2, lon1); lon1 -= 2*radius; if (lon1 < -PI) lon1 += 2*PI; blon1 = MAX(blon1, lon1); blon2 = MIN(blon2, lon1); } segCount++; PFReadLine(f,line); } segStr[segCount] = 0; LOGINT16(segPtr - segStart); /* * adjust length of strings so that the segment records * start on an even byte boundary * */ if ( (segCount+1 + StrLen(description) + 1) & 1 ) { LOGTAG("Adjusting length"); StrCat(description,"\n"); } /* * add the segment string, name, auth and segment records to the * airspace record * */ LOGLINE; writePtr = (void*)&as->segmentCode; PFMemMove(writePtr, segStr, segCount+1); writePtr += segCount+1; PFMemMove(writePtr, description, StrLen(description)+1); writePtr += StrLen(description)+1; PFMemMove(writePtr, segStart, segPtr - segStart); writePtr += segPtr - segStart; LOGSTR(GetStringFromList(as->segmentCode,1)); PFMallocResize(as, writePtr-(void*)as); LOGINT16(PFMallocSize(as)); /* * adjust the longitude limits if the span is > 180 degrees by * swapping lon1 and lon2 around * */ if (fabs(blon1 - blon2) > PI) { double tmp = blon1; blon1 = blon2; blon2 = tmp; } *lat1 = RAD_TO_INT16(blat1); *lon1 = RAD_TO_INT16(blon1); *lat3 = RAD_TO_INT16(blat2); *lon3 = RAD_TO_INT16(blon2); PFMemFree(description); PFMemFree(segStart); PFMemFree(segStr); LOGEXIT; return as; }
void ArsLexis::handleBadAlloc() { ErrThrow(memErrNotEnoughSpace); }
void std::__msl_error(const char* str) { ErrFatalDisplay(str); ErrThrow(sysErrParamErr); }