예제 #1
0
void StaticArrayTest::convertPointer() {
    StaticArray a;
    int* b = a;
    CORRADE_COMPARE(b, a.begin());

    const StaticArray c;
    const int* d = c;
    CORRADE_COMPARE(d, c.begin());

    /* Pointer arithmetic */
    const StaticArray e;
    const int* f = e + 2;
    CORRADE_COMPARE(f, &e[2]);

    /* Verify that we can't convert rvalues */
    CORRADE_VERIFY((std::is_convertible<StaticArray&, int*>::value));
    CORRADE_VERIFY((std::is_convertible<const StaticArray&, const int*>::value));
    {
        #ifdef CORRADE_GCC47_COMPATIBILITY
        CORRADE_EXPECT_FAIL("Rvalue references for *this are not supported in GCC < 4.8.1.");
        #endif
        CORRADE_VERIFY(!(std::is_convertible<StaticArray, int*>::value));
        CORRADE_VERIFY(!(std::is_convertible<StaticArray&&, int*>::value));
    }

    /* Deleting const&& overload and leaving only const& one will not, in fact,
       disable conversion of const Array&& to pointer, but rather make the
       conversion ambiguous, which is not what we want, as it breaks e.g.
       rvalueArrayAccess() test. */
    {
        CORRADE_EXPECT_FAIL("I don't know how to properly disable conversion of const Array&& to pointer.");
        CORRADE_VERIFY(!(std::is_convertible<const StaticArray, const int*>::value));
        CORRADE_VERIFY(!(std::is_convertible<const StaticArray&&, const int*>::value));
    }
}
예제 #2
0
void StaticArrayTest::convertStaticView() {
    StaticArray a;
    const StaticArray ca;

    const StaticArrayView b = a;
    const ConstStaticArrayView cb = ca;
    CORRADE_VERIFY(b.begin() == a.begin());
    CORRADE_VERIFY(cb.begin() == ca.begin());
}
예제 #3
0
void StaticArrayTest::access() {
    StaticArray a;
    for(std::size_t i = 0; i != 5; ++i)
        a[i] = i;

    CORRADE_COMPARE(a.data(), static_cast<int*>(a));
    CORRADE_COMPARE(*(a.begin()+2), 2);
    CORRADE_COMPARE(a[4], 4);
    CORRADE_COMPARE(a.end()-a.begin(), 5);
}
예제 #4
0
void StaticArrayTest::convertView() {
    StaticArray a;
    const StaticArray ca;

    const ArrayView b = a;
    const ConstArrayView cb = ca;
    CORRADE_VERIFY(b.begin() == a.begin());
    CORRADE_VERIFY(cb.begin() == ca.begin());
    CORRADE_COMPARE(b.size(), 5);
    CORRADE_COMPARE(cb.size(), 5);
}
예제 #5
0
  void CalculateRoute(const ProtectedRoutePlanner &route_planner) {
    const ProtectedRoutePlanner::Lease lease(route_planner);

    for (auto it = waypoints.begin(), end = waypoints.end(); it != end; ++it) {
      VisibleWaypoint &vwp = *it;
      const Waypoint &way_point = *vwp.waypoint;

      if (way_point.IsLandable() || way_point.flags.watched)
        vwp.CalculateReachability(lease, task_behaviour);
    }
  }
예제 #6
0
  void CalculateDirect(const PolarSettings &polar_settings,
                       const TaskBehaviour &task_behaviour,
                       const DerivedInfo &calculated) {
    if (!basic.location_available || !basic.NavAltitudeAvailable())
      return;

    const GlidePolar &glide_polar =
      task_behaviour.route_planner.reach_polar_mode == RoutePlannerConfig::Polar::TASK
      ? polar_settings.glide_polar_task
      : calculated.glide_polar_safety;
    const MacCready mac_cready(task_behaviour.glide, glide_polar);

    for (auto it = waypoints.begin(), end = waypoints.end(); it != end; ++it) {
      VisibleWaypoint &vwp = *it;
      const Waypoint &way_point = *vwp.waypoint;

      if (way_point.IsLandable() || way_point.flags.watched)
        vwp.CalculateReachabilityDirect(basic, calculated.GetWindOrZero(),
                                        mac_cready, task_behaviour);
    }
  }
