aboutsummaryrefslogtreecommitdiffstats
path: root/community/opencpn/Replace-some-wx-arrays-with-std-vector.patch
blob: cddfcd4199fb39b31be6d8a28065bafa6784d0fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
From 9ac4ad6ff62dd449d8e1e6abef98521cae3e1839 Mon Sep 17 00:00:00 2001
From: Pavel Kalian <pavel@kalian.cz>
Date: Thu, 21 Jun 2018 17:08:06 -0300
Subject: [PATCH] Replace some wx arrays with std::vector (Fixes build with
 current wxWidgets codebase)

---
 include/s57chart.h                   |  2 +-
 src/routemanagerdialog.cpp           | 38 ++++++++---------
 src/s57chart.cpp                     | 61 +++++++++++++---------------
 src/wxsvg/include/wxSVG/NodeList.h   |  2 +-
 src/wxsvg/include/wxSVG/SVGElement.h |  2 +
 5 files changed, 51 insertions(+), 54 deletions(-)

diff --git a/include/s57chart.h b/include/s57chart.h
index 42af908c71..2b8eefc014 100644
--- a/include/s57chart.h
+++ b/include/s57chart.h
@@ -160,7 +160,7 @@ class s57chart : public ChartBase
       bool IsPointInObjArea(float lat, float lon, float select_radius, S57Obj *obj);
       wxString GetObjectAttributeValueAsString( S57Obj *obj, int iatt, wxString curAttrName );
       static wxString GetAttributeValueAsString( S57attVal *pAttrVal, wxString AttrName );
-      static int CompareLights( const void** l1, const void** l2 );
+      static bool CompareLights( const S57Light* l1, const S57Light* l2 );
       wxString CreateObjDescriptions( ListOfObjRazRules* rule);
       static wxString GetAttributeDecode(wxString& att, int ival);
 
diff --git a/src/routemanagerdialog.cpp b/src/routemanagerdialog.cpp
index 56dcbbeb99..d677a42dd5 100644
--- a/src/routemanagerdialog.cpp
+++ b/src/routemanagerdialog.cpp
@@ -33,6 +33,8 @@
 #include <wx/clipbrd.h>
 
 #include <iostream>
+#include <vector>
+#include <algorithm>
 
 #include "styles.h"
 #include "dychart.h"
@@ -1523,14 +1525,11 @@ void RouteManagerDialog::OnTrkRightClick( wxListEvent &event )
     PopupMenu( &menu );
 }
 
-WX_DEFINE_ARRAY( Track*, TrackArray );
-
-static int CompareTracks( Track** track1, Track** track2 )
+static bool CompareTracks( Track* track1, Track* track2 )
 {
-    TrackPoint* start1 = ( *track1 )->GetPoint(0);
-    TrackPoint* start2 = ( *track2 )->GetPoint(0);
-    if( start1->GetCreateTime() > start2->GetCreateTime() ) return 1;
-    return -1; // Two tracks starting at the same time is not possible.
+    TrackPoint* start1 = track1->GetPoint(0);
+    TrackPoint* start2 = track2->GetPoint(0);
+    return start1->GetCreateTime() < start2->GetCreateTime();
 }
 
 void RouteManagerDialog::OnTrkMenuSelected( wxCommandEvent &event )
@@ -1616,8 +1615,8 @@ void RouteManagerDialog::OnTrkMenuSelected( wxCommandEvent &event )
             TrackPoint* tPoint;
             TrackPoint* newPoint;
             TrackPoint* lastPoint;
-            TrackArray mergeList;
-            TrackArray deleteList;
+            std::vector<Track*> mergeList;
+            std::vector<Track*> deleteList;
             bool runningSkipped = false;
 
             ::wxBeginBusyCursor();
@@ -1626,17 +1625,17 @@ void RouteManagerDialog::OnTrkMenuSelected( wxCommandEvent &event )
                 item = m_pTrkListCtrl->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
                 if( item == -1 ) break;
                 Track* track = pTrackList->Item( m_pTrkListCtrl->GetItemData( item ) )->GetData();
-                mergeList.Add( track );
+                mergeList.push_back( track );
             }
 
-            mergeList.Sort( (CMPFUNC_wxArrayTrackArray) CompareTracks );
+            std::sort(mergeList.begin(), mergeList.end(), CompareTracks );
 
-            targetTrack = mergeList.Item( 0 );
+            targetTrack = mergeList[ 0 ];
             lastPoint = targetTrack->GetLastPoint();
 
