Skip to content

Commit 573b21e

Browse files
committed
Changes to any:
- Added has_value() to thelink2012 any - Issue #6457: empty() -> !has_value() when using C++17 std::any
1 parent 4fa6ccd commit 573b21e

18 files changed

+79
-61
lines changed

src/Wt/Auth/AuthModel.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool AuthModel::login(Login& login)
191191
if (loginUser(login, user)) {
192192
reset();
193193

194-
if (!v.empty() && cpp17::any_cast<bool>(v) == true)
194+
if (cpp17::any_has_value(v) && cpp17::any_cast<bool>(v) == true)
195195
setRememberMeCookie(user);
196196

197197
return true;

src/Wt/Chart/WEquidistantGridData.C

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int WEquidistantGridData::countSimpleData() const
109109
int nbModelCols = model_->columnCount();
110110
for (int i=0; i<nbModelRows; i++) {
111111
for (int j=0; j<nbModelCols; j++) {
112-
if (model_->data(i,j,ItemDataRole::MarkerBrushColor).empty()) {
112+
if (!cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerBrushColor))) {
113113
result++;
114114
}
115115
}
@@ -149,11 +149,11 @@ void WEquidistantGridData::pointDataFromModel(FloatBuffer& simplePtsArray,
149149

150150
for (int i=0; i < Nx; i++) {
151151
for (int j=0; j < Ny; j++) {
152-
if (model_->data(i,j,ItemDataRole::MarkerBrushColor).empty()) {
152+
if (!cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerBrushColor))) {
153153
simplePtsArray.push_back(scaledXAxis[i]);
154154
simplePtsArray.push_back(scaledYAxis[j]);
155155
simplePtsArray.push_back((float)((Wt::asNumber(model_->data(i,j))-zMin)/(zMax-zMin)));
156-
if (!model_->data(i,j,ItemDataRole::MarkerScaleFactor).empty()) {
156+
if (cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerScaleFactor))) {
157157
simplePtsSize.push_back((float)(Wt::asNumber(model_->data(i,j,ItemDataRole::MarkerScaleFactor))));
158158
} else {
159159
simplePtsSize.push_back((float)pointSize());
@@ -170,7 +170,7 @@ void WEquidistantGridData::pointDataFromModel(FloatBuffer& simplePtsArray,
170170
coloredPtsColor.push_back((float)color.blue());
171171
coloredPtsColor.push_back((float)color.alpha());
172172

173-
if (!model_->data(i,j,ItemDataRole::MarkerScaleFactor).empty()) {
173+
if (cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerScaleFactor))) {
174174
coloredPtsSize.push_back((float)(Wt::asNumber(model_->data(i,j,ItemDataRole::MarkerScaleFactor))));
175175
} else {
176176
coloredPtsSize.push_back((float)pointSize());
@@ -407,7 +407,7 @@ void WEquidistantGridData::barDataFromModel(std::vector<FloatBuffer>& simplePtsA
407407
for (int j=0; j < Ny; j++) {
408408
float z0 = stackAllValues(prevDataseries, i,j);
409409

410-
if (model_->data(i,j,ItemDataRole::MarkerBrushColor).empty()) {
410+
if (!cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerBrushColor))) {
411411
if (simpleCount == BAR_BUFFER_LIMIT) {
412412
simpleBufferIndex++;
413413
simpleCount = 0;

src/Wt/Chart/WGridData.C

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int WGridData::countSimpleData() const
6565
if (j == XAbscisColumn_)
6666
continue;
6767

68-
if (model_->data(i,j,ItemDataRole::MarkerBrushColor).empty()) {
68+
if (!cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerBrushColor))) {
6969
result++;
7070
}
7171
}
@@ -213,11 +213,11 @@ void WGridData::pointDataFromModel(FloatBuffer& simplePtsArray,
213213
colOffset = 1;
214214
continue;
215215
}
216-
if (model_->data(i,j,ItemDataRole::MarkerBrushColor).empty()) {
216+
if (!cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerBrushColor))) {
217217
simplePtsArray.push_back(scaledXAxis[i-rowOffset]);
218218
simplePtsArray.push_back(scaledYAxis[j-colOffset]);
219219
simplePtsArray.push_back((float)((Wt::asNumber(model_->data(i,j,ItemDataRole::Display))-zMin)/(zMax-zMin)));
220-
if (!model_->data(i,j,ItemDataRole::MarkerScaleFactor).empty()) {
220+
if (cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerScaleFactor))) {
221221
simplePtsSize.push_back((float)(Wt::asNumber(model_->data(i,j,ItemDataRole::MarkerScaleFactor))));
222222
} else {
223223
simplePtsSize.push_back((float)pointSize());
@@ -233,7 +233,7 @@ void WGridData::pointDataFromModel(FloatBuffer& simplePtsArray,
233233
coloredPtsColor.push_back((float)color.blue());
234234
coloredPtsColor.push_back((float)color.alpha());
235235

236-
if (!model_->data(i,j,ItemDataRole::MarkerScaleFactor).empty()) {
236+
if (cpp17::any_has_value(model_->data(i,j,ItemDataRole::MarkerScaleFactor))) {
237237
coloredPtsSize.push_back
238238
((float)(Wt::asNumber
239239
(model_->data(i,j, ItemDataRole::MarkerScaleFactor))));
@@ -522,7 +522,7 @@ void WGridData::barDataFromModel(std::vector<FloatBuffer>& simplePtsArrays,
522522
}
523523
float z0 = stackAllValues(prevDataseries, i,j);
524524

525-
if (model_->data(i+rowOffset,j+colOffset,ItemDataRole::MarkerBrushColor).empty()) {
525+
if (!cpp17::any_has_value(model_->data(i+rowOffset,j+colOffset,ItemDataRole::MarkerBrushColor))) {
526526
if (simpleCount == BAR_BUFFER_LIMIT) {
527527
simpleBufferIndex++;
528528
simpleCount = 0;

src/Wt/Chart/WScatterData.C

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ int WScatterData::countSimpleData() const
293293
result = 0;
294294
} else {
295295
for (int i=0; i < N; i++) {
296-
if (model_->data(i,ZSeriesColumn_, ItemDataRole::MarkerBrushColor).empty()) {
296+
if (!cpp17::any_has_value(model_->data(i,ZSeriesColumn_, ItemDataRole::MarkerBrushColor))) {
297297
result++;
298298
}
299299
}
@@ -319,7 +319,7 @@ void WScatterData::dataFromModel(FloatBuffer& simplePtsArray,
319319
double zMax = chart_->axis(Axis::Z3D).maximum();
320320

321321
for (int i=0; i < N; i++) {
322-
if (colorColumn_ == -1 && model_->data(i,ZSeriesColumn_, ItemDataRole::MarkerBrushColor).empty()) {
322+
if (colorColumn_ == -1 && !cpp17::any_has_value(model_->data(i,ZSeriesColumn_, ItemDataRole::MarkerBrushColor))) {
323323
simplePtsArray.push_back
324324
((float)((Wt::asNumber(model_->data(i,XSeriesColumn_)) - xMin) /
325325
(xMax - xMin)));
@@ -365,11 +365,11 @@ void WScatterData::dataFromModel(FloatBuffer& simplePtsArray,
365365

366366
FloatBuffer& sizeArrayAlias =
367367
(colorColumn_ == -1 &&
368-
model_->data(i, ZSeriesColumn_, ItemDataRole::MarkerBrushColor).empty())
368+
!cpp17::any_has_value(model_->data(i, ZSeriesColumn_, ItemDataRole::MarkerBrushColor)))
369369
? simplePtsSize : coloredPtsSize;
370370
if (sizeColumn_ == -1 &&
371-
model_->data(i, ZSeriesColumn_,
372-
ItemDataRole::MarkerScaleFactor).empty()) {
371+
!cpp17::any_has_value(model_->data(i, ZSeriesColumn_,
372+
ItemDataRole::MarkerScaleFactor))) {
373373
sizeArrayAlias.push_back((float)pointSize_);
374374
} else if (sizeColumn_ == -1) {
375375
sizeArrayAlias.push_back

src/Wt/Chart/WStandardChartProxyModel.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ WLink *WStandardChartProxyModel::link(int row, int column) const
6666
{
6767
cpp17::any result = sourceModel_->data(row, column, ItemDataRole::Link);
6868

69-
if (result.empty())
69+
if (!cpp17::any_has_value(result))
7070
return 0;
7171
else {
7272
#ifndef WT_TARGET_JAVA
@@ -84,7 +84,7 @@ const WColor *WStandardChartProxyModel::color(int row, int column, int colorData
8484
{
8585
cpp17::any result = sourceModel_->data(row, column, colorDataRole);
8686

87-
if (result.empty())
87+
if (!cpp17::any_has_value(result))
8888
return nullptr;
8989
else {
9090
#ifndef WT_TARGET_JAVA
@@ -122,7 +122,7 @@ const double *WStandardChartProxyModel::markerScaleFactor(int row, int column) c
122122
cpp17::any result = sourceModel_->data(row, column,
123123
ItemDataRole::MarkerScaleFactor);
124124

125-
if (result.empty()) {
125+
if (!cpp17::any_has_value(result)) {
126126
return WAbstractChartModel::markerScaleFactor(row, column);
127127
} else {
128128
#ifndef WT_TARGET_JAVA

src/Wt/Json/Value.C

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ bool Value::operator== (const Value& other) const
178178
{
179179
if (typeid(v_) != typeid(other.v_))
180180
return false;
181-
else if (v_.empty() || other.v_.empty())
182-
return v_.empty() == other.v_.empty();
181+
else if (!cpp17::any_has_value(v_) || !cpp17::any_has_value(other.v_))
182+
return cpp17::any_has_value(v_) == cpp17::any_has_value(other.v_);
183183
else if (v_.type() == typeid(Json::Object))
184184
return cpp17::any_cast<Json::Object>(v_) ==
185185
cpp17::any_cast<Json::Object>(other.v_);
@@ -211,7 +211,7 @@ bool Value::operator!= (const Value& other) const
211211

212212
Type Value::type() const
213213
{
214-
if (v_.empty())
214+
if (cpp17::any_has_value(v_))
215215
return Type::Null;
216216
else {
217217
return typeOf(v_.type());
@@ -319,15 +319,15 @@ Value::operator Object&()
319319

320320
const WT_USTRING& Value::orIfNull(const WT_USTRING& v) const
321321
{
322-
if (!v_.empty())
322+
if (cpp17::any_has_value(v_))
323323
return *this;
324324
else
325325
return v;
326326
}
327327

328328
std::string Value::orIfNull(const std::string& v) const
329329
{
330-
if (!v_.empty())
330+
if (cpp17::any_has_value(v_))
331331
return *this;
332332
else
333333
return v;
@@ -340,47 +340,47 @@ std::string Value::orIfNull(const char *v) const
340340

341341
bool Value::orIfNull(bool v) const
342342
{
343-
if (!v_.empty())
343+
if (cpp17::any_has_value(v_))
344344
return *this;
345345
else
346346
return v;
347347
}
348348

349349
int Value::orIfNull(int v) const
350350
{
351-
if (!v_.empty())
351+
if (cpp17::any_has_value(v_))
352352
return *this;
353353
else
354354
return v;
355355
}
356356

357357
long long Value::orIfNull(long long v) const
358358
{
359-
if (!v_.empty())
359+
if (cpp17::any_has_value(v_))
360360
return *this;
361361
else
362362
return v;
363363
}
364364

365365
double Value::orIfNull(double v) const
366366
{
367-
if (!v_.empty())
367+
if (cpp17::any_has_value(v_))
368368
return *this;
369369
else
370370
return v;
371371
}
372372

373373
const Array& Value::orIfNull(const Array& v) const
374374
{
375-
if (!v_.empty())
375+
if (cpp17::any_has_value(v_))
376376
return *this;
377377
else
378378
return v;
379379
}
380380

381381
const Object& Value::orIfNull(const Object& v) const
382382
{
383-
if (!v_.empty())
383+
if (cpp17::any_has_value(v_))
384384
return *this;
385385
else
386386
return v;

src/Wt/WAbstractItemView.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ int WAbstractItemView::headerLevel(int column) const
10391039
cpp17::any d = model_->headerData(column, Orientation::Horizontal,
10401040
ItemDataRole::Level);
10411041

1042-
if (!d.empty())
1042+
if (cpp17::any_has_value(d))
10431043
return static_cast<int>(asNumber(d));
10441044
else
10451045
return 0;

src/Wt/WAny.C

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool matchValue(const cpp17::any& value, const cpp17::any& query,
136136

137137
std::string asJSLiteral(const cpp17::any& v, TextFormat textFormat)
138138
{
139-
if (v.empty())
139+
if (!cpp17::any_has_value(v))
140140
return std::string("''");
141141
else if (v.type() == typeid(WString)) {
142142
WString s = cpp17::any_cast<WString>(v);
@@ -249,7 +249,7 @@ T lexical_cast(const std::string& s) {
249249

250250
cpp17::any updateFromJS(const cpp17::any& v, std::string s)
251251
{
252-
if (v.empty())
252+
if (!cpp17::any_has_value(v))
253253
return cpp17::any(s);
254254
else if (v.type() == typeid(WString))
255255
return cpp17::any(WString::fromUTF8(s));
@@ -301,8 +301,8 @@ int compare(const cpp17::any& d1, const cpp17::any& d2)
301301
* If the types are the same then we use std::operator< on that type
302302
* otherwise we compare lexicographically
303303
*/
304-
if (!d1.empty())
305-
if (!d2.empty()) {
304+
if (cpp17::any_has_value(d1))
305+
if (cpp17::any_has_value(d2)) {
306306
if (d1.type() == d2.type()) {
307307
if (d1.type() == typeid(bool))
308308
return static_cast<int>(cpp17::any_cast<bool>(d1))
@@ -355,7 +355,7 @@ int compare(const cpp17::any& d1, const cpp17::any& d2)
355355
} else
356356
return -UNSPECIFIED_RESULT;
357357
else
358-
if (!d2.empty())
358+
if (cpp17::any_has_value(d2))
359359
return UNSPECIFIED_RESULT;
360360
else
361361
return 0;
@@ -365,7 +365,7 @@ int compare(const cpp17::any& d1, const cpp17::any& d2)
365365

366366
WString asString(const cpp17::any& v, const WT_USTRING& format)
367367
{
368-
if (v.empty())
368+
if (!cpp17::any_has_value(v))
369369
return WString();
370370
else if (v.type() == typeid(WString))
371371
return cpp17::any_cast<WString>(v);
@@ -491,7 +491,7 @@ WString asString(const cpp17::any& v, const WT_USTRING& format)
491491

492492
double asNumber(const cpp17::any& v)
493493
{
494-
if (v.empty())
494+
if (!cpp17::any_has_value(v))
495495
return std::numeric_limits<double>::signaling_NaN();
496496
else if (v.type() == typeid(WString))
497497
try {
@@ -568,7 +568,7 @@ extern WT_API cpp17::any convertAnyToAny(const cpp17::any& v,
568568
const std::type_info& type,
569569
const WT_USTRING& format)
570570
{
571-
if (v.empty())
571+
if (!cpp17::any_has_value(v))
572572
return cpp17::any();
573573
else if (v.type() == type)
574574
return v;

src/Wt/WItemDelegate.C

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ std::unique_ptr<WWidget> WItemDelegate::update(WWidget *widget, const WModelInde
123123

124124
bool isNew = false;
125125

126-
bool haveCheckBox = index.isValid() ? !index.data(ItemDataRole::Checked).empty() : false;
127-
bool haveLink = index.isValid() ? !index.data(ItemDataRole::Link).empty() : false;
128-
bool haveIcon = index.isValid() ? !index.data(ItemDataRole::Decoration).empty(): false;
126+
bool haveCheckBox = index.isValid() ? cpp17::any_has_value(index.data(ItemDataRole::Checked)) : false;
127+
bool haveLink = index.isValid() ? cpp17::any_has_value(index.data(ItemDataRole::Link)) : false;
128+
bool haveIcon = index.isValid() ? cpp17::any_has_value(index.data(ItemDataRole::Decoration)): false;
129129
if (!(flags & ViewItemRenderFlag::Editing)) {
130130
if (widgetRef.w) {
131131
if (haveCheckBox != (checkBox(widgetRef, index, false) != 0) ||
@@ -155,7 +155,7 @@ std::unique_ptr<WWidget> WItemDelegate::update(WWidget *widget, const WModelInde
155155
}
156156

157157
cpp17::any checkedData = index.data(ItemDataRole::Checked);
158-
if (!checkedData.empty()) {
158+
if (cpp17::any_has_value(checkedData)) {
159159
CheckState state =
160160
(checkedData.type() == typeid(bool) ?
161161
(cpp17::any_cast<bool>(checkedData) ?
@@ -175,7 +175,7 @@ std::unique_ptr<WWidget> WItemDelegate::update(WWidget *widget, const WModelInde
175175
}
176176

177177
cpp17::any linkData = index.data(ItemDataRole::Link);
178-
if (!linkData.empty()) {
178+
if (cpp17::any_has_value(linkData)) {
179179
WLink link = cpp17::any_cast<WLink>(linkData);
180180
IndexAnchor *a = anchorWidget(widgetRef, index, true);
181181
a->setLink(link);

src/Wt/WItemSelectionModel.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::string WItemSelectionModel::mimeType()
5555
return std::string();
5656

5757
cpp17::any mimeTypeData = mi.data(ItemDataRole::MimeType);
58-
if (!mimeTypeData.empty()) {
58+
if (cpp17::any_has_value(mimeTypeData)) {
5959
std::string currentMimeType = asString(mimeTypeData).toUTF8();
6060

6161
if (!currentMimeType.empty()) {

0 commit comments

Comments
 (0)