/// <summary> /// <list type="number"> /// <item>Set output type of PrologueI.</item> /// <item>Load parameters</item> /// </list> /// </summary> void Builder::SetUpMethodBody(Function& fun, MethodDef& method_def) { auto const pPrologueI = fun.GetStartBB()->GetFirstI(); auto const pRefI = pPrologueI->GetNext(); auto const pBB = pPrologueI->GetBBlock(); auto& v1 = *pPrologueI->GetVd(); ValuesTypeBuilder tybuilder( method_def.IsStatic() ? method_def.CountParams() : method_def.CountParams() + 1); auto nth = 0; // "this" parameter. if (!method_def.IsStatic()) { tybuilder.Append(method_def.owner_class_def().GetClass()); nth++; } foreach (MethodDef::EnumParam, oEnum, method_def) { auto const pParamDef = oEnum.Get(); auto& var = pParamDef->GetVariable(); auto& varty = var.GetTy(); tybuilder.Append(varty); DEBUG_FORMAT("%s %s", varty, var); auto& cell_class = Ty_ClosedCell->Construct(varty); //auto& r2 = *NewOutput(varty).StaticCast<Register>(); auto& r2 = *NewOutput(varty).StaticCast<Register>(); r2.SetVariable(var); auto const pSelectI = new(zone()) SelectI(varty, r2, v1, nth); pSelectI->SetSourceInfo(pParamDef->GetSourceInfo()); pBB->InsertBeforeI(*pSelectI, pRefI); auto& r3 = NewRegister(); auto& vardef_inst = *new(zone()) VarDefI(cell_class, r3, var, r2); vardef_inst.set_source_info(pParamDef->source_info()); pBB->InsertBeforeI(vardef_inst, pRefI); ++nth; }
// // createZone // void BSPScene::createZone( shared_ptr<Geometry> geometry, unsigned int uiMaximumDepth, unsigned int uiMinimumTriCount ) { // Constructs a BSP given the geometry // TODO: Worry about the textures/materials for the BSP // This creates a new zone with the given geometry. shared_ptr<Zone> zone( new Zone( getNextZoneID(), geometry, uiMaximumDepth, uiMinimumTriCount ) ); // Adds the zone to our collection of zones to render addZone( zone ); }
const Register& Builder::EmitI(Op const opcode, const Type& outy, const Operand& src1, const Operand& src2) { auto& inst = Instruction::New(zone(), opcode); auto& out = *NewOutput(outy).StaticCast<Register>(); inst.set_output(out); inst.set_output_type(outy); inst.AppendOperand(src1); inst.AppendOperand(src2); EmitI(inst); return out; }
void Foam::overlapGgiPolyPatch::calcLocalParallel() const { // Calculate patch-to-zone addressing if (localParallelPtr_) { FatalErrorIn("void overlapGgiPolyPatch::calcLocalParallel() const") << "Local parallel switch already calculated" << abort(FatalError); } // If running in serial, all GGIs are local parallel // HJ, 1/Jun/2011 localParallelPtr_ = new bool(false); bool& emptyOrComplete = *localParallelPtr_; // If running in serial, all GGIs are expanded to zone size. // This happens on decomposition and reconstruction where // size and shadow size may be zero, but zone size may not // HJ, 1/Jun/2011 if (!Pstream::parRun()) { emptyOrComplete = false; } else { // Calculate localisation on master and shadow emptyOrComplete = ( zone().size() == size() && shadow().zone().size() == shadow().size() ) || (size() == 0 && shadow().size() == 0); reduce(emptyOrComplete, andOp<bool>()); } if (debug && Pstream::parRun()) { Info<< "Overlap GGI patch Master: " << name() << " Slave: " << shadowName() << " is "; if (emptyOrComplete) { Info<< "local parallel" << endl; } else { Info<< "split between multiple processors" << endl; } } }
int PollardRho(verylong zalpha, verylong zbeta, verylong zn, verylong zp, verylong *zx) { long i = 2, j; static verylong za0 = 0, za1 = 0, za2 = 0, za3 = 0; static verylong zb0 = 0, zb1 = 0, zb2 = 0, zb3 = 0; static verylong zx0 = 0, zx1 = 0, zx2 = 0, zx3 = 0; static verylong zr = 0, zri = 0; zone(&zx0); zzero(&za0); zzero(&zb0); zfi(zalpha, zbeta, zp, zx0, &zx1); zai(za0, zn, zx0, &za1); zbi(zb0, zn, zx0, &zb1); zfi(zalpha, zbeta, zp, zx1, &zx2); zai(za1, zn, zx1, &za2); zbi(zb1, zn, zx1, &zb2); zcopy(za1, &za0); zcopy(zb1, &zb0); zcopy(zx1, &zx0); for (;;) { zfi(zalpha, zbeta, zp, zx0, &zx1); zai(za0, zn, zx0, &za1); zbi(zb0, zn, zx0, &zb1); zcopy(za1, &za2); zcopy(zb1, &zb2); zcopy(zx1, &zx2); i++; for (j = 0; j < i; j++) { zfi(zalpha, zbeta, zp, zx2, &zx3); zai(za2, zn, zx2, &za3); zbi(zb2, zn, zx2, &zb3); zcopy(za3, &za2); zcopy(zb3, &zb2); zcopy(zx3, &zx2); } if (zcompare(zx1, zx3) == 0) { zsubmod(zb1, zb3, zn, &zr); if (zscompare(zr, 0) == 0) return 0; zinvmod(zr, zn, &zri); zsub(za3, za1, &za0); zmulmod(za0, zri, zn, zx); return 1; } zcopy(za1, &za0); zcopy(zb1, &zb0); zcopy(zx1, &zx0); } }
// Exporting Event data to map. Using the same // encoding as ODateBookAccessBackend_xml does.. // Thus, we could remove the stuff there and use this // for it and for all other places.. // Encoding should happen at one place, only ! (eilers) QMap<int, QString> OEvent::toMap()const { QMap<int, QString> retMap; retMap.insert( OEvent::FUid, QString::number( uid() ) ); retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) )); retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) ); retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) ); retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" ); OPimAlarm alarm = notifiers().alarms()[0]; retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" ); OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OTimeZone::utc() ) ) ) ); retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OTimeZone::utc() ) ) ) ); retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) ); retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); if( parent() ) retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); if( children().count() ){ QArray<int> childr = children(); QString buf; for ( uint i = 0; i < childr.count(); i++ ) { if ( i != 0 ) buf += " "; buf += QString::number( childr[i] ); } retMap.insert( OEvent::FRecChildren, buf ); } // Add recurrence stuff if( hasRecurrence() ){ ORecur recur = recurrence(); QMap<int, QString> recFields = recur.toMap(); retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] ); retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] ); retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] ); retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] ); retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); } else { ORecur recur = recurrence(); QMap<int, QString> recFields = recur.toMap(); retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); } return retMap; }
std::ostream& operator<<(std::ostream &s, const LLViewerRegion ®ion) { s << "{ "; s << region.mHost; s << " mOriginGlobal = " << region.getOriginGlobal()<< "\n"; std::string name(region.getName()), zone(region.getZoning()); if (! name.empty()) { s << " mName = " << name << '\n'; } if (! zone.empty()) { s << " mZoning = " << zone << '\n'; } s << "}"; return s; }
MinorCollectionTracer(JSRuntime *rt, Nursery *nursery) : JSTracer(), nursery(nursery), runtime(rt), session(runtime, MinorCollecting), head(NULL), tail(&head), savedNeedsBarrier(runtime->needsBarrier()), disableStrictProxyChecking(runtime) { JS_TracerInit(this, runtime, Nursery::MinorGCCallback); eagerlyTraceWeakMaps = TraceWeakMapKeysValues; runtime->gcNumber++; runtime->setNeedsBarrier(false); for (ZonesIter zone(rt); !zone.done(); zone.next()) zone->saveNeedsBarrier(false); }
void GRIBUIDialog::OnRequest( wxCommandEvent& event ) { double lonmax=m_vp->lon_max; double lonmin=m_vp->lon_min; if( ( fabs( m_vp->lat_max ) < 90. ) && ( fabs( lonmax ) < 360. ) ) { if( lonmax < -180. ) lonmax += 360.; if( lonmax > 180. ) lonmax -= 360.; } if( ( fabs( m_vp->lat_min ) < 90. ) && ( fabs( lonmin ) < 360. ) ) { if( lonmin < -180. ) lonmin += 360.; if( lonmin > 180. ) lonmin -= 360.; } wxString zone( toSAILDOC( 1, 1, m_vp->lat_max ) + wxT(",") + toSAILDOC( 1, 2, m_vp->lat_min ) + wxT(",") + toSAILDOC( 2, 2, lonmin ) + wxT(",") + toSAILDOC( 2, 1, lonmax ) ); GribRequestSetting *req_Dialog = new GribRequestSetting( this, pPlugIn->GetRequestConfig(), zone, pPlugIn->GetMailAdresse() ); if( req_Dialog->ShowModal() == wxID_SAVE ) { req_Dialog->m_RequestConfigBase.SetChar( 2, (char) ( req_Dialog->m_pModel->GetCurrentSelection() + '0' ) ); if( req_Dialog->m_pModel->GetCurrentSelection() == 0 ) { req_Dialog->m_RequestConfigBase.SetChar( 3, (char) ( req_Dialog->m_pResolution->GetCurrentSelection() + '0' ) ); req_Dialog->m_pWaves->IsChecked() ? req_Dialog->m_RequestConfigBase.SetChar( 8, 'X' ) : req_Dialog->m_RequestConfigBase.SetChar( 8, '.' ); req_Dialog->m_pRainfall->IsChecked() ? req_Dialog->m_RequestConfigBase.SetChar( 9, 'X' ) : req_Dialog->m_RequestConfigBase.SetChar( 9, '.' ); req_Dialog->m_pCloudCover->IsChecked() ? req_Dialog->m_RequestConfigBase.SetChar( 10, 'X' ) : req_Dialog->m_RequestConfigBase.SetChar( 10, '.' ); req_Dialog->m_pAirTemp->IsChecked() ? req_Dialog->m_RequestConfigBase.SetChar( 11, 'X' ) : req_Dialog->m_RequestConfigBase.SetChar( 11, '.' ); req_Dialog->m_pSeaTemp->IsChecked() ? req_Dialog->m_RequestConfigBase.SetChar( 12, 'X' ) : req_Dialog->m_RequestConfigBase.SetChar( 12, '.' ); req_Dialog->m_pCurrent->IsChecked() ? req_Dialog->m_RequestConfigBase.SetChar( 13, 'X' ) : req_Dialog->m_RequestConfigBase.SetChar( 13, '.' ); } else if( req_Dialog->m_pModel->GetCurrentSelection() == 1 ) req_Dialog->m_RequestConfigBase.SetChar( 3, (char) ( req_Dialog->m_pResolution->GetCurrentSelection() + '0' ) ); req_Dialog->m_RequestConfigBase.SetChar( 6, 'X' ); //must be always selected req_Dialog->m_RequestConfigBase.SetChar( 7, 'X' ); req_Dialog->m_RequestConfigBase.SetChar( 4, (char) ( req_Dialog->m_pInterval->GetCurrentSelection() + '0' ) ); req_Dialog->m_RequestConfigBase.SetChar( 5, (char) ( req_Dialog->m_pTimeRange->GetCurrentSelection() + '0' ) ); pPlugIn->SetRequestConfig( req_Dialog->m_RequestConfigBase ); } req_Dialog->Destroy(); }
bool EditPanel::CommandPaste(ImageInfoPtr newValue ) { if ( mImageInfo == NULL ) { return false; } wxRect zone( mCursor, newValue->GetSize() ); ImageInfoPtr old = mImageInfo->CopyToImageInfo( zone ); if (old) { ImagePasteCommand* paste = new ImagePasteCommand(this, old->Clone(), newValue->Clone(), mCursor ); return COMMAND->Submit( paste ); } return false; }
// FIXME: Use OEvent::fromMap() which makes this obsolete.. (eilers) void ODateBookAccessBackend_XML::finalizeRecord( OEvent& ev ) { /* AllDay is alway in UTC */ if ( ev.isAllDay() ) { OTimeZone utc = OTimeZone::utc(); ev.setStartDateTime( utc.fromUTCDateTime( start ) ); ev.setEndDateTime ( utc.fromUTCDateTime( end ) ); ev.setTimeZone( "UTC"); // make sure it is really utc } else { /* to current date time */ // qWarning(" Start is %d", start ); OTimeZone zone( ev.timeZone().isEmpty() ? OTimeZone::current() : ev.timeZone() ); QDateTime date = zone.toDateTime( start ); qWarning(" Start is %s", date.toString().latin1() ); ev.setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); date = zone.toDateTime( end ); ev.setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); } if ( rec && rec->doesRecur() ) { OTimeZone utc = OTimeZone::utc(); ORecur recu( *rec ); // call copy c'tor; recu.setEndDate ( utc.fromUTCDateTime( rp_end ).date() ); recu.setCreatedDateTime( utc.fromUTCDateTime( created ) ); recu.setStart( ev.startDateTime().date() ); ev.setRecurrence( recu ); } if (alarmTime != -1 ) { QDateTime dt = ev.startDateTime().addSecs( -1*alarmTime*60 ); OPimAlarm al( snd , dt ); ev.notifiers().add( al ); } if ( m_raw.contains( ev.uid() ) || m_rep.contains( ev.uid() ) ) { qWarning("already contains assign uid"); ev.setUid( 1 ); } qWarning("addind %d %s", ev.uid(), ev.description().latin1() ); if ( ev.hasRecurrence() ) m_rep.insert( ev.uid(), ev ); else m_raw.insert( ev.uid(), ev ); }
void GRIBUIDialog::OnRequest( wxCommandEvent& event ) { double lonmax=m_vp->lon_max; double lonmin=m_vp->lon_min; if( ( fabs( m_vp->lat_max ) < 90. ) && ( fabs( lonmax ) < 360. ) ) { if( lonmax < -180. ) lonmax += 360.; if( lonmax > 180. ) lonmax -= 360.; } if( ( fabs( m_vp->lat_min ) < 90. ) && ( fabs( lonmin ) < 360. ) ) { if( lonmin < -180. ) lonmin += 360.; if( lonmin > 180. ) lonmin -= 360.; } wxString zone( toSAILDOC( 1, 1, m_vp->lat_max ) + wxT(",") + toSAILDOC( 1, 2, m_vp->lat_min ) + wxT(",") + toSAILDOC( 2, 2, lonmin ) + wxT(",") + toSAILDOC( 2, 1, lonmax ) ); ShowSendRequest( zone ); }
void WorldTime::slotSetZone() { QPushButton *sendButton = qobject_cast<QPushButton *>(sender()); if(! sendButton->isChecked()) { sendButton->setChecked(true); return; } int selButton = findCurrentButton(); QTimeZone zone( strCityTz[selButton].toLocal8Bit()); frmMap->setZone(zone); editMode(); changed = true; frmMap->selectNewZone(); setButtonAvailable(selButton); listTimes.at( selButton )->setZone( zone.id()); }
// Mouse pressed event void PlayGround::mousePressEvent( QMouseEvent *event ) { if (draggedCursor) return; QPoint position(event->x() - XMARGIN, event->y() - YMARGIN); if (!zone(position)) return; int draggedNumber = draggedObject.getNumber(); QPixmap object(objectsLayout[draggedNumber].size()); QBitmap shape(objectsLayout[draggedNumber].size()); bitBlt(&object, QPoint(0, 0), &gameboard, objectsLayout[draggedNumber], Qt::CopyROP); bitBlt(&shape, QPoint(0, 0), &masks, objectsLayout[draggedNumber], Qt::CopyROP); object.setMask(shape); draggedCursor = new QCursor(object, position.x(), position.y()); setCursor(*draggedCursor); topLevel->playSound(soundsList[draggedNumber]); }
Foam::label Foam::overlapGgiPolyPatch::zoneIndex() const { if (zoneIndex_ == -1 && zoneName_ != Foam::word::null) { // Grab zone patch index faceZoneID zone(zoneName_, boundaryMesh().mesh().faceZones()); if (!zone.active()) { FatalErrorIn("label overlapGgiPolyPatch::zoneIndex() const") << "Face zone name " << zoneName_ << " not found. Please check your GGI interface definition." << abort(FatalError); } zoneIndex_ = zone.index(); } return zoneIndex_; }
/* This function rerenders the subliminal window's entire sub_buffer. It loops * through all inferior windows, calling their 'draw_to_sub' function to get them * to draw onto its own sub_buffer. After doing this, it alerts any derived * classes's hooks. */ void window_sub::update_sub() { // If we are not capable of having our sub-buffer updated, return if (!sub_buffer || !visible() || !flag(sys_active)) return; // If we are at all clipped, clear our sub-buffer so the clipped portions don't // get filled with junk. if (flag(vis_positive_clip) || flag(vis_negative_clip)) clear_to_color(sub_buffer, 0); // Loop through all inferior windows that we are visible to us for (base_window* loop = get_parent(); loop && loop != this; loop = loop->superior()) { if (loop->visible() && loop->flag(sys_active)) { // If they are visible and active, draw themselves to us loop->draw_to_sub(this, &loop->clipped(), false); } } // Call the hook to inform it our entire surface has been drawn to! sub_changed_hook(&zone(0, 0, w(), h())); }
// This routine checks whether a poylgon can be inserted into a block such that the interior of the polygon does not at all overlap with used space // in the block. We COULD do this using boolean operations (E.g. is the intersection of the used block space and our polygon empty?) but we do NOT want // to. Why? Time to do a boolean op is a function of BOTH polygons, and in a lot of cases the block will be HUGELY complex (imagine a giant forest expanse // with lots of crap already inserted into it) and our test block will be TINY (a quad). In this case, we get better performance by doing a piece-wise per-side // test. // Side note: using the bulk locator totally violates this principle...we will probably need to replace it with a walk location strategy. // So we use the zone utility to see what we'll hit as we go along our edges. bool can_insert_into_block( Block_2& block, const Polygon_2& bounds) { // Run a bulk location on the entire block...TBD: there may be blocks where sweeping is worse than marching. // Anyway, we get a bunch of pairs of the locate point and the actual part of the arrangement we hit. vector<pair<Point_2, CGAL::Object> > pts; CGAL::locate(block, bounds.vertices_begin(), bounds.vertices_end(), back_inserter(pts)); // Quick check: if ANY of our points are inside a non empty face, we are by definition hosed. // We can see this now just from the location data. Block_2::Face_const_handle ff; for(int n = 0; n < pts.size(); ++n) if(CGAL::assign(ff,pts[n].second)) if(ff->data().usage != usage_Empty) return false; for(int n = 0; n < pts.size(); ++n) { // We are now going to go through each side and do a zone test. This will check whether it is // either running along a full area or crashing through it. int m = (n+1)%pts.size(); check_block_visitor v; v.cv = Block_2::X_monotone_curve_2(Segment_2(pts[n].first, pts[m].first)); CGAL::Arrangement_zone_2<Block_2,check_block_visitor> zone(block, &v); if(v.cv.is_directed_right()) zone.init_with_hint(v.cv,pts[n].second); else zone.init_with_hint(v.cv,pts[m].second); zone.compute_zone(); if(!v.ok) return false; } return true; }
bool NitfWrap::verifyBpf(ILeStream& in, BOX3D& bounds) { BpfHeader h; BpfDimensionList dims; LogPtr l(new Log("nitfwrap", "devnull")); h.setLog(l); if (!h.read(in)) return false; if (!h.readDimensions(in, dims)) return false; for (auto d : dims) { if (d.m_id == Dimension::Id::X) { bounds.minx = d.m_min; bounds.maxx = d.m_max; } if (d.m_id == Dimension::Id::Y) { bounds.miny = d.m_min; bounds.maxy = d.m_max; } if (d.m_id == Dimension::Id::Z) { bounds.minz = d.m_min; bounds.maxz = d.m_max; } } int32_t zone(abs(h.m_coordId)); std::string code; if (h.m_coordId > 0) code = "EPSG:326" + Utils::toString(zone); else code = "EPSG:327" + Utils::toString(zone); gdal::reprojectBounds(bounds, code, "EPSG:4326"); return true; }
void check_block(void **reference, void *block) { if (block == _block) { if (_thread) { intptr_t offset = (intptr_t)reference - (intptr_t)_thread_range.end(); agc_reference_t ref = { (vm_address_t)block, (vm_address_t)_thread_range.end(), offset }; _callback(_callback_ctx, ref); } else if (!reference) { // ??? } else { void *owner = zone()->block_start((void*)reference); if (owner) { intptr_t offset = (intptr_t)reference - (intptr_t)owner; agc_reference_t ref = { (vm_address_t)block, (vm_address_t)owner, offset }; _callback(_callback_ctx, ref); } else { agc_reference_t ref = { (vm_address_t)block, (vm_address_t)reference, 0 }; _callback(_callback_ctx, ref); } } } MemoryScanner::check_block(reference, block); }
Player * new_player(EntitySet * others, Camera * cam, InputState * is, Level world, Control * halter) { Player * player = (Player *) zone(sizeof(Player)); Entity * body = load_entity(PLAYER_PATH, player, &player_user_input_response, &player_destructor); player->body = body; player->others = others; player->cam = cam; player->is = is; player->world = world; player->health = 100; player->halter = halter; player->score = 0; player->fire = Mix_LoadWAV(FIRE_PATH); player->attack_timer = new_expirer(PLAYER_ATTACK_FREQUENCY); entity_set_speed(body, 3); entity_set_direction(body, 0, 0); register_entity(others, body); return player; }
void KSystemTimeZonesPrivate::updateTimezoneInformation(bool update) { if (!m_source) m_source = new KSystemTimeZoneSourceWindows; QStringList newZones; Q_FOREACH(const QString & tz, KSystemTimeZoneWindows::listTimeZones()) { // const std::wstring wstr = tz.toStdWString(); // const KTimeZone info = make_time_zone( wstr.c_str() ); KSystemTimeZoneWindows stz(m_source, tz); if (update) { // Update the existing collection with the new zone definition newZones += stz.name(); KTimeZone oldTz = zone(stz.name()); if (oldTz.isValid()) oldTz.updateBase(stz); // the zone previously existed, so update its definition else add(stz); // the zone didn't previously exist, so add it } else add(stz); }
int main () { Arrangement_2 arr; Segment_2 segs[N_SEGMENTS]; std::size_t zone_expected_comp[N_SEGMENTS]; int k; segs[0] = Segment_2 (Point_2 (-2, -2), Point_2 (-1, -1)); segs[1] = Segment_2 (Point_2 (-1, 1), Point_2 (1, 1)); segs[2] = Segment_2 (Point_2 (0, 0), Point_2 (3, 0)); zone_expected_comp[0] = 1; zone_expected_comp[1] = 3; zone_expected_comp[2] = 4; insert(arr, Segment_2(Point_2(0, 0), Point_2(2, 0))); insert(arr, Segment_2(Point_2(2, 0), Point_2(2, 2))); insert(arr, Segment_2(Point_2(2, 2), Point_2(0, 2))); insert(arr, Segment_2(Point_2(0, 2), Point_2(0, 0))); for (k = 0; k < N_SEGMENTS; k++) { std::list<CGAL::Object> zone_elems; zone(arr, segs[k], std::back_inserter(zone_elems)); std::size_t zone_actual_comp = zone_elems.size(); std::cout << "Segment: " << segs[k]; std::cout << " Expected: " << zone_expected_comp[k]; std::cout << " Actual: " << zone_actual_comp << std::endl; if (zone_expected_comp[k] != zone_actual_comp) return (1); } return (0); }
const KstTimezone *KstTimezones::local() { const KstTimezone *local = 0; // First try the simplest solution of checking for well-formed TZ setting. char *envZone = ::getenv("TZ"); if (envZone) { if (envZone[0] == '\0') { return m_UTC; } else if (envZone[0] == ':') { envZone++; } local = zone(envZone); } if (local) return local; // Try to match /etc/localtime against the list of zoneinfo files. QFile f; f.setName("/etc/localtime"); if (f.open(IO_ReadOnly)) { // Compute the MD5 sum of /etc/localtime. KMD5 context(""); context.reset(); context.update(f); QIODevice::Offset referenceSize = f.size(); QString referenceMd5Sum = context.hexDigest(); f.close(); if (!m_zoneinfoDir.isEmpty()) { // Compare it with each zoneinfo file. for (ZoneMap::Iterator it = m_zones->begin(); it != m_zones->end(); ++it) { KstTimezone *zone = it.data(); f.setName(m_zoneinfoDir + '/' + zone->name()); if (f.open(IO_ReadOnly)) { QIODevice::Offset candidateSize = f.size(); QString candidateMd5Sum; if (candidateSize == referenceSize) { // Only do the heavy lifting for file sizes which match. context.reset(); context.update(f); candidateMd5Sum = context.hexDigest(); } f.close(); if (candidateMd5Sum == referenceMd5Sum) { local = zone; break; } } } } } if (local) return local; // BSD support. QString fileZone; f.setName("/etc/timezone"); if (!f.open(IO_ReadOnly)) { // Solaris support using /etc/default/init. f.setName("/etc/default/init"); if (f.open(IO_ReadOnly)) { QTextStream ts(&f); ts.setEncoding(QTextStream::Latin1); // Read the last line starting "TZ=". while (!ts.atEnd()) { fileZone = ts.readLine(); if (fileZone.startsWith("TZ=")) { fileZone = fileZone.mid(3); local = zone(fileZone); } } f.close(); } } else { QTextStream ts(&f); ts.setEncoding(QTextStream::Latin1); // Read the first line. if (!ts.atEnd()) { fileZone = ts.readLine(); local = zone(fileZone); } f.close(); } if (local) return local; // None of the deterministic stuff above has worked: try a heuristic. We // try to find a pair of matching timezone abbreviations...that way, we'll // likely return a value in the user's own country. if (!m_zoneinfoDir.isEmpty()) { tzset(); AbbreviationsMatch matcher(tzname[0], tzname[1]); int bestOffset = INT_MAX; for (ZoneMap::Iterator it = m_zones->begin(); it != m_zones->end(); ++it) { KstTimezone *zone = it.data(); int candidateOffset = QABS(zone->offset(Qt::LocalTime)); if (zone->parse(matcher) && matcher.test() && (candidateOffset < bestOffset)) { bestOffset = candidateOffset; local = zone; } } } if (local) return local; return m_UTC; }
~MinorCollectionTracer() { runtime->setNeedsBarrier(savedNeedsBarrier); for (ZonesIter zone(runtime); !zone.done(); zone.next()) zone->restoreNeedsBarrier(); }
void OEvent::fromMap( const QMap<int, QString>& map ) { // We just want to set the UID if it is really stored. if ( !map[OEvent::FUid].isEmpty() ) setUid( map[OEvent::FUid].toInt() ); setCategories( idsFromString( map[OEvent::FCategories] ) ); setDescription( map[OEvent::FDescription] ); setLocation( map[OEvent::FLocation] ); if ( map[OEvent::FType] == "AllDay" ) setAllDay( true ); else setAllDay( false ); int alarmTime = -1; if( !map[OEvent::FAlarm].isEmpty() ) alarmTime = map[OEvent::FAlarm].toInt(); int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); if ( ( alarmTime != -1 ) ){ QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); OPimAlarm al( sound , dt ); notifiers().add( al ); } if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){ setTimeZone( map[OEvent::FTimeZone] ); } time_t start = (time_t) map[OEvent::FStart].toLong(); time_t end = (time_t) map[OEvent::FEnd].toLong(); /* AllDay is always in UTC */ if ( isAllDay() ) { OTimeZone utc = OTimeZone::utc(); setStartDateTime( utc.fromUTCDateTime( start ) ); setEndDateTime ( utc.fromUTCDateTime( end ) ); setTimeZone( "UTC"); // make sure it is really utc }else { /* to current date time */ // qWarning(" Start is %d", start ); OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); QDateTime date = zone.toDateTime( start ); qWarning(" Start is %s", date.toString().latin1() ); setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); date = zone.toDateTime( end ); setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); } if ( !map[OEvent::FRecParent].isEmpty() ) setParent( map[OEvent::FRecParent].toInt() ); if ( !map[OEvent::FRecChildren].isEmpty() ){ QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { addChild( (*it).toInt() ); } } // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. if( !map[OEvent::FRType].isEmpty() ){ QMap<int, QString> recFields; recFields.insert( ORecur::RType, map[OEvent::FRType] ); recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] ); recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] ); recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] ); recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] ); recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] ); recFields.insert( ORecur::Created, map[OEvent::FRCreated] ); recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] ); ORecur recur( recFields ); setRecurrence( recur ); } }
int main(int argc, char* argv[]) { terrama2::core::initializeTerraMA(); { QUrl uri; uri.setScheme("postgis"); uri.setHost(QString::fromStdString(TERRAMA2_DATABASE_HOST)); uri.setPort(std::stoi(TERRAMA2_DATABASE_PORT)); uri.setUserName(QString::fromStdString(TERRAMA2_DATABASE_USERNAME)); uri.setPassword(QString::fromStdString(TERRAMA2_DATABASE_PASSWORD)); uri.setPath(QString::fromStdString("/"+TERRAMA2_DATABASE_DBNAME)); //DataProvider information terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider(); terrama2::core::DataProviderPtr dataProviderPtr(dataProvider); dataProvider->uri = uri.url().toStdString(); dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT; dataProvider->dataProviderType = "POSTGIS"; dataProvider->active = true; //DataSeries information terrama2::core::DataSeries* dataSeries = new terrama2::core::DataSeries(); terrama2::core::DataSeriesPtr dataSeriesPtr(dataSeries); auto& semanticsManager = terrama2::core::SemanticsManager::getInstance(); dataSeries->semantics = semanticsManager.getSemantics("OCCURRENCE-postgis"); //DataSet information terrama2::core::DataSetOccurrence* dataSet = new terrama2::core::DataSetOccurrence(); dataSet->active = true; dataSet->format.emplace("table_name", "fires"); dataSet->format.emplace("timestamp_property", "data_pas"); dataSet->format.emplace("geometry_property", "geom"); dataSeries->datasetList.emplace_back(dataSet); //accessing data terrama2::core::DataAccessorOccurrencePostGis accessor(dataProviderPtr, dataSeriesPtr); //empty filter terrama2::core::Filter filter; boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone("+00")); filter.lastValue = true; std::string boundingBoxWkt = "POLYGON((-51.11 -17.74, -41.11 -17.74, -41.11 -20.83, -51.11 -20.83, -51.11 -17.74))"; te::gm::Geometry* geometry = te::gm::WKTReader::read(boundingBoxWkt.c_str()); geometry->setSRID(4326); filter.region = std::shared_ptr<te::gm::Geometry>(geometry); terrama2::core::OccurrenceSeriesPtr occurrenceSeries = accessor.getOccurrenceSeries(filter); assert(occurrenceSeries->occurrencesMap().size() == 1); auto teDataSet = (*occurrenceSeries->occurrencesMap().begin()).second.syncDataSet->dataset(); //Print column names and types (DateTime/Double) int dateColumn = -1; int geomColumn = -1; std::string names, types; for(int i = 0; i < teDataSet->getNumProperties(); ++i) { std::string name = teDataSet->getPropertyName(i); names+= name + "\t"; if(name == "data_pas") { types+= "DataTime\t"; dateColumn = i; } else if(name == "geom") { types+= "Geometry\t"; geomColumn = i; } else types+= "Int\t"; } std::cout << names << std::endl; std::cout << types << std::endl; //Print values teDataSet->moveBeforeFirst(); while(teDataSet->moveNext()) { for(int i = 0; i < teDataSet->getNumProperties(); ++i) { if(teDataSet->isNull(i)) { std::cout << "NULL"; continue; } if(i == dateColumn) { std::shared_ptr<te::dt::DateTime> dateTime = teDataSet->getDateTime(i); std::cout << dateTime->toString(); } else if(i == geomColumn) { std::cout << "<<Geometry>>"; } else { std::cout << teDataSet->getInt32(i); } std::cout << "\t"; } std::cout << std::endl; } std::cout << "\ndataset size: " << teDataSet->size() << std::endl; } terrama2::core::finalizeTerraMA(); return 0; }
bool mature_object_p() const { return zone() == MatureObjectZone; }
bool young_object_p() const { return zone() == YoungObjectZone; }
// read zone file, allowing for zones with or without end dates bool HrZones::read(QFile &file) { defaults_from_user = false; scheme.zone_default.clear(); scheme.zone_default_is_pct.clear(); scheme.zone_default_name.clear(); scheme.zone_default_desc.clear(); scheme.zone_default_trimp.clear(); scheme.nzones_default = 0; ranges.clear(); // set up possible warning dialog warning = QString(); int warning_lines = 0; const int max_warning_lines = 100; // macro to append lines to the warning #define append_to_warning(s) \ if (warning_lines < max_warning_lines) \ warning.append(s); \ else if (warning_lines == max_warning_lines) \ warning.append("...\n"); \ warning_lines ++; // read using text mode takes care of end-lines if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { err = "can't open file"; return false; } QTextStream fileStream(&file); QRegExp commentrx("\\s*#.*$"); QRegExp blankrx("^[ \t]*$"); QRegExp rangerx[] = { QRegExp("^\\s*(?:from\\s+)?" // optional "from" "((\\d\\d\\d\\d)[-/](\\d{1,2})[-/](\\d{1,2})|BEGIN)" // begin date "\\s*([,:]?\\s*(LT)\\s*=\\s*(\\d+))?" // optional {LT = integer (optional %)} "\\s*([,:]?\\s*(RestHr)\\s*=\\s*(\\d+))?" // optional {RestHr = integer (optional %)} "\\s*([,:]?\\s*(MaxHr)\\s*=\\s*(\\d+))?" // optional {MaxHr = integer (optional %)} "\\s*:?\\s*$", // optional : Qt::CaseInsensitive), QRegExp("^\\s*(?:from\\s+)?" // optional "from" "((\\d\\d\\d\\d)[-/](\\d{1,2})[-/](\\d{1,2})|BEGIN)" // begin date "\\s+(?:until|to|-)\\s+" // until "((\\d\\d\\d\\d)[-/](\\d{1,2})[-/](\\d{1,2})|END)?" // end date "\\s*:?,?\\s*((LT)\\s*=\\s*(\\d+))?" // optional {LT = integer (optional %)} "\\s*:?,?\\s*((RestHr)\\s*=\\s*(\\d+))?" // optional {RestHr = integer (optional %)} "\\s*:?,?\\s*((MaxHr)\\s*=\\s*(\\d+))?" // optional {MaxHr = integer (optional %)} "\\s*:?\\s*$", // optional : Qt::CaseInsensitive) }; QRegExp zonerx("^\\s*([^ ,][^,]*),\\s*([^ ,][^,]*),\\s*" "(\\d+)\\s*(%?)\\s*(?:,\\s*(\\d+(\\.\\d+)?)\\s*)?$", Qt::CaseInsensitive);// QRegExp zonedefaultsx("^\\s*(?:zone)?\\s*defaults?\\s*:?\\s*$", Qt::CaseInsensitive); int lineno = 0; // the current range in the file // ZoneRange *range = NULL; bool in_range = false; QDate begin = date_zero, end = date_infinity; int lt = 0; int restHr = 0; int maxHr = 0; QList<HrZoneInfo> zoneInfos; // true if zone defaults are found in the file (then we need to write them) bool zones_are_defaults = false; while (! fileStream.atEnd() ) { ++lineno; QString line = fileStream.readLine(); int pos = commentrx.indexIn(line, 0); if (pos != -1) line = line.left(pos); if (blankrx.indexIn(line, 0) == 0) goto next_line; // check for default zone range definition (may be followed by hr zone definitions) if (zonedefaultsx.indexIn(line, 0) != -1) { zones_are_defaults = true; // defaults are allowed only at the beginning of the file if (ranges.size()) { err = "HR Zone defaults must be specified at head of hr.zones file"; return false; } // only one set of defaults is allowed if (scheme.nzones_default) { err = "Only one set of zone defaults may be specified in hr.zones file"; return false; } goto next_line; } // check for range specification (may be followed by zone definitions) for (int r=0; r<2; r++) { if (rangerx[r].indexIn(line, 0) != -1) { if (in_range) { // if zones are empty, then generate them HrZoneRange range(begin, end, lt, restHr, maxHr); range.zones = zoneInfos; if (range.zones.empty()) { if (range.lt > 0) setHrZonesFromLT(range); else { err = tr("line %1: read new range without reading " "any zones for previous one").arg(lineno); file.close(); return false; } } else { qSort(range.zones); } ranges.append(range); } in_range = true; zones_are_defaults = false; zoneInfos.clear(); // process the beginning date if (rangerx[r].cap(1) == "BEGIN") begin = date_zero; else { begin = QDate(rangerx[r].cap(2).toInt(), rangerx[r].cap(3).toInt(), rangerx[r].cap(4).toInt()); } // process an end date, if any, else it is null if (rangerx[r].cap(5) == "END") end = date_infinity; else if (rangerx[r].cap(6).toInt() || rangerx[r].cap(7).toInt() || rangerx[r].cap(8).toInt()) { end = QDate(rangerx[r].cap(6).toInt(), rangerx[r].cap(7).toInt(), rangerx[r].cap(8).toInt()); } else { end = QDate(); } // set up the range, capturing LT if it's specified // range = new ZoneRange(begin, end); int nLT = (r ? 11 : 7); if (rangerx[r].numCaptures() >= (nLT)) lt = rangerx[r].cap(nLT).toInt(); else lt = 0; int nRestHr = (r ? 14 : 10); if (rangerx[r].numCaptures() >= (nRestHr)) restHr = rangerx[r].cap(nRestHr).toInt(); else restHr = 0; int nMaxHr = (r ? 17 : 13); if (rangerx[r].numCaptures() >= (nRestHr)) maxHr = rangerx[r].cap(nMaxHr).toInt(); else maxHr = 0; // bleck goto next_line; } } // check for zone definition if (zonerx.indexIn(line, 0) != -1) { if (! (in_range || zones_are_defaults)) { err = tr("line %1: read zone without " "preceeding date range").arg(lineno); file.close(); return false; } int lo = zonerx.cap(3).toInt(); double trimp = zonerx.cap(5).toDouble(); // allow for zone specified as % of LT bool lo_is_pct = false; if (zonerx.cap(4) == "%") { if (zones_are_defaults) lo_is_pct = true; else if (lt > 0) lo = int(lo * lt / 100); else { err = tr("attempt to set zone based on % of " "LT without setting LT in line number %1.\n"). arg(lineno); file.close(); return false; } } int hi = -1; // signal an undefined number double tr = zonerx.cap(5).toDouble(); if (zones_are_defaults) { scheme.nzones_default ++; scheme.zone_default_is_pct.append(lo_is_pct); scheme.zone_default.append(lo); scheme.zone_default_name.append(zonerx.cap(1)); scheme.zone_default_desc.append(zonerx.cap(2)); scheme.zone_default_trimp.append(trimp); defaults_from_user = true; } else { HrZoneInfo zone(zonerx.cap(1), zonerx.cap(2), lo, hi, tr); zoneInfos.append(zone); } } next_line: {} } if (in_range) { HrZoneRange range(begin, end, lt, restHr, maxHr); range.zones = zoneInfos; if (range.zones.empty()) { if (range.lt > 0) setHrZonesFromLT(range); else { err = tr("file ended without reading any zones for last range"); file.close(); return false; } } else { qSort(range.zones); } ranges.append(range); } file.close(); // sort the ranges qSort(ranges); // set the default zones if not in file if (!scheme.nzones_default) { // do we have a zone which is explicitly set? for (int i=0; i<ranges.count(); i++) { if (ranges[i].hrZonesSetFromLT == false) { // set the defaults using this one! scheme.nzones_default = ranges[i].zones.count(); for (int j=0; j<scheme.nzones_default; j++) { scheme.zone_default.append(((double)ranges[i].zones[j].lo / (double)ranges[i].lt) * 100.00); scheme.zone_default_is_pct.append(true); scheme.zone_default_name.append(ranges[i].zones[j].name); scheme.zone_default_desc.append(ranges[i].zones[j].desc); scheme.zone_default_trimp.append(ranges[i].zones[j].trimp); } } } // still not set then reset to defaults as usual if (!scheme.nzones_default) initializeZoneParameters(); } // resolve undefined endpoints in ranges and zones for (int nr = 0; nr < ranges.size(); nr ++) { // clean up gaps or overlaps in zone ranges if (ranges[nr].end.isNull()) ranges[nr].end = (nr < ranges.size() - 1) ? ranges[nr + 1].begin : date_infinity; else if ((nr < ranges.size() - 1) && (ranges[nr + 1].begin != ranges[nr].end)) { append_to_warning(tr("Setting end date of range %1 " "to start date of range %2.\n"). arg(nr + 1). arg(nr + 2) ); ranges[nr].end = ranges[nr + 1].begin; } else if ((nr == ranges.size() - 1) && (ranges[nr].end < QDate::currentDate())) { append_to_warning(tr("Extending final range %1 to infinite " "to include present date.\n").arg(nr + 1)); ranges[nr].end = date_infinity; } if (ranges[nr].lt <= 0) { err = tr("LT must be greater than zero in zone " "range %1 of hr.zones").arg(nr + 1); return false; } if (ranges[nr].zones.size()) { // check that the first zone starts with zero ranges[nr].zones[0].lo = 0; // resolve zone end powers for (int nz = 0; nz < ranges[nr].zones.size(); nz ++) { if (ranges[nr].zones[nz].hi == -1) ranges[nr].zones[nz].hi = (nz < ranges[nr].zones.size() - 1) ? ranges[nr].zones[nz + 1].lo : INT_MAX; else if ((nz < ranges[nr].zones.size() - 1) && (ranges[nr].zones[nz].hi != ranges[nr].zones[nz + 1].lo)) { if (abs(ranges[nr].zones[nz].hi - ranges[nr].zones[nz + 1].lo) > 4) { append_to_warning(tr("Range %1: matching top of zone %2 " "(%3) to bottom of zone %4 (%5).\n"). arg(nr + 1). arg(ranges[nr].zones[nz].name). arg(ranges[nr].zones[nz].hi). arg(ranges[nr].zones[nz + 1].name). arg(ranges[nr].zones[nz + 1].lo) ); } ranges[nr].zones[nz].hi = ranges[nr].zones[nz + 1].lo; } else if ((nz == ranges[nr].zones.size() - 1) && (ranges[nr].zones[nz].hi < INT_MAX)) { append_to_warning(tr("Range %1: setting top of zone %2 from %3 to MAX.\n"). arg(nr + 1). arg(ranges[nr].zones[nz].name). arg(ranges[nr].zones[nz].hi) ); ranges[nr].zones[nz].hi = INT_MAX; } } } } // mark zones as modified so pages which depend on zones can be updated modificationTime = QDateTime::currentDateTime(); return true; }
// read zone file, allowing for zones with or without end dates bool Zones::read(QFile &file) { defaults_from_user = false; scheme.zone_default.clear(); scheme.zone_default_is_pct.clear(); scheme.zone_default_name.clear(); scheme.zone_default_desc.clear(); scheme.nzones_default = 0; ranges.clear(); // set up possible warning dialog warning = QString(); int warning_lines = 0; const int max_warning_lines = 100; int defaultwprime = 20000; // default to 20kJ int defaultpmax = 1000; // macro to append lines to the warning #define append_to_warning(s) \ if (warning_lines < max_warning_lines) { \ warning.append(s); } \ else if (warning_lines == max_warning_lines) { \ warning.append("...\n"); } \ warning_lines++; // read using text mode takes care of end-lines if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { err = "can't open file"; return false; } QTextStream fileStream(&file); QRegExp commentrx("\\s*#.*$"); QRegExp blankrx("^[ \t]*$"); QRegExp rangerx[] = { QRegExp("^\\s*(?:from\\s+)?" // optional "from" "((\\d\\d\\d\\d)[-/](\\d{1,2})[-/](\\d{1,2})|BEGIN)" // begin date "\\s*([,:]?\\s*(FTP|CP)\\s*=\\s*(\\d+))?" // optional {CP/FTP = integer (optional %)} "\\s*:?\\s*$", // optional : Qt::CaseInsensitive), QRegExp("^\\s*(?:from\\s+)?" // optional "from" "((\\d\\d\\d\\d)[-/](\\d{1,2})[-/](\\d{1,2})|BEGIN)" // begin date "\\s+(?:until|to|-)\\s+" // until "((\\d\\d\\d\\d)[-/](\\d{1,2})[-/](\\d{1,2})|END)?" // end date "\\s*:?,?\\s*((FTP|CP)\\s*=\\s*(\\d+))?" // optional {CP/FTP = integer (optional %)} "\\s*:?\\s*$", // optional : Qt::CaseInsensitive) }; QRegExp ftpx("^FTP=(\\d+)$"); QRegExp wprimerx("^W'=(\\d+)$"); QRegExp pmaxx("^Pmax=(\\d+)$"); QRegExp zonerx("^\\s*([^ ,][^,]*),\\s*([^ ,][^,]*),\\s*" "(\\d+)\\s*(%?)\\s*(?:,\\s*(\\d+|MAX)\\s*(%?)\\s*)?$", Qt::CaseInsensitive); QRegExp zonedefaultsx("^\\s*(?:zone)?\\s*defaults?\\s*:?\\s*$", Qt::CaseInsensitive); int lineno = 0; // the current range in the file // ZoneRange *range = NULL; bool in_range = false; QDate begin = date_zero, end = date_infinity; int cp=0; int ftp=0; int wprime=0; int pmax=0; QList<ZoneInfo> zoneInfos; // true if zone defaults are found in the file (then we need to write them) bool zones_are_defaults = false; while (!fileStream.atEnd() ) { ++lineno; QString line = fileStream.readLine(); int pos = commentrx.indexIn(line, 0); if (pos != -1) line = line.left(pos); if (blankrx.indexIn(line, 0) == 0) goto next_line; // check for default zone range definition (may be followed by zone definitions) if (zonedefaultsx.indexIn(line, 0) != -1) { zones_are_defaults = true; // defaults are allowed only at the beginning of the file if (ranges.size()) { err = "Zone defaults must be specified at head of power.zones file"; return false; } // only one set of defaults is allowed if (scheme.nzones_default) { err = "Only one set of zone defaults may be specified in power.zones file"; return false; } goto next_line; } // check for range specification (may be followed by zone definitions) for (int r=0; r<2; r++) { if (rangerx[r].indexIn(line, 0) != -1) { if (in_range) { // if zones are empty, then generate them ZoneRange range(begin, end, cp, ftp ? ftp : cp, wprime ? wprime : defaultwprime, pmax ? pmax : defaultpmax); range.zones = zoneInfos; if (range.zones.empty()) { if (range.cp > 0) { setZonesFromCP(range); } else { err = tr("line %1: read new range without reading " "any zones for previous one").arg(lineno); file.close(); return false; } } else { qSort(range.zones); } ranges.append(range); } in_range = true; zones_are_defaults = false; zoneInfos.clear(); // process the beginning date if (rangerx[r].cap(1) == "BEGIN") { begin = date_zero; } else { begin = QDate(rangerx[r].cap(2).toInt(), rangerx[r].cap(3).toInt(), rangerx[r].cap(4).toInt()); } // process an end date, if any, else it is null if (rangerx[r].cap(5) == "END") { end = date_infinity; } else if (rangerx[r].cap(6).toInt() || rangerx[r].cap(7).toInt() || rangerx[r].cap(8).toInt()) { end = QDate(rangerx[r].cap(6).toInt(), rangerx[r].cap(7).toInt(), rangerx[r].cap(8).toInt()); } else { end = QDate(); } // set up the range, capturing CP if it's specified // range = new ZoneRange(begin, end); int nCP = (r ? 11 : 7); if (rangerx[r].captureCount() == (nCP)) cp = rangerx[r].cap(nCP).toInt(); else cp = 0; // bleck goto next_line; } } // check for FTP if (ftpx.indexIn(line, 0) != -1) { if (!in_range) qDebug()<<"ignoring errant FTP= in power.zones"; else { ftp = ftpx.cap(1).toInt(); // ok its stored, so if it is in kJ upscale // if it is zero as never set, then use default if (!ftp) { ftp = cp; } } } // check for w' if (wprimerx.indexIn(line, 0) != -1) { if (!in_range) qDebug()<<"ignoring errant W'= in power.zones"; else { wprime = wprimerx.cap(1).toInt(); // ok its stored, so if it is in kJ upscale // if it is zero as never set, then use default if (wprime) { if (wprime < 1000) wprime *= 1000; // JOULES not kJ defaultwprime = wprime; } else { wprime = defaultwprime; } } } // check for Pmax if (pmaxx.indexIn(line, 0) != -1) { if (!in_range) qDebug()<<"ignoring errant Pmax= in power.zones"; else { pmax = pmaxx.cap(1).toInt(); } } // check for zone definition if (zonerx.indexIn(line, 0) != -1) { if (!(in_range || zones_are_defaults)) { err = tr("line %1: read zone without " "preceding date range").arg(lineno); file.close(); return false; } int lo = zonerx.cap(3).toInt(); // allow for zone specified as % of CP bool lo_is_pct = false; if (zonerx.cap(4) == "%") { if (zones_are_defaults) { lo_is_pct = true; } else if (cp > 0) { lo = int(lo * cp / 100); } else { err = tr("attempt to set zone based on % of " "CP without setting CP in line number %1.\n").arg(lineno); file.close(); return false; } } int hi; // if this is not a zone defaults specification, process possible hi end of zones if (zones_are_defaults || zonerx.cap(5).isEmpty()) { hi = -1; // signal an undefined number } else if (zonerx.cap(5) == "MAX") { hi = INT_MAX; } else { hi = zonerx.cap(5).toInt(); // allow for zone specified as % of CP if (zonerx.cap(5) == "%") { if (cp > 0) { hi = int(hi * cp / 100); } else { err = tr("attempt to set zone based on % of CP " "without setting CP in line number %1.\n"). arg(lineno); file.close(); return false; } } } if (zones_are_defaults) { scheme.nzones_default++; scheme.zone_default_is_pct.append(lo_is_pct); scheme.zone_default.append(lo); scheme.zone_default_name.append(zonerx.cap(1)); scheme.zone_default_desc.append(zonerx.cap(2)); defaults_from_user = true; } else { ZoneInfo zone(zonerx.cap(1), zonerx.cap(2), lo, hi); zoneInfos.append(zone); } } next_line: {} } if (in_range) { ZoneRange range(begin, end, cp, ftp ? ftp : cp, wprime ? wprime : defaultwprime, pmax ? pmax : defaultpmax); range.zones = zoneInfos; if (range.zones.empty()) { if (range.cp > 0) { setZonesFromCP(range); } else { err = tr("file ended without reading any zones for last range"); file.close(); return false; } } else { qSort(range.zones); } ranges.append(range); } file.close(); // sort the ranges qSort(ranges); // set the default zones if not in file if (!scheme.nzones_default) { // do we have a zone which is explicitly set? for (int i=0; i<ranges.count(); i++) { if (ranges[i].zonesSetFromCP == false) { // set the defaults using this one! scheme.nzones_default = ranges[i].zones.count(); for (int j=0; j<scheme.nzones_default; j++) { scheme.zone_default.append(((double)ranges[i].zones[j].lo / (double)ranges[i].cp) * 100.00); scheme.zone_default_is_pct.append(true); scheme.zone_default_name.append(ranges[i].zones[j].name); scheme.zone_default_desc.append(ranges[i].zones[j].desc); } } } // still not set then reset to defaults as usual if (!scheme.nzones_default) initializeZoneParameters(); } // resolve undefined endpoints in ranges and zones for (int nr = 0; nr < ranges.size(); nr++) { // clean up gaps or overlaps in zone ranges if (ranges[nr].end.isNull()) { ranges[nr].end = (nr < ranges.size() - 1) ? ranges[nr + 1].begin : date_infinity; } else if ((nr < ranges.size() - 1) && (ranges[nr + 1].begin != ranges[nr].end)) { append_to_warning(tr("Setting end date of range %1 " "to start date of range %2.\n"). arg(nr + 1). arg(nr + 2) ); ranges[nr].end = ranges[nr + 1].begin; } else if ((nr == ranges.size() - 1) && (ranges[nr].end < QDate::currentDate())) { append_to_warning(tr("Extending final range %1 to infinite " "to include present date.\n").arg(nr + 1)); ranges[nr].end = date_infinity; } if (ranges[nr].cp <= 0) { err = tr("CP must be greater than zero in zone " "range %1 of power.zones").arg(nr + 1); return false; } if (ranges[nr].zones.size()) { // check that the first zone starts with zero // ranges[nr].zones[0].lo = 0; // there is no reason we should enforce this // resolve zone end powers for (int nz = 0; nz < ranges[nr].zones.size(); nz++) { if (ranges[nr].zones[nz].hi == -1) { ranges[nr].zones[nz].hi = (nz < ranges[nr].zones.size() - 1) ? ranges[nr].zones[nz + 1].lo : INT_MAX; } else if ((nz < ranges[nr].zones.size() - 1) && (ranges[nr].zones[nz].hi != ranges[nr].zones[nz + 1].lo)) { if (abs(ranges[nr].zones[nz].hi - ranges[nr].zones[nz + 1].lo) > 4) { append_to_warning(tr("Range %1: matching top of zone %2 " "(%3) to bottom of zone %4 (%5).\n"). arg(nr + 1). arg(ranges[nr].zones[nz].name). arg(ranges[nr].zones[nz].hi). arg(ranges[nr].zones[nz + 1].name). arg(ranges[nr].zones[nz + 1].lo) ); } ranges[nr].zones[nz].hi = ranges[nr].zones[nz + 1].lo; } else if ((nz == ranges[nr].zones.size() - 1) && (ranges[nr].zones[nz].hi < INT_MAX)) { append_to_warning(tr("Range %1: setting top of zone %2 from %3 to MAX.\n"). arg(nr + 1). arg(ranges[nr].zones[nz].name). arg(ranges[nr].zones[nz].hi) ); ranges[nr].zones[nz].hi = INT_MAX; } } } } // mark zones as modified so pages which depend on zones can be updated modificationTime = QDateTime::currentDateTime(); return true; }