-            for( unsigned int t = 1; t < mergeList.Count(); t++ ) {
-
-                mergeTrack = mergeList.Item( t );
+            for(auto const& mergeTrack: mergeList) {
+                if(mergeTrack == *mergeList.begin())
+                    continue;
 
                 if( mergeTrack->IsRunning() ) {
                     runningSkipped = true;
@@ -1654,18 +1653,17 @@ void RouteManagerDialog::OnTrkMenuSelected( wxCommandEvent &event )
 
                     lastPoint = newPoint;
                 }
-                deleteList.Add( mergeTrack );
+                deleteList.push_back( mergeTrack );
             }
 
-            for( unsigned int i = 0; i < deleteList.Count(); i++ ) {
-                Track* deleteTrack = deleteList.Item( i );
+            for(auto const& deleteTrack: deleteList) {
                 g_pAIS->DeletePersistentTrack( deleteTrack );
                 pConfig->DeleteConfigTrack( deleteTrack );
                 g_pRouteMan->DeleteTrack( deleteTrack );
             }
 
-            mergeList.Clear();
-            deleteList.Clear();
+            mergeList.clear();
+            deleteList.clear();
 
             ::wxEndBusyCursor();
 
diff --git a/src/s57chart.cpp b/src/s57chart.cpp
index 1144b3ddcc..2a363e8771 100644
--- a/src/s57chart.cpp
+++ b/src/s57chart.cpp
@@ -5101,29 +5101,25 @@ wxString s57chart::GetAttributeValueAsString( S57attVal *pAttrVal, wxString Attr
     return value;
 }
 
-int s57chart::CompareLights( const void** l1ptr, const void** l2ptr )
+bool s57chart::CompareLights( const S57Light* l1, const S57Light* l2 )
 {
-    S57Light l1 = *(S57Light*) *l1ptr;
-    S57Light l2 = *(S57Light*) *l2ptr;
+    int positionDiff = l1->position.Cmp( l2->position );
+    if( positionDiff != 0 ) return true;
 
-    int positionDiff = l1.position.Cmp( l2.position );
-    if( positionDiff != 0 ) return positionDiff;
 
-    double angle1, angle2;
-    int attrIndex1 = l1.attributeNames.Index( _T("SECTR1") );
-    int attrIndex2 = l2.attributeNames.Index( _T("SECTR1") );
+    int attrIndex1 = l1->attributeNames.Index( _T("SECTR1") );
+    int attrIndex2 = l2->attributeNames.Index( _T("SECTR1") );
 
     // This should put Lights without sectors last in the list.
-    if( attrIndex1 == wxNOT_FOUND && attrIndex2 == wxNOT_FOUND ) return 0;
-    if( attrIndex1 != wxNOT_FOUND && attrIndex2 == wxNOT_FOUND ) return -1;
-    if( attrIndex1 == wxNOT_FOUND && attrIndex2 != wxNOT_FOUND ) return 1;
+    if( attrIndex1 == wxNOT_FOUND && attrIndex2 == wxNOT_FOUND ) return false;
+    if( attrIndex1 != wxNOT_FOUND && attrIndex2 == wxNOT_FOUND ) return true;
+    if( attrIndex1 == wxNOT_FOUND && attrIndex2 != wxNOT_FOUND ) return false;
 
-    l1.attributeValues.Item( attrIndex1 ).ToDouble( &angle1 );
-    l2.attributeValues.Item( attrIndex2 ).ToDouble( &angle2 );
+    double angle1, angle2;
+    l1->attributeValues.Item( attrIndex1 ).ToDouble( &angle1 );
+    l2->attributeValues.Item( attrIndex2 ).ToDouble( &angle2 );
 
-    if( angle1 == angle2 ) return 0;
-    if( angle1 > angle2 ) return 1;
-    return -1;
+    return angle1 < angle2;
 }
 
 static const char *type2str( GeoPrim_t type)
@@ -5161,7 +5157,7 @@ wxString s57chart::CreateObjDescriptions( ListOfObjRazRules* rule_list )
     wxString objText;
     wxString lightsHtml;
     wxString positionString;
-    wxArrayPtrVoid lights;
+    std::vector<S57Light*> lights;
     S57Light* curLight = NULL;
 
     for( ListOfObjRazRules::Node *node = rule_list->GetLast(); node; node = node->GetPrevious() ) {
@@ -5252,7 +5248,7 @@ wxString s57chart::CreateObjDescriptions( ListOfObjRazRules* rule_list )
                 curLight = new S57Light;
                 curLight->position = positionString;
                 curLight->hasSectors = false;
-                lights.Add( curLight );
+                lights.push_back( curLight );
             }
         }
 
@@ -5352,30 +5348,31 @@ wxString s57chart::CreateObjDescriptions( ListOfObjRazRules* rule_list )
         }
     } // Object for loop
 
