cpp: add template_streamop generation with runtime/compiler test coverage
Add template_streamop support in the C++ generator so generated operator<< and printTo can target generic stream-like output types.
Keep default behavior unchanged when the option is not set (std::ostream signatures remain).
Add compiler/runtime coverage for template generation, friend declaration correctness, enums, and collection printing.
default:
```cpp
std::ostream& operator<<(std::ostream& out, const SimpleStruct& obj);
class SimpleStruct {
public:
void printTo(std::ostream& out) const;
};
```
with `template_streamop`:
```cpp
template <typename OStream_>
OStream_& operator<<(OStream_& out, const SimpleStruct& obj);
class SimpleStruct {
public:
template <typename OStream_>
void printTo(OStream_& out) const;
};
```
diff --git a/test/cpp/Makefile.am b/test/cpp/Makefile.am
index f2d07ec..720a4b3 100644
--- a/test/cpp/Makefile.am
+++ b/test/cpp/Makefile.am
@@ -28,7 +28,10 @@
gen-cpp-private/ThriftTest_types.cpp \
gen-cpp-private/ThriftTest_constants.cpp \
gen-cpp-enumclass/ThriftTest_types.cpp \
- gen-cpp-enumclass/ThriftTest_constants.cpp
+ gen-cpp-enumclass/ThriftTest_constants.cpp \
+ gen-cpp-templatestreamop/ThriftTest_types.cpp \
+ gen-cpp-templatestreamop/ThriftTest_types.tcc \
+ gen-cpp-templatestreamop/ThriftTest_constants.cpp
noinst_LTLIBRARIES = libtestgencpp.la libstresstestgencpp.la
nodist_libtestgencpp_la_SOURCES = \
@@ -51,7 +54,8 @@
noinst_LTLIBRARIES += \
libforwardsettertestgencpp.la \
libprivateoptonaltestgencpp.la \
- libenumclasstestgencpp.la
+ libenumclasstestgencpp.la \
+ libtemplatestreamoptestgencpp.la
nodist_libforwardsettertestgencpp_la_SOURCES = \
gen-cpp-forward/ThriftTest_types.cpp \
@@ -81,6 +85,16 @@
libenumclasstestgencpp_la_LIBADD = $(top_builddir)/lib/cpp/libthrift.la
+nodist_libtemplatestreamoptestgencpp_la_SOURCES = \
+ gen-cpp-templatestreamop/ThriftTest_types.cpp \
+ gen-cpp-templatestreamop/ThriftTest_types.h \
+ gen-cpp-templatestreamop/ThriftTest_types.tcc \
+ gen-cpp-templatestreamop/ThriftTest_constants.cpp \
+ gen-cpp-templatestreamop/ThriftTest_constants.h \
+ src/ThriftTest_extras.cpp
+
+libtemplatestreamoptestgencpp_la_LIBADD = $(top_builddir)/lib/cpp/libthrift.la
+
nodist_libstresstestgencpp_la_SOURCES = \
gen-cpp/StressTest_types.h \
gen-cpp/Service.cpp \
@@ -97,7 +111,8 @@
StressTestNonBlocking \
ForwardSetterTest \
PrivateOptionalTest \
- EnumClassTest
+ EnumClassTest \
+ TemplateStreamOpTest
# we currently do not run the testsuite, stop c++ server issue
# TESTS = \
@@ -162,6 +177,14 @@
libenumclasstestgencpp.la \
$(top_builddir)/lib/cpp/libthrift.la
+TemplateStreamOpTest_SOURCES = \
+ src/TemplateStreamOpTest.cpp
+
+TemplateStreamOpTest_CPPFLAGS = -Igen-cpp-templatestreamop $(AM_CPPFLAGS)
+TemplateStreamOpTest_LDADD = \
+ libtemplatestreamoptestgencpp.la \
+ $(top_builddir)/lib/cpp/libthrift.la
+
#
# Common thrift code generation rules
#
@@ -183,6 +206,11 @@
$(MKDIR_P) gen-cpp-enumclass
$(THRIFT) --gen cpp:pure_enums=enum_class -out gen-cpp-enumclass $<
+# Generate ThriftTest with template_streamop option
+gen-cpp-templatestreamop/ThriftTest_types.cpp gen-cpp-templatestreamop/ThriftTest_types.h gen-cpp-templatestreamop/ThriftTest_types.tcc gen-cpp-templatestreamop/ThriftTest_constants.cpp: $(top_srcdir)/test/ThriftTest.thrift $(THRIFT)
+ $(MKDIR_P) gen-cpp-templatestreamop
+ $(THRIFT) --gen cpp:template_streamop -out gen-cpp-templatestreamop $<
+
gen-cpp/Service.cpp: $(top_srcdir)/test/StressTest.thrift $(THRIFT)
$(THRIFT) --gen cpp $<
@@ -194,7 +222,7 @@
AM_LDFLAGS = $(BOOST_LDFLAGS) $(LIBEVENT_LDFLAGS) $(ZLIB_LIBS)
clean-local:
- $(RM) -r gen-cpp/ gen-cpp-forward/ gen-cpp-private/ gen-cpp-enumclass/
+ $(RM) -r gen-cpp/ gen-cpp-forward/ gen-cpp-private/ gen-cpp-enumclass/ gen-cpp-templatestreamop/
style-local:
$(CPPSTYLE_CMD)
@@ -209,4 +237,5 @@
src/StressTestNonBlocking.cpp \
src/ForwardSetterTest.cpp \
src/PrivateOptionalTest.cpp \
- src/EnumClassTest.cpp
+ src/EnumClassTest.cpp \
+ src/TemplateStreamOpTest.cpp