8826f210da7ae102b9dc819d176a4f2c5194e310
[feed/telephony.git] / net / sipp / patches / 02-Fix_compatibility_with_older_C++_in_3.6.x_branch.patch
1 commit 626de652455a6c061d5a045fb226212c1f7eaeb5
2 Author: Walter Doekes <walter+github@wjd.nu>
3 Date: Fri Sep 18 09:56:40 2020 +0200
4
5 Fix compatibility with older C++ in 3.6.x branch
6
7 - no auto keyword (auto x = 1)
8 - no range based loop (for (*iter) : iterable)
9 - no std::to_string
10
11 diff --git a/CMakeLists.txt b/CMakeLists.txt
12 index 111c137..f1f815a 100644
13 --- a/CMakeLists.txt
14 +++ b/CMakeLists.txt
15 @@ -32,6 +32,7 @@ file(GLOB all_SRCS
16 "${PROJECT_SOURCE_DIR}/src/*.c"
17 )
18
19 +include(${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake)
20 include(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
21 include(${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
22 include(${CMAKE_ROOT}/Modules/CheckStructHasMember.cmake)
23 @@ -43,6 +44,10 @@ CHECK_STRUCT_HAS_MEMBER("struct udphdr" uh_sport "sys/types.h;netinet/udp.h" HA
24
25 CHECK_SYMBOL_EXISTS(le16toh "endian.h" HAVE_DECL_LE16TOH)
26 CHECK_SYMBOL_EXISTS(le16toh "sys/endian.h" HAVE_DECL_LE16TOH_BSD)
27 +CHECK_CXX_SOURCE_COMPILES("
28 +#include <string>
29 +int main() { std::to_string(1).c_str(); return 0; }
30 +" HAVE_STD_TOSTRING)
31
32 configure_file("${PROJECT_SOURCE_DIR}/include/config.h.in"
33 "${PROJECT_BINARY_DIR}/config.h" )
34 diff --git a/include/config.h.in b/include/config.h.in
35 index 8c22504..cf39ea1 100644
36 --- a/include/config.h.in
37 +++ b/include/config.h.in
38 @@ -1,5 +1,5 @@
39 /*--------------------------------------------------------------------------
40 - * This file is autogenerated from config.h.in
41 + * This file is autogenerated from include/config.h.in
42 * during the cmake configuration of your project. If you need to make changes
43 * edit the original file NOT THIS FILE.
44 * --------------------------------------------------------------------------*/
45 @@ -18,5 +18,6 @@
46 #endif
47 #cmakedefine HAVE_IP_COMPAT_H @HAVE_IP_COMPAT_H@
48 #cmakedefine HAVE_UDP_UH_PREFIX @HAVE_UDP_UH_PREFIX@
49 +#cmakedefine HAVE_STD_TOSTRING @HAVE_STD_TOSTRING@
50
51 #endif
52 diff --git a/include/screen.hpp b/include/screen.hpp
53 index 13a9708..37c8ddf 100644
54 --- a/include/screen.hpp
55 +++ b/include/screen.hpp
56 @@ -43,9 +43,12 @@ void print_statistics(int last);
57 extern int key_backspace;
58 extern int key_dc;
59
60 +typedef std::vector<std::string> string_array;
61 +
62 class ScreenPrinter {
63 public:
64 ScreenPrinter():
65 + M_last(false),
66 M_headless(!isatty(fileno(stdout)))
67 {};
68 void redraw();
69 @@ -63,9 +66,9 @@ private:
70 void draw_repartition_detailed(CStat::T_dynamicalRepartition * tabRepartition,
71 int sizeOfTab);
72
73 - std::vector<std::string> lines;
74 + string_array lines;
75
76 - bool M_last = false;
77 + bool M_last;
78 };
79
80 extern ScreenPrinter* sp;
81 diff --git a/include/sipp.hpp b/include/sipp.hpp
82 index 878c99f..b04a619 100644
83 --- a/include/sipp.hpp
84 +++ b/include/sipp.hpp
85 @@ -83,6 +83,18 @@
86 #include "ratetask.hpp"
87 #include "watchdog.hpp"
88
89 +/* Backwards compatibility */
90 +#ifndef HAVE_STD_TOSTRING
91 +#include <sstream>
92 +namespace std {
93 +template <typename T> string to_string(T value) {
94 + ostringstream os;
95 + os << value;
96 + return os.str();
97 +}
98 +}
99 +#endif
100 +
101 /*
102 * If this files is included in the Main, then extern definitions
103 * are removed, and the DEFVAL macro becomes '= value;'. Else
104 diff --git a/src/screen.cpp b/src/screen.cpp
105 index bbf9cd2..5521a44 100644
106 --- a/src/screen.cpp
107 +++ b/src/screen.cpp
108 @@ -83,15 +83,15 @@ void print_statistics(int last)
109 void ScreenPrinter::print_closing_stats() {
110 M_last = true;
111 get_lines();
112 - for (auto line : lines) {
113 - printf("%s\n", line.c_str());
114 + for (string_array::iterator it = lines.begin(); it != lines.end(); ++it) {
115 + printf("%s\n", (*it).c_str());
116 }
117
118 if (currentScreenToDisplay != DISPLAY_STAT_SCREEN) {
119 currentScreenToDisplay = DISPLAY_STAT_SCREEN;
120 get_lines();
121 - for (auto line : lines) {
122 - printf("%s\n", line.c_str());
123 + for (string_array::iterator it = lines.begin(); it != lines.end(); ++it) {
124 + printf("%s\n", (*it).c_str());
125 }
126 }
127
128 @@ -100,8 +100,8 @@ void ScreenPrinter::print_closing_stats() {
129 void ScreenPrinter::print_to_file(FILE* f)
130 {
131 get_lines();
132 - for (auto line : lines) {
133 - fprintf(f, "%s\n", line.c_str());
134 + for (string_array::iterator it = lines.begin(); it != lines.end(); ++it) {
135 + fprintf(f, "%s\n", (*it).c_str());
136 }
137 }
138
139 @@ -114,8 +114,8 @@ void ScreenPrinter::redraw()
140 if (!M_headless) {
141 get_lines();
142 erase();
143 - for (auto line : lines) {
144 - printw("%s\n", line.c_str());
145 + for (string_array::iterator it = lines.begin(); it != lines.end(); ++it) {
146 + printw("%s\n", (*it).c_str());
147 }
148
149 if (command_mode) {