-    if( lights.Count() > 0 ) {
+    if( !lights.empty() ) {
 
         // For lights we now have all the info gathered but no HTML output yet, now
         // run through the data and build a merged table for all lights.
 
-        lights.Sort( ( CMPFUNC_wxArraywxArrayPtrVoid )( &s57chart::CompareLights ) );
+        std::sort(lights.begin(), lights.end(), s57chart::CompareLights);
 
         wxString lastPos;
 
-        for( unsigned int curLightNo = 0; curLightNo < lights.Count(); curLightNo++ ) {
-            S57Light* thisLight = (S57Light*) lights.Item( curLightNo );
+        for(auto const& thisLight: lights) {
             int attrIndex;
 
             if( thisLight->position != lastPos ) {
 
                 lastPos = thisLight->position;
 
-                if( curLightNo > 0 ) lightsHtml << _T("</table>\n<hr noshade>\n");
+                if( thisLight != *lights.begin() )
+                    lightsHtml << _T("</table>\n<hr noshade>\n");
+                curLight++;
 
                 lightsHtml << _T("<b>Light</b> <font size=-2>(LIGHTS)</font><br>");
                 lightsHtml << _T("<font size=-2>") << thisLight->position << _T("</font><br>\n");
 
-                if( curLight && curLight->hasSectors ) lightsHtml
-                        <<_("<font size=-2>(Sector angles are True Bearings from Seaward)</font><br>");
+                if( curLight && curLight->hasSectors )
+                    lightsHtml <<_("<font size=-2>(Sector angles are True Bearings from Seaward)</font><br>");
 
                 lightsHtml << _T("<table>");
             }
@@ -5386,12 +5383,12 @@ wxString s57chart::CreateObjDescriptions( ListOfObjRazRules* rule_list )
             attrIndex = thisLight->attributeNames.Index( _T("COLOUR") );
             if( attrIndex != wxNOT_FOUND ) {
                 wxString color = thisLight->attributeValues.Item( attrIndex );
-                if( color == _T("red (3)") ) lightsHtml
-                        << _T("<table border=0><tr><td bgcolor=red>&nbsp;&nbsp;&nbsp;</td></tr></table> ");
-                if( color == _T("green (4)") ) lightsHtml
-                        << _T("<table border=0><tr><td bgcolor=green>&nbsp;&nbsp;&nbsp;</td></tr></table> ");
-                if( color == _T("white (1)") ) lightsHtml
-                        << _T("<table border=0><tr><td bgcolor=yellow>&nbsp;&nbsp;&nbsp;</td></tr></table> ");
+                if( color == _T("red (3)") )
+                    lightsHtml << _T("<table border=0><tr><td bgcolor=red>&nbsp;&nbsp;&nbsp;</td></tr></table> ");
+                if( color == _T("green (4)") )
+                    lightsHtml << _T("<table border=0><tr><td bgcolor=green>&nbsp;&nbsp;&nbsp;</td></tr></table> ");
+                if( color == _T("white (1)") )
+                    lightsHtml << _T("<table border=0><tr><td bgcolor=yellow>&nbsp;&nbsp;&nbsp;</td></tr></table> ");
             }
 
             lightsHtml << _T("</font></td><td><font size=-1><nobr><b>");
@@ -5474,7 +5471,7 @@ wxString s57chart::CreateObjDescriptions( ListOfObjRazRules* rule_list )
         lightsHtml << _T("</table><hr noshade>\n");
         ret_val = lightsHtml << ret_val;
 
-        lights.Clear();
+        lights.clear();
     }
 
     return ret_val;
diff --git a/src/wxsvg/include/wxSVG/NodeList.h b/src/wxsvg/include/wxSVG/NodeList.h
index 4d91c39cd9..9c4e7b1e6b 100644
--- a/src/wxsvg/include/wxSVG/NodeList.h
+++ b/src/wxsvg/include/wxSVG/NodeList.h
@@ -13,6 +13,6 @@
 
 #include "SVGElement.h"
 #include <wx/dynarray.h>
-WX_DECLARE_OBJARRAY(wxSVGElement*, wxNodeList);
+WX_DECLARE_OBJARRAY(wxSVGElementP, wxNodeList);
 
 #endif //wxSVG_NODE_LIST_H
diff --git a/src/wxsvg/include/wxSVG/SVGElement.h b/src/wxsvg/include/wxSVG/SVGElement.h
index c472b4654a..f47fb89659 100644
--- a/src/wxsvg/include/wxSVG/SVGElement.h
+++ b/src/wxsvg/include/wxSVG/SVGElement.h
@@ -18,6 +18,8 @@ class wxSVGDocument;
 #include "SVGAnimatedType.h"
 #include "SVGDTD.h"
 
+typedef wxSVGElement* wxSVGElementP;
+
 class wxSVGElement:
   public wxSvgXmlElement
 {