Skip to content

Commit f251285

Browse files
committed
added Var::isBoolean() and fixed JSON stringifier
1 parent 65628a6 commit f251285

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

Foundation/include/Poco/Dynamic/Var.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ class Foundation_API Var
495495
/// Returns true if stored value is numeric.
496496
/// Returns false for numeric strings (e.g. "123" is string, not number)
497497

498+
bool isBoolean() const;
499+
/// Returns true if stored value is boolean.
500+
/// Returns false for boolean strings (e.g. "true" is string, not number)
501+
498502
bool isString() const;
499503
/// Returns true if stored value is std::string.
500504

@@ -825,6 +829,13 @@ inline bool Var::isNumeric() const
825829
}
826830

827831

832+
inline bool Var::isBoolean() const
833+
{
834+
VarHolder* pHolder = content();
835+
return pHolder ? pHolder->isBoolean() : false;
836+
}
837+
838+
828839
inline bool Var::isString() const
829840
{
830841
VarHolder* pHolder = content();

Foundation/include/Poco/Dynamic/VarHolder.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ class Foundation_API VarHolder
246246
/// Returns false. Must be properly overriden in a type
247247
/// specialization in order to suport the diagnostic.
248248

249+
virtual bool isBoolean() const;
250+
/// Returns false. Must be properly overriden in a type
251+
/// specialization in order to suport the diagnostic.
252+
249253
virtual bool isString() const;
250254
/// Returns false. Must be properly overriden in a type
251255
/// specialization in order to suport the diagnostic.
@@ -594,6 +598,12 @@ inline bool VarHolder::isNumeric() const
594598
}
595599

596600

601+
inline bool VarHolder::isBoolean() const
602+
{
603+
return false;
604+
}
605+
606+
597607
inline bool VarHolder::isString() const
598608
{
599609
return false;
@@ -782,6 +792,11 @@ class VarHolderImpl<Int8>: public VarHolder
782792
return std::numeric_limits<Int8>::is_specialized;
783793
}
784794

795+
bool isBoolean() const
796+
{
797+
return false;
798+
}
799+
785800
bool isString() const
786801
{
787802
return false;
@@ -921,6 +936,7 @@ class VarHolderImpl<Int16>: public VarHolder
921936
return std::numeric_limits<Int16>::is_specialized;
922937
}
923938

939+
924940
bool isString() const
925941
{
926942
return false;
@@ -1054,6 +1070,11 @@ class VarHolderImpl<Int32>: public VarHolder
10541070
return std::numeric_limits<Int32>::is_specialized;
10551071
}
10561072

1073+
bool isBoolean() const
1074+
{
1075+
return false;
1076+
}
1077+
10571078
bool isString() const
10581079
{
10591080
return false;
@@ -1202,6 +1223,11 @@ class VarHolderImpl<Int64>: public VarHolder
12021223
return std::numeric_limits<Int64>::is_specialized;
12031224
}
12041225

1226+
bool isBoolean() const
1227+
{
1228+
return false;
1229+
}
1230+
12051231
bool isString() const
12061232
{
12071233
return false;
@@ -1335,6 +1361,11 @@ class VarHolderImpl<UInt8>: public VarHolder
13351361
return std::numeric_limits<UInt8>::is_specialized;
13361362
}
13371363

1364+
bool isBoolean() const
1365+
{
1366+
return false;
1367+
}
1368+
13381369
bool isString() const
13391370
{
13401371
return false;
@@ -1468,6 +1499,11 @@ class VarHolderImpl<UInt16>: public VarHolder
14681499
return std::numeric_limits<UInt16>::is_specialized;
14691500
}
14701501

1502+
bool isBoolean() const
1503+
{
1504+
return false;
1505+
}
1506+
14711507
bool isString() const
14721508
{
14731509
return false;
@@ -1601,6 +1637,11 @@ class VarHolderImpl<UInt32>: public VarHolder
16011637
return std::numeric_limits<UInt32>::is_specialized;
16021638
}
16031639