예제 #7
0
파일: AvFilter.hpp 프로젝트: DRIZO/xcsoar
  /**
   * Calculate average from samples
   *
   * @return Average value in buffer
   */
  gcc_pure
  fixed Average() const {
    assert(!x.empty());

    return std::accumulate(x.begin(), x.end(), fixed(0)) / x.size();
  }
예제 #8
0
 void visit_warned(AirspaceVisitor &visitor) const {
   for (auto it = ids_warning.begin(), end = ids_warning.end(); it != end; ++it)
     if (!is_acked(**it))
       visitor.Visit(**it);
 }
예제 #9
0
파일: State.hpp 프로젝트: macsux/XCSoar
 /**
  * Search for the first traffic in the ordered list.
  */
 const FLARM_TRAFFIC *FirstTraffic() const {
   return traffic.empty() ? NULL : traffic.begin();
 }
예제 #10
0
파일: State.hpp 프로젝트: macsux/XCSoar
 unsigned TrafficIndex(const FLARM_TRAFFIC *t) const {
   return t - traffic.begin();
 }
예제 #11
0
void
dlgWaypointDetailsShowModal(SingleWindow &parent, const Waypoint &_waypoint,
                            bool allow_navigation)
{
    waypoint = &_waypoint;

    wf = LoadDialog(CallBackTable, parent,
                    Layout::landscape ? _T("IDR_XML_WAYPOINTDETAILS_L") :
                    _T("IDR_XML_WAYPOINTDETAILS"));
    assert(wf != NULL);

    LastUsedWaypoints::Add(_waypoint);

    UpdateCaption(waypoint->name.c_str(), waypoint->file_num);

    wf->SetKeyDownNotify(FormKeyDown);

    wInfo = (DockWindow *)wf->FindByName(_T("info"));
    assert(wInfo != NULL);
    wInfo->SetWidget(new WaypointInfoWidget(UIGlobals::GetDialogLook(),
                                            _waypoint));

    wCommand = (DockWindow *)wf->FindByName(_T("commands"));
    assert(wCommand != NULL);
    wCommand->SetWidget(new WaypointCommandsWidget(UIGlobals::GetDialogLook(),
                        wf, _waypoint,
                        protected_task_manager));
    wCommand->Hide();

    wDetails = wf->FindByName(_T("frmDetails"));
    assert(wDetails != NULL);

    ListControl *wFilesList = (ListControl *)wf->FindByName(_T("Files"));
    assert(wFilesList != NULL);

    EditWindow *wDetailsText = (EditWindow *)wf->FindByName(_T("Details"));
    assert(wDetailsText != NULL);
    wDetailsText->SetText(waypoint->details.c_str());

#ifdef ANDROID
    int num_files = std::distance(waypoint->files_external.begin(),
                                  waypoint->files_external.end());
    if (num_files > 0) {
        wFilesList->SetPaintItemCallback(OnFileListItemPaint);
        wFilesList->SetCursorCallback(OnFileListEnter);
        wFilesList->SetActivateCallback(OnFileListEnter);

        unsigned list_height = wFilesList->GetItemHeight() * std::min(num_files, 5);
        wFilesList->Resize(wFilesList->GetWidth(), list_height);
        wFilesList->SetLength(num_files);

        PixelRect rc = wDetailsText->GetPosition();
        rc.top += list_height;
        wDetailsText->Move(rc);
    } else
#endif
        wFilesList->Hide();

    wImage = (PaintWindow *)wf->FindByName(_T("frmImage"));
    assert(wImage != NULL);
    wMagnify = (WndButton *)wf->FindByName(_T("cmdMagnify"));
    assert(wMagnify != NULL);
    wShrink = (WndButton *)wf->FindByName(_T("cmdShrink"));
    assert(wShrink != NULL);

    if (!allow_navigation) {
        WndButton* butnav = (WndButton *)wf->FindByName(_T("cmdPrev"));
        assert(butnav != NULL);
        butnav->Hide();

        butnav = (WndButton *)wf->FindByName(_T("cmdNext"));
        assert(butnav != NULL);
        butnav->Hide();

        butnav = (WndButton *)wf->FindByName(_T("cmdGoto"));
        assert(butnav != NULL);
        butnav->Hide();
    }

    for (auto it = waypoint->files_embed.begin(),
            it_end = waypoint->files_embed.end();
            it != it_end && !images.full(); it++) {
        TCHAR path[MAX_PATH];
        LocalPath(path, it->c_str());
        if (!images.append().LoadFile(path))
            images.shrink(images.size() - 1);
    }

    page = 0;

    NextPage(0); // JMW just to turn proper pages on/off

    wf->ShowModal();

    delete wf;

    for (auto image = images.begin(); image < images.end(); image++)
        image->Reset();

    images.clear();
}
예제 #12
0
파일: State.hpp 프로젝트: macsux/XCSoar
 /**
  * Search for the previous traffic in the ordered list.
  */
 const FLARM_TRAFFIC *PreviousTraffic(const FLARM_TRAFFIC *t) const {
   return t > traffic.begin()
     ? t - 1
     : NULL;
 }
