Skip to content

Commit 0fd1e78

Browse files
author
Mikhail Koviazin
authored
AVRO-4097: Replace boost::any with std::any; boost::tuple with std::tuple (#3256)
* AVRO-4097: [C++] replace boost::any with std::any Signed-off-by: Mikhail Koviazin <mikhail.koviazin@aiven.io> * AVRO-4097: [C++] replace boost::tuple with std::tuple Signed-off-by: Mikhail Koviazin <mikhail.koviazin@aiven.io> --------- Signed-off-by: Mikhail Koviazin <mikhail.koviazin@aiven.io>
1 parent 77540f6 commit 0fd1e78

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

lang/c++/impl/json/JsonDom.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ void Entity::ensureType(EntityType type) const {
145145

146146
String Entity::stringValue() const {
147147
ensureType(EntityType::String);
148-
return JsonParser::toStringValue(**boost::any_cast<std::shared_ptr<String>>(&value_));
148+
return JsonParser::toStringValue(**std::any_cast<std::shared_ptr<String>>(&value_));
149149
}
150150

151151
String Entity::bytesValue() const {
152152
ensureType(EntityType::String);
153-
return JsonParser::toBytesValue(**boost::any_cast<std::shared_ptr<String>>(&value_));
153+
return JsonParser::toBytesValue(**std::any_cast<std::shared_ptr<String>>(&value_));
154154
}
155155

156156
std::string Entity::toString() const {

lang/c++/impl/json/JsonDom.hh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef avro_json_JsonDom_hh__
2020
#define avro_json_JsonDom_hh__
2121

22+
#include <any>
2223
#include <cstdint>
2324
#include <iostream>
2425
#include <map>
@@ -27,7 +28,6 @@
2728
#include <vector>
2829

2930
#include "Config.hh"
30-
#include "boost/any.hpp"
3131

3232
namespace avro {
3333

@@ -67,7 +67,7 @@ inline std::ostream &operator<<(std::ostream &os, EntityType et) {
6767

6868
class AVRO_DECL Entity {
6969
EntityType type_;
70-
boost::any value_;
70+
std::any value_;
7171
size_t line_; // can't be const else noncopyable...
7272

7373
void ensureType(EntityType) const;
@@ -99,17 +99,17 @@ public:
9999

100100
Bool boolValue() const {
101101
ensureType(EntityType::Bool);
102-
return boost::any_cast<Bool>(value_);
102+
return std::any_cast<Bool>(value_);
103103
}
104104

105105
Long longValue() const {
106106
ensureType(EntityType::Long);
107-
return boost::any_cast<Long>(value_);
107+
return std::any_cast<Long>(value_);
108108
}
109109

110110
Double doubleValue() const {
111111
ensureType(EntityType::Double);
112-
return boost::any_cast<Double>(value_);
112+
return std::any_cast<Double>(value_);
113113
}
114114

115115
String stringValue() const;
@@ -118,12 +118,12 @@ public:
118118

119119
const Array &arrayValue() const {
120120
ensureType(EntityType::Arr);
121-
return **boost::any_cast<std::shared_ptr<Array>>(&value_);
121+
return **std::any_cast<std::shared_ptr<Array>>(&value_);
122122
}
123123

124124
const Object &objectValue() const {
125125
ensureType(EntityType::Obj);
126-
return **boost::any_cast<std::shared_ptr<Object>>(&value_);
126+
return **std::any_cast<std::shared_ptr<Object>>(&value_);
127127
}
128128

129129
std::string toString() const;

lang/c++/impl/parsing/Symbol.hh

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
#define avro_parsing_Symbol_hh__
2121

2222
#include <algorithm>
23+
#include <any>
2324
#include <map>
2425
#include <set>
2526
#include <sstream>
2627
#include <stack>
28+
#include <tuple>
2729
#include <utility>
2830
#include <vector>
2931

30-
#include <boost/any.hpp>
31-
#include <boost/tuple/tuple.hpp>
32-
3332
#include "Decoder.hh"
3433
#include "Exception.hh"
3534
#include "Node.hh"
@@ -39,10 +38,10 @@ namespace parsing {
3938

4039
class Symbol;
4140

42-
typedef std::vector<Symbol> Production;
43-
typedef std::shared_ptr<Production> ProductionPtr;
44-
typedef boost::tuple<std::stack<ssize_t>, bool, ProductionPtr, ProductionPtr> RepeaterInfo;
45-
typedef boost::tuple<ProductionPtr, ProductionPtr> RootInfo;
41+
using Production = std::vector<Symbol>;
42+
using ProductionPtr = std::shared_ptr<Production>;
43+
using RepeaterInfo = std::tuple<std::stack<ssize_t>, bool, ProductionPtr, ProductionPtr>;
44+
using RootInfo = std::tuple<ProductionPtr, ProductionPtr>;
4645

4746
class Symbol {
4847
public:
@@ -92,7 +91,7 @@ public:
9291

9392
private:
9493
Kind kind_;
95-
boost::any extra_;
94+
std::any extra_;
9695

9796
explicit Symbol(Kind k) : kind_(k) {}
9897
template<typename T>
@@ -105,17 +104,17 @@ public:
105104

106105
template<typename T>
107106
T extra() const {
108-
return boost::any_cast<T>(extra_);
107+
return std::any_cast<T>(extra_);
109108
}
110109

111110
template<typename T>
112111
T *extrap() {
113-
return boost::any_cast<T>(&extra_);
112+
return std::any_cast<T>(&extra_);
114113
}
115114

116115
template<typename T>
117116
const T *extrap() const {
118-
return boost::any_cast<T>(&extra_);
117+
return std::any_cast<T>(&extra_);
119118
}
120119

121120
template<typename T>
@@ -340,8 +339,8 @@ void fixup(Symbol &s, const std::map<T, ProductionPtr> &m,
340339
} break;
341340
case Symbol::Kind::Repeater: {
342341
const RepeaterInfo &ri = *s.extrap<RepeaterInfo>();
343-
fixup_internal(boost::tuples::get<2>(ri), m, seen);
344-
fixup_internal(boost::tuples::get<3>(ri), m, seen);
342+
fixup_internal(std::get<2>(ri), m, seen);
343+
fixup_internal(std::get<3>(ri), m, seen);
345344
} break;
346345
case Symbol::Kind::Placeholder: {
347346
typename std::map<T, std::shared_ptr<Production>>::const_iterator it =
@@ -419,7 +418,7 @@ public:
419418
} else {
420419
switch (s.kind()) {
421420
case Symbol::Kind::Root:
422-
append(boost::tuples::get<0>(*s.extrap<RootInfo>()));
421+
append(std::get<0>(*s.extrap<RootInfo>()));
423422
continue;
424423
case Symbol::Kind::Indirect: {
425424
ProductionPtr pp =
@@ -437,7 +436,7 @@ public:
437436
continue;
438437
case Symbol::Kind::Repeater: {
439438
auto *p = s.extrap<RepeaterInfo>();
440-
std::stack<ssize_t> &ns = boost::tuples::get<0>(*p);
439+
std::stack<ssize_t> &ns = std::get<0>(*p);
441440
if (ns.empty()) {
442441
throw Exception(
443442
"Empty item count stack in repeater advance");
@@ -447,7 +446,7 @@ public:
447446
"Zero item count in repeater advance");
448447
}
449448
--ns.top();
450-
append(boost::tuples::get<2>(*p));
449+
append(std::get<2>(*p));
451450
}
452451
continue;
453452
case Symbol::Kind::Error:
@@ -527,7 +526,7 @@ public:
527526
}
528527
Symbol &t2 = parsingStack.top();
529528
auto *p = t2.extrap<RepeaterInfo>();
530-
boost::tuples::get<0>(*p).push(n);
529+
std::get<0>(*p).push(n);
531530
continue;
532531
}
533532
case Symbol::Kind::ArrayEnd:
@@ -542,7 +541,7 @@ public:
542541
}
543542
Symbol &t2 = parsingStack.top();
544543
auto *p2 = t2.extrap<RepeaterInfo>();
545-
boost::tuples::get<0>(*p2).push(n);
544+
std::get<0>(*p2).push(n);
546545
continue;
547546
}
548547
case Symbol::Kind::MapEnd:
@@ -564,19 +563,19 @@ public:
564563
}
565564
case Symbol::Kind::Repeater: {
566565
auto *p = t.extrap<RepeaterInfo>();
567-
std::stack<ssize_t> &ns = boost::tuples::get<0>(*p);
566+
std::stack<ssize_t> &ns = std::get<0>(*p);
568567
if (ns.empty()) {
569568
throw Exception(
570569
"Empty item count stack in repeater skip");
571570
}
572571
ssize_t &n = ns.top();
573572
if (n == 0) {
574-
n = boost::tuples::get<1>(*p) ? d.arrayNext()
575-
: d.mapNext();
573+
n = std::get<1>(*p) ? d.arrayNext()
574+
: d.mapNext();
576575
}
577576
if (n != 0) {
578577
--n;
579-
append(boost::tuples::get<3>(*p));
578+
append(std::get<3>(*p));
580579
continue;
581580
} else {
582581
ns.pop();
@@ -680,7 +679,7 @@ public:
680679
Symbol &s = parsingStack.top();
681680
assertMatch(Symbol::Kind::Repeater, s.kind());
682681
auto *p = s.extrap<RepeaterInfo>();
683-
std::stack<ssize_t> &nn = boost::tuples::get<0>(*p);
682+
std::stack<ssize_t> &nn = std::get<0>(*p);
684683
nn.push(n);
685684
}
686685

@@ -689,7 +688,7 @@ public:
689688
Symbol &s = parsingStack.top();
690689
assertMatch(Symbol::Kind::Repeater, s.kind());
691690
auto *p = s.extrap<RepeaterInfo>();
692-
std::stack<ssize_t> &nn = boost::tuples::get<0>(*p);
691+
std::stack<ssize_t> &nn = std::get<0>(*p);
693692
if (nn.empty() || nn.top() != 0) {
694693
throw Exception("Wrong number of items");
695694
}
@@ -701,7 +700,7 @@ public:
701700
Symbol &s = parsingStack.top();
702701
assertMatch(Symbol::Kind::Repeater, s.kind());
703702
auto *p = s.extrap<RepeaterInfo>();
704-
std::stack<ssize_t> &ns = boost::tuples::get<0>(*p);
703+
std::stack<ssize_t> &ns = std::get<0>(*p);
705704
if (ns.empty()) {
706705
throw Exception("Incorrect number of items (empty)");
707706
}
@@ -770,7 +769,7 @@ public:
770769
parsingStack.pop();
771770
}
772771
Symbol &s = parsingStack.top();
773-
append(boost::tuples::get<0>(*s.extrap<RootInfo>()));
772+
append(std::get<0>(*s.extrap<RootInfo>()));
774773
}
775774
};
776775

@@ -790,8 +789,8 @@ inline std::ostream &operator<<(std::ostream &os, const Symbol &s) {
790789
case Symbol::Kind::Repeater: {
791790
const RepeaterInfo &ri = *s.extrap<RepeaterInfo>();
792791
os << '(' << Symbol::toString(s.kind())
793-
<< ' ' << *boost::tuples::get<2>(ri)
794-
<< ' ' << *boost::tuples::get<3>(ri)
792+
<< ' ' << *std::get<2>(ri)
793+
<< ' ' << *std::get<3>(ri)
795794
<< ')';
796795
} break;
797796
case Symbol::Kind::Indirect: {

0 commit comments

Comments
 (0)