1640+
bool isBoolean() const
1641+
{
1642+
return false;
1643+
}
1644+
16041645
bool isString() const
16051646
{
16061647
return false;
@@ -1755,6 +1796,11 @@ class VarHolderImpl<UInt64>: public VarHolder
17551796
return std::numeric_limits<UInt64>::is_specialized;
17561797
}
17571798

1799+
bool isBoolean() const
1800+
{
1801+
return false;
1802+
}
1803+
17581804
bool isString() const
17591805
{
17601806
return false;
@@ -1886,6 +1932,11 @@ class VarHolderImpl<bool>: public VarHolder
18861932
return std::numeric_limits<bool>::is_specialized;
18871933
}
18881934

1935+
bool isBoolean() const
1936+
{
1937+
return true;
1938+
}
1939+
18891940
bool isString() const
18901941
{
18911942
return false;
@@ -2020,6 +2071,11 @@ class VarHolderImpl<float>: public VarHolder
20202071
return std::numeric_limits<float>::is_specialized;
20212072
}
20222073

2074+
bool isBoolean() const
2075+
{
2076+
return false;
2077+
}
2078+
20232079
bool isString() const
20242080
{
20252081
return false;
@@ -2160,6 +2216,11 @@ class VarHolderImpl<double>: public VarHolder
21602216
return std::numeric_limits<double>::is_specialized;
21612217
}
21622218

2219+
bool isBoolean() const
2220+
{
2221+
return false;
2222+
}
2223+
21632224
bool isString() const
21642225
{
21652226
return false;
@@ -2291,6 +2352,11 @@ class VarHolderImpl<char>: public VarHolder
22912352
return std::numeric_limits<char>::is_specialized;
22922353
}
22932354

2355+
bool isBoolean() const
2356+
{
2357+
return false;
2358+
}
2359+
22942360
bool isString() const
22952361
{
22962362
return false;
@@ -2793,6 +2859,11 @@ class VarHolderImpl<long>: public VarHolder
27932859
return std::numeric_limits<long>::is_specialized;
27942860
}
27952861

2862+
bool isBoolean() const
2863+
{
2864+
return false;
2865+
}
2866+
27962867
bool isString() const
27972868
{
27982869
return false;
@@ -2926,6 +2997,11 @@ class VarHolderImpl<unsigned long>: public VarHolder
29262997
return std::numeric_limits<unsigned long>::is_specialized;
29272998
}
29282999

3000+
bool isBoolean() const
3001+
{
3002+
return false;
3003+
}
3004+
29293005
bool isString() const
29303006
{
29313007
return false;
@@ -3245,6 +3321,11 @@ class VarHolderImpl<DateTime>: public VarHolder
32453321
return false;
32463322
}
32473323

3324+
bool isBoolean() const
3325+
{
3326+
return false;
3327+
}
3328+
32483329
bool isString() const
32493330
{
32503331
return false;
@@ -3341,6 +3422,11 @@ class VarHolderImpl<LocalDateTime>: public VarHolder
33413422
return false;
33423423
}
33433424

3425+
bool isBoolean() const
3426+
{
3427+
return false;
3428+
}
3429+
33443430
bool isString() const
33453431
{
33463432
return false;
@@ -3437,6 +3523,11 @@ class VarHolderImpl<Timestamp>: public VarHolder
34373523
return false;
34383524
}
34393525

3526+
bool isBoolean() const
3527+
{
3528+
return false;
3529+
}
3530+
34403531
bool isString() const
34413532
{
34423533
return false;

JSON/src/Stringifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
5555
{
5656
out << "null";
5757
}
58+
else if ( any.isNumeric() || any.isBoolean() )
59+
{
60+
out << any.convert<std::string>();
61+
}
5862
else
5963
{
6064
std::string value = any.convert<std::string>();

0 commit comments

Comments
 (0)