예제 #13
0
 const Label *begin() const {
     return labels.begin();
 }
예제 #14
0
파일: AvFilter.hpp 프로젝트: Advi42/XCSoar
  /**
   * Calculate average from samples
   *
   * @return Average value in buffer
   */
  gcc_pure
  double Average() const {
    assert(!x.empty());

    return std::accumulate(x.begin(), x.end(), 0.0) / x.size();
  }
예제 #15
0
 void visit_inside(AirspaceVisitor &visitor) const {
   for (auto it = ids_inside.begin(), end = ids_inside.end(); it != end; ++it)
     if (!is_acked(**it))
       visitor.Visit(**it);
 }
예제 #16
0
 void VisitWarnings(AirspaceVisitor &visitor) const {
   for (auto it = ids_warning.begin(), end = ids_warning.end(); it != end; ++it)
     if (!IsAcked(**it))
       visitor.Visit(**it);
 }
예제 #17
0
void 
dlgWaypointDetailsShowModal(const Waypoint &_waypoint,
                            bool allow_navigation)
{
  waypoint = &_waypoint;

  form = LoadDialog(CallBackTable, UIGlobals::GetMainWindow(),
                  Layout::landscape ? _T("IDR_XML_WAYPOINTDETAILS_L") :
                                      _T("IDR_XML_WAYPOINTDETAILS"));
  assert(form != nullptr);

  LastUsedWaypoints::Add(_waypoint);

  UpdateCaption();

  form->SetKeyDownFunction(FormKeyDown);

  info_widget = (DockWindow *)form->FindByName(_T("info"));
  assert(info_widget != nullptr);
  info_widget->SetWidget(new WaypointInfoWidget(UIGlobals::GetDialogLook(),
                                          _waypoint));

  commands_widget = (DockWindow *)form->FindByName(_T("commands"));
  assert(commands_widget != nullptr);
  commands_widget->SetWidget(new WaypointCommandsWidget(UIGlobals::GetDialogLook(),
                                                 form, _waypoint,
                                                 protected_task_manager));
  commands_widget->Hide();

  details_panel = form->FindByName(_T("frmDetails"));
  assert(details_panel != nullptr);

  ListControl *wFilesList = (ListControl *)form->FindByName(_T("Files"));
  assert(wFilesList != nullptr);

  LargeTextWindow *wDetailsText = (LargeTextWindow *)
    form->FindByName(_T("Details"));
  assert(wDetailsText != nullptr);
  wDetailsText->SetText(waypoint->details.c_str());

#ifdef ANDROID
  WaypointExternalFileListHandler handler;
  int num_files = std::distance(waypoint->files_external.begin(),
                                waypoint->files_external.end());
  if (num_files > 0) {
    wFilesList->SetItemRenderer(&handler);
    wFilesList->SetCursorHandler(&handler);

    unsigned list_height = wFilesList->GetItemHeight() * std::min(num_files, 5);
    wFilesList->Resize(wFilesList->GetWidth(), list_height);
    wFilesList->SetLength(num_files);

    PixelRect rc = wDetailsText->GetPosition();
    rc.top += list_height;
    wDetailsText->Move(rc);
  } else
#endif
    wFilesList->Hide();

  image_window = (PaintWindow *)form->FindByName(_T("frmImage"));
  assert(image_window != nullptr);
  magnify_button = (WndButton *)form->FindByName(_T("cmdMagnify"));
  assert(magnify_button != nullptr);
  shrink_button = (WndButton *)form->FindByName(_T("cmdShrink"));
  assert(shrink_button != nullptr);

  if (!allow_navigation) {
    for (const TCHAR *button_name :
         { _T("cmdPrev"), _T("cmdNext"), _T("cmdGoto") }) {
      Window *button = form->FindByName(button_name);
      assert(button != nullptr);
      button->Hide();
    }
  }

  for (auto it = waypoint->files_embed.begin(),
       it_end = waypoint->files_embed.end();
       it != it_end && !images.full(); it++) {
    TCHAR path[MAX_PATH];
    LocalPath(path, it->c_str());
    if (!images.append().LoadFile(path))
      images.shrink(images.size() - 1);
  }

  last_page = 2 + images.size();

  page = 0;
  UpdatePage();

  form->ShowModal();

  delete form;

  for (auto image = images.begin(); image < images.end(); image++)
    image->Reset();

  images.clear();
}
예제 #18
0
void
TerrainXSRenderer::Draw(Canvas &canvas, const ChartRenderer &chart, const short *elevations) const
{
  const fixed max_distance = chart.GetXMax();

  StaticArray<RasterPoint, CrossSectionRenderer::NUM_SLICES + 2> points;

  canvas.SelectNullPen();

  RasterBuffer::TerrainType last_type = RasterBuffer::TerrainType::UNKNOWN;
  fixed last_distance = fixed(0);

  for (unsigned j = 0; j < CrossSectionRenderer::NUM_SLICES; ++j) {
    const fixed distance_factor =
        fixed(j) / (CrossSectionRenderer::NUM_SLICES - 1);
    const fixed distance = distance_factor * max_distance;

    short h = elevations[j];
    RasterBuffer::TerrainType type = RasterBuffer::GetTerrainType(h);

    if (type == RasterBuffer::TerrainType::WATER)
      h = 0;

    // Close and paint polygon
    if (j != 0 &&
        type != last_type &&
        last_type != RasterBuffer::TerrainType::UNKNOWN) {
      const fixed center_distance = (distance + last_distance) / 2;
      points.append() = chart.ToScreen(center_distance, fixed(0));
      points.append() = chart.ToScreen(center_distance, fixed(-500));

      DrawPolygon(canvas, last_type, points.begin(), points.size());
    }

    if (type != RasterBuffer::TerrainType::UNKNOWN) {
      if (j == 0) {
        // Start first polygon
        points.append() = chart.ToScreen(distance, fixed(-500));
        points.append() = chart.ToScreen(distance, fixed(h));
      } else if (type != last_type) {
        // Start new polygon
        points.clear();

        const fixed center_distance = (distance + last_distance) / 2;
        points.append() = chart.ToScreen(center_distance, fixed(-500));
        points.append() = chart.ToScreen(center_distance, fixed(0));
      }

      if (j + 1 == CrossSectionRenderer::NUM_SLICES) {
        // Close and paint last polygon
        points.append() = chart.ToScreen(distance, fixed(h));
        points.append() = chart.ToScreen(distance, fixed(-500));

        DrawPolygon(canvas, type, points.begin(), points.size());
      } else if (type == last_type && j != 0) {
        // Add single point to polygon
        points.append() = chart.ToScreen(distance, fixed(h));
      }
    }

    last_type = type;
    last_distance = distance;
  }
}
예제 #19
0
 void Draw(Canvas &canvas) {
   for (auto it = waypoints.begin(), end = waypoints.end(); it != end; ++it)
     DrawWaypoint(canvas, *it);
 }