THRIFT-4776:Modernize c++11 code by clang-tidy (#1732)
* use override
* use make_shared
* use emplace
* use range for
* fix error on MSVC
* replace boost functions with std functions
* fix static analyzer warnings
* check api return value
* initialize member
* check the return value of SSL_peek > 0
* add override
diff --git a/compiler/cpp/src/thrift/audit/t_audit.cpp b/compiler/cpp/src/thrift/audit/t_audit.cpp
index 4ae9a1f..fbce15c 100644
--- a/compiler/cpp/src/thrift/audit/t_audit.cpp
+++ b/compiler/cpp/src/thrift/audit/t_audit.cpp
@@ -54,18 +54,16 @@
const std::map<std::string, std::string>& newNamespaceMap = newProgram->get_all_namespaces();
const std::map<std::string, std::string>& oldNamespaceMap = oldProgram->get_all_namespaces();
- for(auto oldNamespaceMapIt = oldNamespaceMap.begin();
- oldNamespaceMapIt != oldNamespaceMap.end();
- oldNamespaceMapIt++)
+ for(const auto & oldNamespaceMapIt : oldNamespaceMap)
{
- auto newNamespaceMapIt = newNamespaceMap.find(oldNamespaceMapIt->first);
+ auto newNamespaceMapIt = newNamespaceMap.find(oldNamespaceMapIt.first);
if(newNamespaceMapIt == newNamespaceMap.end())
{
- thrift_audit_warning(1, "Language %s not found in new thrift file\n", (oldNamespaceMapIt->first).c_str());
+ thrift_audit_warning(1, "Language %s not found in new thrift file\n", (oldNamespaceMapIt.first).c_str());
}
- else if((newNamespaceMapIt->second) != oldNamespaceMapIt->second)
+ else if((newNamespaceMapIt->second) != oldNamespaceMapIt.second)
{
- thrift_audit_warning(1, "Namespace %s changed in new thrift file\n", (oldNamespaceMapIt->second).c_str());
+ thrift_audit_warning(1, "Namespace %s changed in new thrift file\n", (oldNamespaceMapIt.second).c_str());
}
}
}
@@ -73,15 +71,13 @@
void compare_enum_values(t_enum* newEnum,t_enum* oldEnum)
{
const std::vector<t_enum_value*>& oldEnumValues = oldEnum->get_constants();
- for(auto oldEnumValuesIt = oldEnumValues.begin();
- oldEnumValuesIt != oldEnumValues.end();
- oldEnumValuesIt++)
+ for(auto oldEnumValue : oldEnumValues)
{
- int enumValue = (*oldEnumValuesIt)->get_value();
+ int enumValue = oldEnumValue->get_value();
t_enum_value* newEnumValue = newEnum->get_constant_by_value(enumValue);
if(newEnumValue != nullptr)
{
- std::string enumName = (*oldEnumValuesIt)->get_name();
+ std::string enumName = oldEnumValue->get_name();
if(enumName != newEnumValue->get_name())
{
thrift_audit_warning(1, "Name of the value %d changed in enum %s\n", enumValue, oldEnum->get_name().c_str());
@@ -352,27 +348,23 @@
{
std::map<std::string, t_function*> newFunctionMap;
std::map<std::string, t_function*>::iterator newFunctionMapIt;
- for(auto newFunctionIt = newFunctionList.begin();
- newFunctionIt != newFunctionList.end();
- newFunctionIt++)
+ for(auto newFunctionIt : newFunctionList)
{
- newFunctionMap[(*newFunctionIt)->get_name()] = *newFunctionIt;
+ newFunctionMap[newFunctionIt->get_name()] = newFunctionIt;
}
- for(auto oldFunctionIt = oldFunctionList.begin();
- oldFunctionIt != oldFunctionList.end();
- oldFunctionIt++)
+ for(auto oldFunctionIt : oldFunctionList)
{
- newFunctionMapIt = newFunctionMap.find((*oldFunctionIt)->get_name());
+ newFunctionMapIt = newFunctionMap.find(oldFunctionIt->get_name());
if(newFunctionMapIt == newFunctionMap.end())
{
- thrift_audit_failure("New Thrift File has missing function %s\n",(*oldFunctionIt)->get_name().c_str());
+ thrift_audit_failure("New Thrift File has missing function %s\n",oldFunctionIt->get_name().c_str());
continue;
}
else
{
//Function is found in both thrift files. Compare return type and argument list
- compare_single_function(newFunctionMapIt->second, *oldFunctionIt);
+ compare_single_function(newFunctionMapIt->second, oldFunctionIt);
}
}
@@ -383,11 +375,9 @@
std::vector<t_service*>::const_iterator oldServiceIt;
std::map<std::string, t_service*> newServiceMap;
- for(auto newServiceIt = newServices.begin();
- newServiceIt != newServices.end();
- newServiceIt++)
+ for(auto newService : newServices)
{
- newServiceMap[(*newServiceIt)->get_name()] = *newServiceIt;
+ newServiceMap[newService->get_name()] = newService;
}
diff --git a/compiler/cpp/src/thrift/generate/t_as3_generator.cc b/compiler/cpp/src/thrift/generate/t_as3_generator.cc
index 41724fe..dd4d166 100644
--- a/compiler/cpp/src/thrift/generate/t_as3_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_as3_generator.cc
@@ -68,20 +68,20 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void print_const_value(std::ostream& out,
std::string name,
@@ -191,7 +191,7 @@
std::string function_signature(t_function* tfunction, std::string prefix = "");
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
- std::string get_enum_class_name(t_type* type);
+ std::string get_enum_class_name(t_type* type) override;
bool type_can_be_null(t_type* ttype) {
ttype = get_true_type(ttype);
@@ -2519,9 +2519,7 @@
bool is_first = true;
bool was_previous_char_upper = false;
- for (string::iterator iter = name.begin(); iter != name.end(); ++iter) {
- string::value_type character = (*iter);
-
+ for (char character : name) {
bool is_upper = isupper(character);
if (is_upper && !is_first && !was_previous_char_upper) {
diff --git a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
index 3060863..f1531cc 100644
--- a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
@@ -103,16 +103,16 @@
}
/* initialization and destruction */
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/* generation functions */
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_consts(vector<t_const*> consts);
- void generate_struct(t_struct* tstruct);
- void generate_service(t_service* tservice);
- void generate_xception(t_struct* tstruct);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_consts(vector<t_const*> consts) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_service(t_service* tservice) override;
+ void generate_xception(t_struct* tstruct) override;
private:
/* file streams */
@@ -253,15 +253,13 @@
if (!includes.empty()) {
f_types_ << "/* other thrift includes */" << endl;
- for (vector<t_program*>::const_iterator iter = includes.begin();
- iter != includes.end();
- ++iter) {
- const std::string& include_nspace = (*iter)->get_namespace("c_glib");
+ for (auto include : includes) {
+ const std::string& include_nspace = include->get_namespace("c_glib");
std::string include_nspace_prefix =
include_nspace.empty() ? "" : initial_caps_to_underscores(include_nspace) + "_";
f_types_ << "#include \"" << include_nspace_prefix
- << initial_caps_to_underscores((*iter)->get_name()) << "_types.h\"" << endl;
+ << initial_caps_to_underscores(include->get_name()) << "_types.h\"" << endl;
}
f_types_ << endl;
}
@@ -269,11 +267,11 @@
/* include custom headers */
const vector<string>& c_includes = program_->get_c_includes();
f_types_ << "/* custom thrift includes */" << endl;
- for (size_t i = 0; i < c_includes.size(); ++i) {
- if (c_includes[i][0] == '<') {
- f_types_ << "#include " << c_includes[i] << endl;
+ for (const auto & c_include : c_includes) {
+ if (c_include[0] == '<') {
+ f_types_ << "#include " << c_include << endl;
} else {
- f_types_ << "#include \"" << c_includes[i] << "\"" << endl;
+ f_types_ << "#include \"" << c_include << "\"" << endl;
}
}
f_types_ << endl;
diff --git a/compiler/cpp/src/thrift/generate/t_cl_generator.cc b/compiler/cpp/src/thrift/generate/t_cl_generator.cc
index 38807f4..ad7c0ef 100644
--- a/compiler/cpp/src/thrift/generate/t_cl_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_cl_generator.cc
@@ -70,15 +70,15 @@
copy_options_ = option_string;
}
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_typedef (t_typedef* ttypedef);
- void generate_enum (t_enum* tenum);
- void generate_const (t_const* tconst);
- void generate_struct (t_struct* tstruct);
- void generate_xception (t_struct* txception);
- void generate_service (t_service* tservice);
+ void generate_typedef (t_typedef* ttypedef) override;
+ void generate_enum (t_enum* tenum) override;
+ void generate_const (t_const* tconst) override;
+ void generate_struct (t_struct* tstruct) override;
+ void generate_xception (t_struct* txception) override;
+ void generate_service (t_service* tservice) override;
void generate_cl_struct (std::ostream& out, t_struct* tstruct, bool is_exception);
void generate_cl_struct_internal (std::ostream& out, t_struct* tstruct, bool is_exception);
void generate_exception_sig(std::ostream& out, t_function* f);
@@ -128,9 +128,9 @@
string f_types_name = program_dir + "/" + program_name_ + "-types.lisp";
string f_vars_name = program_dir + "/" + program_name_ + "-vars.lisp";
- f_types_.open(f_types_name.c_str());
+ f_types_.open(f_types_name);
f_types_ << cl_autogen_comment() << endl;
- f_vars_.open(f_vars_name.c_str());
+ f_vars_.open(f_vars_name);
f_vars_ << cl_autogen_comment() << endl;
package_def(f_types_);
@@ -139,7 +139,7 @@
if (!no_asd) {
string f_asd_name = program_dir + "/" + system_prefix + program_name_ + ".asd";
- f_asd_.open(f_asd_name.c_str());
+ f_asd_.open(f_asd_name);
f_asd_ << cl_autogen_comment() << endl;
asdf_def(f_asd_);
}
@@ -152,8 +152,8 @@
const vector<t_program*>& includes = program_->get_includes();
string result = "";
result += ":depends-on (:thrift";
- for (size_t i = 0; i < includes.size(); ++i) {
- result += " :" + system_prefix + underscore(includes[i]->get_name());
+ for (auto include : includes) {
+ result += " :" + system_prefix + underscore(include->get_name());
}
result += ")\n";
return result;
@@ -215,8 +215,8 @@
out << "(thrift:def-package :" << package();
if ( includes.size() > 0 ) {
out << " :use (";
- for (size_t i = 0; i < includes.size(); ++i) {
- out << " :" << includes[i]->get_name();
+ for (auto include : includes) {
+ out << " :" << include->get_name();
}
out << ")";
}
diff --git a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
index 617ba7e..dca3167 100644
--- a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
@@ -101,25 +101,25 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
void generate_enum_ostream_operator_decl(std::ostream& out, t_enum* tenum);
void generate_enum_ostream_operator(std::ostream& out, t_enum* tenum);
- void generate_forward_declaration(t_struct* tstruct);
- void generate_struct(t_struct* tstruct) { generate_cpp_struct(tstruct, false); }
- void generate_xception(t_struct* txception) { generate_cpp_struct(txception, true); }
+ void generate_forward_declaration(t_struct* tstruct) override;
+ void generate_struct(t_struct* tstruct) override { generate_cpp_struct(tstruct, false); }
+ void generate_xception(t_struct* txception) override { generate_cpp_struct(txception, true); }
void generate_cpp_struct(t_struct* tstruct, bool is_exception);
- void generate_service(t_service* tservice);
+ void generate_service(t_service* tservice) override;
void print_const_value(std::ostream& out, std::string name, t_type* type, t_const_value* value);
std::string render_const_value(std::ostream& out,
@@ -424,24 +424,24 @@
// Include other Thrift includes
const vector<t_program*>& includes = program_->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
- f_types_ << "#include \"" << get_include_prefix(*(includes[i])) << includes[i]->get_name()
+ for (auto include : includes) {
+ f_types_ << "#include \"" << get_include_prefix(*include) << include->get_name()
<< "_types.h\"" << endl;
// XXX(simpkins): If gen_templates_ is enabled, we currently assume all
// included files were also generated with templates enabled.
- f_types_tcc_ << "#include \"" << get_include_prefix(*(includes[i])) << includes[i]->get_name()
+ f_types_tcc_ << "#include \"" << get_include_prefix(*include) << include->get_name()
<< "_types.tcc\"" << endl;
}
f_types_ << endl;
// Include custom headers
const vector<string>& cpp_includes = program_->get_cpp_includes();
- for (size_t i = 0; i < cpp_includes.size(); ++i) {
- if (cpp_includes[i][0] == '<') {
- f_types_ << "#include " << cpp_includes[i] << endl;
+ for (const auto & cpp_include : cpp_includes) {
+ if (cpp_include[0] == '<') {
+ f_types_ << "#include " << cpp_include << endl;
} else {
- f_types_ << "#include \"" << cpp_includes[i] << "\"" << endl;
+ f_types_ << "#include \"" << cpp_include << "\"" << endl;
}
}
f_types_ << endl;
@@ -1238,7 +1238,6 @@
if (setters) {
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if (is_reference((*m_iter))) {
- std::string type = type_name((*m_iter)->get_type());
out << endl << indent() << "void " << tstruct->get_name() << "::__set_"
<< (*m_iter)->get_name() << "(::std::shared_ptr<"
<< type_name((*m_iter)->get_type(), false, false) << ">";
@@ -1538,9 +1537,7 @@
bool has_nonrequired_fields = false;
const vector<t_field*>& fields = tstruct->get_members();
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- t_field* tfield = *f_iter;
-
+ for (auto tfield : fields) {
if (tfield->get_req() != t_field::T_REQUIRED) {
has_nonrequired_fields = true;
}
diff --git a/compiler/cpp/src/thrift/generate/t_csharp_generator.cc b/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
index 6e99a3e..e4d99b2 100644
--- a/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
@@ -89,17 +89,17 @@
out_dir_base_ = "gen-csharp";
}
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_struct(t_struct* tstruct) override;
void generate_union(t_struct* tunion);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void generate_property(ostream& out, t_field* tfield, bool isPublic, bool generateIsset);
void generate_csharp_property(ostream& out,
t_field* tfield,
@@ -207,7 +207,7 @@
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
std::string prop_name(t_field* tfield, bool suppress_mapping = false);
- std::string get_enum_class_name(t_type* type);
+ std::string get_enum_class_name(t_type* type) override;
bool field_has_default(t_field* tfield) { return tfield->get_value() != NULL; }
diff --git a/compiler/cpp/src/thrift/generate/t_d_generator.cc b/compiler/cpp/src/thrift/generate/t_d_generator.cc
index df56cfc..56519e4 100644
--- a/compiler/cpp/src/thrift/generate/t_d_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_d_generator.cc
@@ -71,7 +71,7 @@
}
protected:
- virtual void init_generator() {
+ void init_generator() override {
// Make output directory
MKDIR(get_out_dir().c_str());
@@ -102,20 +102,20 @@
// Include type modules from other imported programs.
const vector<t_program*>& includes = program_->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
- f_types_ << "public import " << render_package(*(includes[i])) << includes[i]->get_name()
+ for (auto include : includes) {
+ f_types_ << "public import " << render_package(*include) << include->get_name()
<< "_types;" << endl;
}
if (!includes.empty())
f_types_ << endl;
}
- virtual void close_generator() {
+ void close_generator() override {
// Close output file
f_types_.close();
}
- virtual void generate_consts(std::vector<t_const*> consts) {
+ void generate_consts(std::vector<t_const*> consts) override {
if (!consts.empty()) {
string f_consts_name = package_dir_ + program_name_ + "_constants.d";
ofstream_with_content_based_conditional_update f_consts;
@@ -159,13 +159,13 @@
}
}
- virtual void generate_typedef(t_typedef* ttypedef) {
+ void generate_typedef(t_typedef* ttypedef) override {
this->emit_doc(ttypedef, f_types_);
f_types_ << indent() << "alias " << render_type_name(ttypedef->get_type()) << " "
<< ttypedef->get_symbolic() << ";" << endl << endl;
}
- virtual void generate_enum(t_enum* tenum) {
+ void generate_enum(t_enum* tenum) override {
vector<t_enum_value*> constants = tenum->get_constants();
this->emit_doc(tenum, f_types_);
@@ -188,15 +188,15 @@
f_types_ << endl;
}
- virtual void generate_struct(t_struct* tstruct) {
+ void generate_struct(t_struct* tstruct) override {
print_struct_definition(f_types_, tstruct, false);
}
- virtual void generate_xception(t_struct* txception) {
+ void generate_xception(t_struct* txception) override {
print_struct_definition(f_types_, txception, true);
}
- virtual void generate_service(t_service* tservice) {
+ void generate_service(t_service* tservice) override {
string svc_name = tservice->get_name();
// Service implementation file includes
diff --git a/compiler/cpp/src/thrift/generate/t_dart_generator.cc b/compiler/cpp/src/thrift/generate/t_dart_generator.cc
index c82d26c..fbbb9e6 100644
--- a/compiler/cpp/src/thrift/generate/t_dart_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_dart_generator.cc
@@ -121,25 +121,25 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
void export_class_to_library(string file_name, string class_name);
void generate_dart_library();
void generate_dart_pubspec();
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void print_const_value(std::ostream& out,
std::string name,
@@ -359,8 +359,8 @@
// add imports for included thrift files
const vector<t_program*>& includes = program_->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
- string include_name = find_library_name(includes[i]);
+ for (auto include : includes) {
+ string include_name = find_library_name(include);
string named_import = "t_" + include_name;
if (package_prefix_.empty()) {
imports += "import 'package:" + include_name + "/" + include_name + ".dart' as " + named_import + ";" + endl;
@@ -438,15 +438,15 @@
indent_down();
} else {
const vector<std::string> lines = split(pubspec_lib_, '|');
- for (size_t line_index = 0; line_index < lines.size(); line_index++) {
- indent(f_pubspec) << lines[line_index] << endl;
+ for (const auto & line : lines) {
+ indent(f_pubspec) << line << endl;
}
}
// add included thrift files as dependencies
const vector<t_program*>& includes = program_->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
- string include_name = find_library_name(includes[i]);
+ for (auto include : includes) {
+ string include_name = find_library_name(include);
indent(f_pubspec) << include_name << ":" << endl;
indent_up();
indent(f_pubspec) << "path: ../" << include_name << endl;
@@ -2432,9 +2432,7 @@
bool is_first = true;
bool was_previous_char_upper = false;
- for (string::iterator iter = name.begin(); iter != name.end(); ++iter) {
- string::value_type character = (*iter);
-
+ for (char character : name) {
bool is_upper = isupper(character);
if (is_upper && !is_first && !was_previous_char_upper) {
diff --git a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
index 737aa5a..505120e 100644
--- a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
@@ -89,17 +89,17 @@
escape_['\''] = "''";
}
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_forward_declaration(t_struct* tstruct);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_forward_declaration(t_struct* tstruct) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void generate_property(ostream& out, t_field* tfield, bool isPublic, bool is_xception);
void generate_property_writer_(ostream& out, t_field* tfield, bool isPublic);
@@ -343,7 +343,7 @@
void write_struct(std::string line);
void write_service(std::string line);
- virtual std::string autogen_comment() {
+ std::string autogen_comment() override {
return std::string("(**\n") + " * Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
+ " *\n" + " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
+ " *)\n";
@@ -757,9 +757,9 @@
string unitname, nsname;
const vector<t_program*>& includes = program_->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
- unitname = includes[i]->get_name();
- nsname = includes[i]->get_namespace("delphi");
+ for (auto include : includes) {
+ unitname = include->get_name();
+ nsname = include->get_namespace("delphi");
if ("" != nsname) {
unitname = normalize_name(nsname);
}
@@ -786,7 +786,7 @@
std::string f_name = get_out_dir() + "/" + unitname + ".pas";
ofstream_with_content_based_conditional_update f_all;
- f_all.open(f_name.c_str());
+ f_all.open(f_name);
f_all << autogen_comment() << endl;
generate_delphi_doc(f_all, program_);
diff --git a/compiler/cpp/src/thrift/generate/t_erl_generator.cc b/compiler/cpp/src/thrift/generate/t_erl_generator.cc
index d4fe12c..d331ecc 100644
--- a/compiler/cpp/src/thrift/generate/t_erl_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_erl_generator.cc
@@ -83,19 +83,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void generate_member_type(std::ostream& out, t_type* type);
void generate_member_value(std::ostream& out, t_type* type, t_const_value* value);
@@ -310,8 +310,8 @@
string t_erl_generator::render_includes() {
const vector<t_program*>& includes = program_->get_includes();
string result = "";
- for (size_t i = 0; i < includes.size(); ++i) {
- result += "-include(\"" + make_safe_for_module_name(includes[i]->get_name())
+ for (auto include : includes) {
+ result += "-include(\"" + make_safe_for_module_name(include->get_name())
+ "_types.hrl\").\n";
}
if (includes.size() > 0) {
diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index 11246f3..66bb653 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -105,19 +105,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
std::string render_const_value(t_type* type, t_const_value* value, const string& name, bool opt = false);
@@ -743,10 +743,10 @@
// Make output files
f_types_name_ = package_dir_ + "/" + program_name_ + ".go";
- f_types_.open(f_types_name_.c_str());
+ f_types_.open(f_types_name_);
f_consts_name_ = package_dir_ + "/" + program_name_ + "-consts.go";
- f_consts_.open(f_consts_name_.c_str());
+ f_consts_.open(f_consts_name_);
// Print header
f_types_ << go_autogen_comment() << go_package() << render_includes(false);
@@ -771,12 +771,12 @@
unused_protection = "";
string local_namespace = program_->get_namespace("go");
- for (size_t i = 0; i < includes.size(); ++i) {
- if (!local_namespace.empty() && local_namespace == includes[i]->get_namespace("go")) {
+ for (auto include : includes) {
+ if (!local_namespace.empty() && local_namespace == include->get_namespace("go")) {
continue;
}
- string go_module = get_real_go_module(includes[i]);
+ string go_module = get_real_go_module(include);
size_t found = 0;
for (size_t j = 0; j < go_module.size(); j++) {
// Import statement uses slashes ('/') in namespace
@@ -803,12 +803,12 @@
string unused_prot = "";
string local_namespace = program_->get_namespace("go");
- for (size_t i = 0; i < includes.size(); ++i) {
- if (!local_namespace.empty() && local_namespace == includes[i]->get_namespace("go")) {
+ for (auto include : includes) {
+ if (!local_namespace.empty() && local_namespace == include->get_namespace("go")) {
continue;
}
- string go_module = get_real_go_module(includes[i]);
+ string go_module = get_real_go_module(include);
size_t found = 0;
for (size_t j = 0; j < go_module.size(); j++) {
// Import statement uses slashes ('/') in namespace
@@ -1255,15 +1255,14 @@
bool is_args_or_result) {
out << publicize(type_name(tstruct), is_args_or_result) << "{";
const vector<t_field*>& members = tstruct->get_members();
- for (vector<t_field*>::const_iterator m_iter = members.begin(); m_iter != members.end();
- ++m_iter) {
- bool pointer_field = is_pointer_field(*m_iter);
+ for (auto member : members) {
+ bool pointer_field = is_pointer_field(member);
string publicized_name;
t_const_value* def_value;
- get_publicized_name_and_def_value(*m_iter, &publicized_name, &def_value);
- if (!pointer_field && def_value != NULL && !omit_initialization(*m_iter)) {
+ get_publicized_name_and_def_value(member, &publicized_name, &def_value);
+ if (!pointer_field && def_value != NULL && !omit_initialization(member)) {
out << endl << indent() << publicized_name << ": "
- << render_field_initial_value(*m_iter, (*m_iter)->get_name(), pointer_field) << ","
+ << render_field_initial_value(member, member->get_name(), pointer_field) << ","
<< endl;
}
}
diff --git a/compiler/cpp/src/thrift/generate/t_gv_generator.cc b/compiler/cpp/src/thrift/generate/t_gv_generator.cc
index 7f8301a..2c0acf9 100644
--- a/compiler/cpp/src/thrift/generate/t_gv_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_gv_generator.cc
@@ -67,17 +67,17 @@
/**
* Init and end of generator
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_service(t_service* tservice) override;
protected:
/**
diff --git a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
index 3b88c4d..13f2cd1 100644
--- a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
@@ -74,20 +74,20 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void print_const_value(std::ostream& out,
std::string name,
@@ -190,7 +190,7 @@
std::string function_signature_normal(t_function* tfunction);
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
- std::string get_enum_class_name(t_type* type);
+ std::string get_enum_class_name(t_type* type) override;
string generate_service_method_onsuccess(t_function* tfunction, bool as_type, bool omit_name);
void generate_service_method_signature_callback(t_function* tfunction, bool is_interface);
void generate_service_method_signature_normal(t_function* tfunction, bool is_interface);
@@ -2884,9 +2884,7 @@
bool is_first = true;
bool was_previous_char_upper = false;
- for (string::iterator iter = name.begin(); iter != name.end(); ++iter) {
- string::value_type character = (*iter);
-
+ for (char character : name) {
bool is_upper = isupper(character);
if (is_upper && !is_first && !was_previous_char_upper) {
diff --git a/compiler/cpp/src/thrift/generate/t_hs_generator.cc b/compiler/cpp/src/thrift/generate/t_hs_generator.cc
index 8f6d4b0..a59dee5 100644
--- a/compiler/cpp/src/thrift/generate/t_hs_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_hs_generator.cc
@@ -66,18 +66,18 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
string render_const_value(t_type* type, t_const_value* value);
@@ -261,8 +261,8 @@
"import qualified Thrift.Arbitraries as T\n"
"\n");
- for (size_t i = 0; i < includes.size(); ++i)
- result += "import qualified " + capitalize(includes[i]->get_name()) + "_Types\n";
+ for (auto include : includes)
+ result += "import qualified " + capitalize(include->get_name()) + "_Types\n";
if (includes.size() > 0)
result += "\n";
@@ -407,14 +407,13 @@
} else if (type->is_enum()) {
t_enum* tenum = (t_enum*)type;
vector<t_enum_value*> constants = tenum->get_constants();
- for (vector<t_enum_value*>::iterator c_iter = constants.begin(); c_iter != constants.end();
- ++c_iter) {
- int val = (*c_iter)->get_value();
+ for (auto & constant : constants) {
+ int val = constant->get_value();
if (val == value->get_integer()) {
t_program* prog = type->get_program();
if (prog != NULL && prog != program_)
out << capitalize(prog->get_name()) << "_Types.";
- out << capitalize((*c_iter)->get_name());
+ out << capitalize(constant->get_name());
break;
}
}
@@ -427,21 +426,18 @@
const map<t_const_value*, t_const_value*, t_const_value::value_compare>& val = value->get_map();
bool first = true;
- for (map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter = val.begin();
- v_iter != val.end();
- ++v_iter) {
+ for (auto v_iter : val) {
t_field* field = NULL;
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end();
- ++f_iter)
- if ((*f_iter)->get_name() == v_iter->first->get_string())
- field = (*f_iter);
+ for (auto f_iter : fields)
+ if (f_iter->get_name() == v_iter.first->get_string())
+ field = f_iter;
if (field == NULL)
- throw "type error: " + cname + " has no field " + v_iter->first->get_string();
+ throw "type error: " + cname + " has no field " + v_iter.first->get_string();
- string fname = v_iter->first->get_string();
- string const_value = render_const_value(field->get_type(), v_iter->second);
+ string fname = v_iter.first->get_string();
+ string const_value = render_const_value(field->get_type(), v_iter.second);
out << (first ? "" : ", ");
out << field_name(cname, fname) << " = ";
@@ -543,21 +539,20 @@
if (members.size() > 0) {
indent_up();
bool first = true;
- for (vector<t_field*>::const_iterator m_iter = members.begin(); m_iter != members.end();
- ++m_iter) {
+ for (auto member : members) {
if (first) {
indent(out) << "{ ";
first = false;
} else {
indent(out) << ", ";
}
- string mname = (*m_iter)->get_name();
+ string mname = member->get_name();
out << field_name(tname, mname) << " :: ";
- if ((*m_iter)->get_req() == t_field::T_OPTIONAL
- || ((t_type*)(*m_iter)->get_type())->is_xception()) {
+ if (member->get_req() == t_field::T_OPTIONAL
+ || ((t_type*)member->get_type())->is_xception()) {
out << "P.Maybe ";
}
- out << render_hs_type((*m_iter)->get_type(), true) << endl;
+ out << render_hs_type(member->get_type(), true) << endl;
}
indent(out) << "}";
indent_down();
@@ -571,9 +566,8 @@
indent(out) << "instance H.Hashable " << tname << " where" << endl;
indent_up();
indent(out) << "hashWithSalt salt record = salt";
- for (vector<t_field*>::const_iterator m_iter = members.begin(); m_iter != members.end();
- ++m_iter) {
- string mname = (*m_iter)->get_name();
+ for (auto member : members) {
+ string mname = member->get_name();
indent(out) << " `H.hashWithSalt` " << field_name(tname, mname) << " record";
}
indent(out) << endl;
@@ -600,8 +594,7 @@
indent_up();
indent_up();
bool first = true;
- for (vector<t_field*>::const_iterator m_iter = members.begin(); m_iter != members.end();
- ++m_iter) {
+ for (auto member : members) {
if (first) {
first = false;
out << " ";
@@ -609,8 +602,8 @@
indent(out) << "`M.ap`";
}
out << "(";
- if ((*m_iter)->get_req() == t_field::T_OPTIONAL
- || ((t_type*)(*m_iter)->get_type())->is_xception()) {
+ if (member->get_req() == t_field::T_OPTIONAL
+ || ((t_type*)member->get_type())->is_xception()) {
out << "M.liftM P.Just ";
}
out << "QC.arbitrary)" << endl;
@@ -625,15 +618,14 @@
indent(out) << " | P.otherwise = M.catMaybes" << endl;
indent_up();
first = true;
- for (vector<t_field*>::const_iterator m_iter = members.begin(); m_iter != members.end();
- ++m_iter) {
+ for (auto member : members) {
if (first) {
first = false;
indent(out) << "[ ";
} else {
indent(out) << ", ";
}
- string fname = field_name(tname, (*m_iter)->get_name());
+ string fname = field_name(tname, member->get_name());
out << "if obj == default_" << tname;
out << "{" << fname << " = " << fname << " obj} ";
out << "then P.Nothing ";
@@ -665,10 +657,10 @@
bool first = true;
// Generate deserialization code for known cases
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- int32_t key = (*f_iter)->get_key();
- string etype = type_to_enum((*f_iter)->get_type());
- string fname = (*f_iter)->get_name();
+ for (auto field : fields) {
+ int32_t key = field->get_key();
+ string etype = type_to_enum(field->get_type());
+ string fname = field->get_name();
if (first) {
first = false;
@@ -680,11 +672,11 @@
indent(out) << field_name(sname, fname) << " = ";
out << "P.maybe (";
- if ((*f_iter)->get_req() == t_field::T_REQUIRED) {
+ if (field->get_req() == t_field::T_REQUIRED) {
out << "P.error \"Missing required field: " << fname << "\"";
} else {
- if (((*f_iter)->get_req() == t_field::T_OPTIONAL
- || ((t_type*)(*f_iter)->get_type())->is_xception()) && (*f_iter)->get_value() == NULL) {
+ if ((field->get_req() == t_field::T_OPTIONAL
+ || ((t_type*)field->get_type())->is_xception()) && field->get_value() == NULL) {
out << "P.Nothing";
} else {
out << field_name(sname, fname) << " default_" << sname;
@@ -693,10 +685,10 @@
out << ") ";
out << "(\\(_," << val << ") -> ";
- if ((*f_iter)->get_req() == t_field::T_OPTIONAL
- || ((t_type*)(*f_iter)->get_type())->is_xception())
+ if (field->get_req() == t_field::T_OPTIONAL
+ || ((t_type*)field->get_type())->is_xception())
out << "P.Just ";
- generate_deserialize_field(out, *f_iter, val);
+ generate_deserialize_field(out, field, val);
out << ")";
out << " (Map.lookup (" << key << ") fields)";
}
@@ -733,8 +725,8 @@
// Get Exceptions
bool hasExn = false;
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if (((t_type*)(*f_iter)->get_type())->is_xception()) {
+ for (auto field : fields) {
+ if (((t_type*)field->get_type())->is_xception()) {
hasExn = true;
break;
}
@@ -745,19 +737,18 @@
out << endl;
indent(out) << "(let exns = M.catMaybes ";
indent_up();
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end();
- ++f_iter) {
- if (((t_type*)(*f_iter)->get_type())->is_xception()) {
+ for (auto field : fields) {
+ if (((t_type*)field->get_type())->is_xception()) {
if (isfirst) {
out << "[ ";
isfirst = false;
} else {
out << ", ";
}
- string mname = (*f_iter)->get_name();
- int32_t key = (*f_iter)->get_key();
+ string mname = field->get_name();
+ int32_t key = field->get_key();
out << "(\\" << v << " -> (" << key << ", (\"" << mname << "\",";
- generate_serialize_type(out, (*f_iter)->get_type(), v);
+ generate_serialize_type(out, field->get_type(), v);
out << "))) <$> " << field_name(name, mname) << " record";
}
}
@@ -774,7 +765,7 @@
out << "M.catMaybes" << endl;
// Get the Rest
isfirst = true;
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ for (auto field : fields) {
// Write field header
if (isfirst) {
indent(out) << "[ ";
@@ -782,19 +773,19 @@
} else {
indent(out) << ", ";
}
- string mname = (*f_iter)->get_name();
- int32_t key = (*f_iter)->get_key();
+ string mname = field->get_name();
+ int32_t key = field->get_key();
out << "(\\";
out << v << " -> ";
- if ((*f_iter)->get_req() != t_field::T_OPTIONAL
- && !((t_type*)(*f_iter)->get_type())->is_xception()) {
+ if (field->get_req() != t_field::T_OPTIONAL
+ && !((t_type*)field->get_type())->is_xception()) {
out << "P.Just ";
}
out << "(" << key << ", (\"" << mname << "\",";
- generate_serialize_type(out, (*f_iter)->get_type(), v);
+ generate_serialize_type(out, field->get_type(), v);
out << "))) ";
- if ((*f_iter)->get_req() != t_field::T_OPTIONAL
- && !((t_type*)(*f_iter)->get_type())->is_xception()) {
+ if (field->get_req() != t_field::T_OPTIONAL
+ && !((t_type*)field->get_type())->is_xception()) {
out << "$";
} else {
out << "<$>";
@@ -910,14 +901,14 @@
indent(out) << "typemap_" << name << " :: T.TypeMap" << endl;
indent(out) << "typemap_" << name << " = Map.fromList [";
bool first = true;
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- string mname = (*f_iter)->get_name();
+ for (auto field : fields) {
+ string mname = field->get_name();
if (!first) {
out << ",";
}
- t_type* type = get_true_type((*f_iter)->get_type());
- int32_t key = (*f_iter)->get_key();
+ t_type* type = get_true_type(field->get_type());
+ int32_t key = field->get_key();
out << "(" << key << ",(\"" << mname << "\"," << type_to_enum(type) << "))";
first = false;
}
@@ -937,19 +928,19 @@
indent(out) << fname << " = " << name << "{" << endl;
indent_up();
bool first = true;
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- string mname = (*f_iter)->get_name();
+ for (auto field : fields) {
+ string mname = field->get_name();
if (first) {
first = false;
} else {
out << "," << endl;
}
- t_type* type = get_true_type((*f_iter)->get_type());
- t_const_value* value = (*f_iter)->get_value();
+ t_type* type = get_true_type(field->get_type());
+ t_const_value* value = field->get_value();
indent(out) << field_name(name, mname) << " = ";
- if ((*f_iter)->get_req() == t_field::T_OPTIONAL
- || ((t_type*)(*f_iter)->get_type())->is_xception()) {
+ if (field->get_req() == t_field::T_OPTIONAL
+ || ((t_type*)field->get_type())->is_xception()) {
if (value == NULL) {
out << "P.Nothing";
} else {
@@ -1087,13 +1078,12 @@
indent(f_client_) << "write_" << argsname << " op (" << argsname << "{";
bool first = true;
- for (vector<t_field*>::const_iterator fld_iter = fields.begin(); fld_iter != fields.end();
- ++fld_iter) {
- string fieldname = (*fld_iter)->get_name();
+ for (auto field : fields) {
+ string fieldname = field->get_name();
f_client_ << (first ? "" : ",");
f_client_ << field_name(argsname, fieldname) << "=";
- if ((*fld_iter)->get_req() == t_field::T_OPTIONAL
- || ((t_type*)(*fld_iter)->get_type())->is_xception())
+ if (field->get_req() == t_field::T_OPTIONAL
+ || ((t_type*)field->get_type())->is_xception())
f_client_ << "P.Just ";
f_client_ << "arg_" << fieldname;
first = false;
@@ -1123,10 +1113,9 @@
t_struct* xs = (*f_iter)->get_xceptions();
const vector<t_field*>& xceptions = xs->get_members();
- for (vector<t_field*>::const_iterator x_iter = xceptions.begin(); x_iter != xceptions.end();
- ++x_iter) {
+ for (auto xception : xceptions) {
indent(f_client_) << "P.maybe (P.return ()) X.throw ("
- << field_name(resultname, (*x_iter)->get_name()) << " res)" << endl;
+ << field_name(resultname, xception->get_name()) << " res)" << endl;
}
if (!(*f_iter)->get_returntype()->is_void())
@@ -1499,11 +1488,11 @@
string result = "";
const vector<t_field*>& fields = tfunc->get_arglist()->get_members();
- for (vector<t_field*>::const_iterator f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if ((*f_iter)->get_req() == t_field::T_OPTIONAL
- || ((t_type*)(*f_iter)->get_type())->is_xception())
+ for (auto field : fields) {
+ if (field->get_req() == t_field::T_OPTIONAL
+ || ((t_type*)field->get_type())->is_xception())
result += "P.Maybe ";
- result += render_hs_type((*f_iter)->get_type(), options);
+ result += render_hs_type(field->get_type(), options);
result += " -> ";
}
diff --git a/compiler/cpp/src/thrift/generate/t_html_generator.cc b/compiler/cpp/src/thrift/generate/t_html_generator.cc
index 00c9a0a..b61a712 100644
--- a/compiler/cpp/src/thrift/generate/t_html_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_html_generator.cc
@@ -82,7 +82,7 @@
init_allowed__markup();
}
- void generate_program();
+ void generate_program() override;
void generate_program_toc();
void generate_program_toc_row(t_program* tprog);
void generate_program_toc_rows(t_program* tprog, std::vector<t_program*>& finished);
@@ -101,12 +101,12 @@
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_service(t_service* tservice);
- void generate_xception(t_struct* txception);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_service(t_service* tservice) override;
+ void generate_xception(t_struct* txception) override;
void print_doc(t_doc* tdoc);
int print_type(t_type* ttype);
@@ -140,16 +140,16 @@
*/
void t_html_generator::generate_program_toc_rows(t_program* tprog,
std::vector<t_program*>& finished) {
- for (vector<t_program*>::iterator iter = finished.begin(); iter != finished.end(); iter++) {
- if (tprog->get_path() == (*iter)->get_path()) {
+ for (auto & iter : finished) {
+ if (tprog->get_path() == iter->get_path()) {
return;
}
}
finished.push_back(tprog);
generate_program_toc_row(tprog);
vector<t_program*> includes = tprog->get_includes();
- for (vector<t_program*>::iterator iter = includes.begin(); iter != includes.end(); iter++) {
- generate_program_toc_rows(*iter, finished);
+ for (auto & include : includes) {
+ generate_program_toc_rows(include, finished);
}
}
@@ -176,9 +176,8 @@
+ "\">" + fn_name + "</a></li>";
fn_html.insert(pair<string, string>(fn_name, html));
}
- for (map<string, string>::iterator html_iter = fn_html.begin(); html_iter != fn_html.end();
- html_iter++) {
- f_out_ << html_iter->second << endl;
+ for (auto & html_iter : fn_html) {
+ f_out_ << html_iter.second << endl;
}
f_out_ << "</ul>" << endl;
}
@@ -220,9 +219,8 @@
data_types.insert(pair<string, string>(name, html));
}
}
- for (map<string, string>::iterator dt_iter = data_types.begin(); dt_iter != data_types.end();
- dt_iter++) {
- f_out_ << dt_iter->second << "<br/>" << endl;
+ for (auto & data_type : data_types) {
+ f_out_ << data_type.second << "<br/>" << endl;
}
f_out_ << "</td>" << endl << "<td>";
if (!tprog->get_consts().empty()) {
@@ -235,9 +233,8 @@
+ "</a></code>";
const_html.insert(pair<string, string>(name, html));
}
- for (map<string, string>::iterator con_iter = const_html.begin(); con_iter != const_html.end();
- con_iter++) {
- f_out_ << con_iter->second << "<br/>" << endl;
+ for (auto & con_iter : const_html) {
+ f_out_ << con_iter.second << "<br/>" << endl;
}
}
f_out_ << "</td>" << endl << "</tr>";
@@ -572,8 +569,8 @@
if (first_white != string::npos) {
tag_key.erase(first_white);
}
- for (std::string::size_type i = 0; i < tag_key.length(); ++i) {
- tag_key[i] = tolower(tag_key[i]);
+ for (char & i : tag_key) {
+ i = tolower(i);
}
if (allowed_markup.find(tag_key) != allowed_markup.end()) {
result << "<" << tag_content << ">";
diff --git a/compiler/cpp/src/thrift/generate/t_java_generator.cc b/compiler/cpp/src/thrift/generate/t_java_generator.cc
index 2c84551..2fb1f1a 100644
--- a/compiler/cpp/src/thrift/generate/t_java_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_java_generator.cc
@@ -122,21 +122,21 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_struct(t_struct* tstruct) override;
void generate_union(t_struct* tunion);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void print_const_value(std::ostream& out,
std::string name,
@@ -4652,9 +4652,7 @@
bool is_first = true;
bool was_previous_char_upper = false;
- for (string::iterator iter = name.begin(); iter != name.end(); ++iter) {
- string::value_type character = (*iter);
-
+ for (char character : name) {
bool is_upper = isupper(character);
if (is_upper && !is_first && !was_previous_char_upper) {
diff --git a/compiler/cpp/src/thrift/generate/t_javame_generator.cc b/compiler/cpp/src/thrift/generate/t_javame_generator.cc
index fa743ca..e1694ab 100644
--- a/compiler/cpp/src/thrift/generate/t_javame_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_javame_generator.cc
@@ -65,21 +65,21 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(std::vector<t_const*> consts);
+ void generate_consts(std::vector<t_const*> consts) override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_struct(t_struct* tstruct) override;
void generate_union(t_struct* tunion);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void print_const_value(std::ostream& out,
std::string name,
@@ -185,13 +185,13 @@
void generate_serialize_list_element(std::ostream& out, t_list* tlist, std::string iter);
- void generate_java_doc(std::ostream& out, t_field* field);
+ void generate_java_doc(std::ostream& out, t_field* field) override;
- void generate_java_doc(std::ostream& out, t_doc* tdoc);
+ void generate_java_doc(std::ostream& out, t_doc* tdoc) override;
- void generate_java_doc(std::ostream& out, t_function* tdoc);
+ void generate_java_doc(std::ostream& out, t_function* tdoc) override;
- void generate_java_docstring_comment(std::ostream& out, string contents);
+ void generate_java_docstring_comment(std::ostream& out, string contents) override;
void generate_deep_copy_container(std::ostream& out,
std::string source_name_p1,
@@ -221,7 +221,7 @@
std::string function_signature(t_function* tfunction, std::string prefix = "");
std::string argument_list(t_struct* tstruct, bool include_types = true);
std::string type_to_enum(t_type* ttype);
- std::string get_enum_class_name(t_type* type);
+ std::string get_enum_class_name(t_type* type) override;
void generate_struct_desc(ostream& out, t_struct* tstruct);
void generate_field_descs(ostream& out, t_struct* tstruct);
std::string box_type(t_type* type, string value);
@@ -2980,9 +2980,7 @@
bool is_first = true;
bool was_previous_char_upper = false;
- for (string::iterator iter = name.begin(); iter != name.end(); ++iter) {
- string::value_type character = (*iter);
-
+ for (char character : name) {
bool is_upper = isupper(character);
if (is_upper && !is_first && !was_previous_char_upper) {
diff --git a/compiler/cpp/src/thrift/generate/t_js_generator.cc b/compiler/cpp/src/thrift/generate/t_js_generator.cc
index e7f625c..af402a4 100644
--- a/compiler/cpp/src/thrift/generate/t_js_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_js_generator.cc
@@ -121,19 +121,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
std::string render_recv_throw(std::string var);
std::string render_recv_return(std::string var);
@@ -215,7 +215,7 @@
std::string type_to_enum(t_type* ttype);
std::string make_valid_nodeJs_identifier(std::string const& name);
- std::string autogen_comment() {
+ std::string autogen_comment() override {
return std::string("//\n") + "// Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
+ "//\n" + "// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
+ "//\n";
@@ -499,8 +499,8 @@
if (gen_node_) {
const vector<t_program*>& includes = program_->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
- result += js_const_type_ + make_valid_nodeJs_identifier(includes[i]->get_name()) + "_ttypes = require('./" + includes[i]->get_name()
+ for (auto include : includes) {
+ result += js_const_type_ + make_valid_nodeJs_identifier(include->get_name()) + "_ttypes = require('./" + include->get_name()
+ "_types');\n";
}
if (includes.size() > 0) {
@@ -521,8 +521,8 @@
return result;
}
const vector<t_program*>& includes = program_->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
- result += "import " + make_valid_nodeJs_identifier(includes[i]->get_name()) + "_ttypes = require('./" + includes[i]->get_name()
+ for (auto include : includes) {
+ result += "import " + make_valid_nodeJs_identifier(include->get_name()) + "_ttypes = require('./" + include->get_name()
+ "_types');\n";
}
if (includes.size() > 0) {
@@ -1440,8 +1440,8 @@
t_struct* exceptions = tfunction->get_xceptions();
if (exceptions) {
const vector<t_field*>& members = exceptions->get_members();
- for (vector<t_field*>::const_iterator it = members.begin(); it != members.end(); ++it) {
- t_type* t = get_true_type((*it)->get_type());
+ for (auto member : members) {
+ t_type* t = get_true_type(member->get_type());
if (t->is_xception()) {
if (!has_exception) {
has_exception = true;
@@ -1504,8 +1504,8 @@
indent(f_service_) << "if ((err === null || typeof err === 'undefined')";
if (has_exception) {
const vector<t_field*>& members = exceptions->get_members();
- for (vector<t_field*>::const_iterator it = members.begin(); it != members.end(); ++it) {
- t_type* t = get_true_type((*it)->get_type());
+ for (auto member : members) {
+ t_type* t = get_true_type(member->get_type());
if (t->is_xception()) {
f_service_ << " || err instanceof " << js_type_namespace(t->get_program()) << t->get_name();
}
diff --git a/compiler/cpp/src/thrift/generate/t_json_generator.cc b/compiler/cpp/src/thrift/generate/t_json_generator.cc
index cd53612..eb4ef79 100644
--- a/compiler/cpp/src/thrift/generate/t_json_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_json_generator.cc
@@ -68,23 +68,23 @@
out_dir_base_ = "gen-json";
}
- virtual ~t_json_generator() {}
+ ~t_json_generator() override = default;
/**
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_program();
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_program() override;
void generate_function(t_function* tfunc);
void generate_field(t_field* field);
- void generate_service(t_service* tservice);
- void generate_struct(t_struct* tstruct);
+ void generate_service(t_service* tservice) override;
+ void generate_struct(t_struct* tstruct) override;
private:
bool should_merge_includes_;
@@ -147,8 +147,8 @@
string t_json_generator::escape_json_string(const string& input) {
std::ostringstream ss;
- for (std::string::const_iterator iter = input.begin(); iter != input.end(); iter++) {
- switch (*iter) {
+ for (char iter : input) {
+ switch (iter) {
case '\\':
ss << "\\\\";
break;
@@ -174,7 +174,7 @@
ss << "\\t";
break;
default:
- ss << *iter;
+ ss << iter;
break;
}
}
@@ -267,8 +267,8 @@
if (ttype->annotations_.size() > 0) {
write_key_and("annotations");
start_object();
- for (map<string, string>::iterator it = ttype->annotations_.begin(); it != ttype->annotations_.end(); ++it) {
- write_key_and_string(it->first, it->second);
+ for (auto & annotation : ttype->annotations_) {
+ write_key_and_string(annotation.first, annotation.second);
}
end_object();
}
@@ -457,8 +457,8 @@
if (ttypedef->annotations_.size() > 0) {
write_key_and("annotations");
start_object();
- for (map<string, string>::iterator it = ttypedef->annotations_.begin(); it != ttypedef->annotations_.end(); ++it) {
- write_key_and_string(it->first, it->second);
+ for (auto & annotation : ttypedef->annotations_) {
+ write_key_and_string(annotation.first, annotation.second);
}
end_object();
}
@@ -564,8 +564,8 @@
if (tenum->annotations_.size() > 0) {
write_key_and("annotations");
start_object();
- for (map<string, string>::iterator it = tenum->annotations_.begin(); it != tenum->annotations_.end(); ++it) {
- write_key_and_string(it->first, it->second);
+ for (auto & annotation : tenum->annotations_) {
+ write_key_and_string(annotation.first, annotation.second);
}
end_object();
}
@@ -603,8 +603,8 @@
if (tstruct->annotations_.size() > 0) {
write_key_and("annotations");
start_object();
- for (map<string, string>::iterator it = tstruct->annotations_.begin(); it != tstruct->annotations_.end(); ++it) {
- write_key_and_string(it->first, it->second);
+ for (auto & annotation : tstruct->annotations_) {
+ write_key_and_string(annotation.first, annotation.second);
}
end_object();
}
@@ -643,8 +643,8 @@
if (tservice->annotations_.size() > 0) {
write_key_and("annotations");
start_object();
- for (map<string, string>::iterator it = tservice->annotations_.begin(); it != tservice->annotations_.end(); ++it) {
- write_key_and_string(it->first, it->second);
+ for (auto & annotation : tservice->annotations_) {
+ write_key_and_string(annotation.first, annotation.second);
}
end_object();
}
@@ -680,8 +680,8 @@
if (tfunc->annotations_.size() > 0) {
write_key_and("annotations");
start_object();
- for (map<string, string>::iterator it = tfunc->annotations_.begin(); it != tfunc->annotations_.end(); ++it) {
- write_key_and_string(it->first, it->second);
+ for (auto & annotation : tfunc->annotations_) {
+ write_key_and_string(annotation.first, annotation.second);
}
end_object();
}
@@ -726,8 +726,8 @@
if (field->annotations_.size() > 0) {
write_key_and("annotations");
start_object();
- for (map<string, string>::iterator it = field->annotations_.begin(); it != field->annotations_.end(); ++it) {
- write_key_and_string(it->first, it->second);
+ for (auto & annotation : field->annotations_) {
+ write_key_and_string(annotation.first, annotation.second);
}
end_object();
}
diff --git a/compiler/cpp/src/thrift/generate/t_lua_generator.cc b/compiler/cpp/src/thrift/generate/t_lua_generator.cc
index adee896..e6432c8 100644
--- a/compiler/cpp/src/thrift/generate/t_lua_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_lua_generator.cc
@@ -56,18 +56,18 @@
/**
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
std::string render_const_value(t_type* type, t_const_value* value);
@@ -149,7 +149,7 @@
std::string type_to_enum(t_type* ttype);
static std::string get_namespace(const t_program* program);
- std::string autogen_comment() {
+ std::string autogen_comment() override {
return std::string("--\n") + "-- Autogenerated by Thrift\n" + "--\n"
+ "-- DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" + "-- @"
"generated\n"
diff --git a/compiler/cpp/src/thrift/generate/t_netcore_generator.cc b/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
index 6f346a3..1a5c384 100644
--- a/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
@@ -2734,7 +2734,7 @@
void t_netcore_generator::prepare_member_name_mapping(void* scope, const vector<t_field*>& members, const string& structname)
{
// begin new scope
- member_mapping_scopes.push_back(member_mapping_scope());
+ member_mapping_scopes.emplace_back();
member_mapping_scope& active = member_mapping_scopes.back();
active.scope_member = scope;
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
index 8cb3027..593bb64 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
@@ -2719,7 +2719,7 @@
void t_netstd_generator::prepare_member_name_mapping(void* scope, const vector<t_field*>& members, const string& structname)
{
// begin new scope
- member_mapping_scopes.push_back(member_mapping_scope());
+ member_mapping_scopes.emplace_back();
member_mapping_scope& active = member_mapping_scopes.back();
active.scope_member = scope;
diff --git a/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc b/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc
index 0ec81ba..a3781e8 100644
--- a/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_ocaml_generator.cc
@@ -65,19 +65,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_program();
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_program() override;
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
std::string render_const_value(t_type* type, t_const_value* value);
bool struct_member_persistent(t_field* tmember);
diff --git a/compiler/cpp/src/thrift/generate/t_perl_generator.cc b/compiler/cpp/src/thrift/generate/t_perl_generator.cc
index 8924a76..80729cb 100644
--- a/compiler/cpp/src/thrift/generate/t_perl_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_perl_generator.cc
@@ -66,19 +66,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
std::string render_const_value(t_type* type, t_const_value* value);
@@ -152,7 +152,7 @@
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
- std::string autogen_comment() {
+ std::string autogen_comment() override {
return std::string("#\n") + "# Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
+ "#\n" + "# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" + "#\n";
}
diff --git a/compiler/cpp/src/thrift/generate/t_php_generator.cc b/compiler/cpp/src/thrift/generate/t_php_generator.cc
index 50a4415..79bd5a2 100644
--- a/compiler/cpp/src/thrift/generate/t_php_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_php_generator.cc
@@ -99,7 +99,7 @@
escape_['$'] = "\\$";
}
- virtual std::string indent_str() const {
+ std::string indent_str() const override {
return " ";
}
@@ -109,19 +109,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_consts(vector<t_const*> consts);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_consts(vector<t_const*> consts) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
std::string render_const_value(t_type* type, t_const_value* value);
@@ -284,9 +284,9 @@
}
// Transform the java-style namespace into a path.
- for (std::string::iterator it = ns.begin(); it != ns.end(); ++it) {
- if (*it == '.') {
- *it = '/';
+ for (char & n : ns) {
+ if (n == '.') {
+ n = '/';
}
}
@@ -304,8 +304,8 @@
vector<string> x = split(str, '_');
- for (size_t i = 0; i < x.size(); ++i) {
- classe = classe + capitalize(x[i]);
+ for (const auto & i : x) {
+ classe = classe + capitalize(i);
}
return classe;
@@ -420,8 +420,8 @@
vector<string> NSx = split(php_namespace_suffix(get_program()), '\\');
package_dir_ = get_out_dir();
- for (size_t i = 0; i < NSx.size(); ++i) {
- package_dir_ = package_dir_ + "/" + NSx[i] + "/";
+ for (const auto & i : NSx) {
+ package_dir_ = package_dir_ + "/" + i + "/";
MKDIR(package_dir_.c_str());
}
diff --git a/compiler/cpp/src/thrift/generate/t_py_generator.cc b/compiler/cpp/src/thrift/generate/t_py_generator.cc
index e46207a..c16d6d3 100644
--- a/compiler/cpp/src/thrift/generate/t_py_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_py_generator.cc
@@ -136,7 +136,7 @@
}
}
- virtual std::string indent_str() const {
+ std::string indent_str() const override {
return " ";
}
@@ -144,20 +144,20 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_forward_declaration(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_forward_declaration(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
std::string render_const_value(t_type* type, t_const_value* value);
@@ -335,7 +335,7 @@
std::string module_;
protected:
- virtual std::set<std::string> lang_keywords() const {
+ std::set<std::string> lang_keywords() const override {
std::string keywords[] = { "False", "None", "True", "and", "as", "assert", "break", "class",
"continue", "def", "del", "elif", "else", "except", "exec", "finally", "for", "from",
"global", "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass", "print",
@@ -415,8 +415,8 @@
string t_py_generator::render_includes() {
const vector<t_program*>& includes = program_->get_includes();
string result = "";
- for (size_t i = 0; i < includes.size(); ++i) {
- result += "import " + get_real_py_module(includes[i], gen_twisted_, package_prefix_) + ".ttypes\n";
+ for (auto include : includes) {
+ result += "import " + get_real_py_module(include, gen_twisted_, package_prefix_) + ".ttypes\n";
}
return result;
}
@@ -2607,7 +2607,7 @@
string signature = tfunction->get_name() + "(";
if (!(gen_zope_interface_ && interface)) {
- pre.push_back("self");
+ pre.emplace_back("self");
}
signature += argument_list(tfunction->get_arglist(), &pre, &post) + ")";
diff --git a/compiler/cpp/src/thrift/generate/t_rb_generator.cc b/compiler/cpp/src/thrift/generate/t_rb_generator.cc
index 13ea249..61c3481 100644
--- a/compiler/cpp/src/thrift/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_rb_generator.cc
@@ -102,21 +102,21 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_forward_declaration(t_struct* tstruct);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_forward_declaration(t_struct* tstruct) override;
void generate_union(t_struct* tunion);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
t_rb_ofstream& render_const_value(t_rb_ofstream& out, t_type* type, t_const_value* value);
@@ -307,15 +307,15 @@
string t_rb_generator::render_includes() {
const vector<t_program*>& includes = program_->get_includes();
string result = "";
- for (size_t i = 0; i < includes.size(); ++i) {
+ for (auto include : includes) {
if (namespaced_) {
- t_program* included = includes[i];
+ t_program* included = include;
std::string included_require_prefix
= rb_namespace_to_path_prefix(included->get_namespace("rb"));
std::string included_name = included->get_name();
result += "require '" + included_require_prefix + underscore(included_name) + "_types'\n";
} else {
- result += "require '" + underscore(includes[i]->get_name()) + "_types'\n";
+ result += "require '" + underscore(include->get_name()) + "_types'\n";
}
}
if (includes.size() > 0) {
@@ -763,8 +763,8 @@
}
void t_rb_generator::begin_namespace(t_rb_ofstream& out, vector<std::string> modules) {
- for (vector<std::string>::iterator m_iter = modules.begin(); m_iter != modules.end(); ++m_iter) {
- out.indent() << "module " << *m_iter << endl;
+ for (auto & module : modules) {
+ out.indent() << "module " << module << endl;
out.indent_up();
}
}
@@ -1140,8 +1140,8 @@
string t_rb_generator::full_type_name(const t_type* ttype) {
string prefix = "::";
vector<std::string> modules = ruby_modules(ttype->get_program());
- for (vector<std::string>::iterator m_iter = modules.begin(); m_iter != modules.end(); ++m_iter) {
- prefix += *m_iter + "::";
+ for (auto & module : modules) {
+ prefix += module + "::";
}
return prefix + type_name(ttype);
}
diff --git a/compiler/cpp/src/thrift/generate/t_rs_generator.cc b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
index 9843d7a..fdf6861 100644
--- a/compiler/cpp/src/thrift/generate/t_rs_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_rs_generator.cc
@@ -74,19 +74,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
private:
// struct type
@@ -3285,8 +3285,8 @@
string t_rs_generator::rust_enum_variant_name(const string &name) {
bool all_uppercase = true;
- for (size_t i = 0; i < name.size(); i++) {
- if (isalnum(name[i]) && islower(name[i])) {
+ for (char i : name) {
+ if (isalnum(i) && islower(i)) {
all_uppercase = false;
break;
}
diff --git a/compiler/cpp/src/thrift/generate/t_st_generator.cc b/compiler/cpp/src/thrift/generate/t_st_generator.cc
index 595a949..bc95feb 100644
--- a/compiler/cpp/src/thrift/generate/t_st_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_st_generator.cc
@@ -71,19 +71,19 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_const(t_const* tconst);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_const(t_const* tconst) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void generate_class_side_definition();
void generate_force_consts();
@@ -233,9 +233,9 @@
string cat = program_->get_namespace("smalltalk.category");
// For compatibility with the Thrift grammar, the category must
// be punctuated by dots. Replaces them with dashes here.
- for (string::iterator iter = cat.begin(); iter != cat.end(); ++iter) {
- if (*iter == '.') {
- *iter = '-';
+ for (char & iter : cat) {
+ if (iter == '.') {
+ iter = '-';
}
}
return cat.size() ? cat : "Generated-" + class_name();
diff --git a/compiler/cpp/src/thrift/generate/t_swift_generator.cc b/compiler/cpp/src/thrift/generate/t_swift_generator.cc
index 31db04d..eb746c1 100644
--- a/compiler/cpp/src/thrift/generate/t_swift_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_swift_generator.cc
@@ -94,20 +94,20 @@
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
- void generate_consts(vector<t_const*> consts);
+ void generate_consts(vector<t_const*> consts) override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
+ void generate_struct(t_struct* tstruct) override;
+ void generate_xception(t_struct* txception) override;
+ void generate_service(t_service* tservice) override;
void render_const_value(ostream& out,
@@ -336,7 +336,7 @@
string t_swift_generator::swift_imports() {
vector<string> includes_list;
- includes_list.push_back("Foundation");
+ includes_list.emplace_back("Foundation");
ostringstream includes;
@@ -347,8 +347,8 @@
if (namespaced_) {
const vector<t_program*>& program_includes = program_->get_includes();
- for (size_t i = 0; i < program_includes.size(); ++i) {
- includes << ("import " + get_real_swift_module(program_includes[i])) << endl;
+ for (auto program_include : program_includes) {
+ includes << ("import " + get_real_swift_module(program_include)) << endl;
}
}
includes << endl;
@@ -364,10 +364,10 @@
string t_swift_generator::swift_thrift_imports() {
vector<string> includes_list;
- includes_list.push_back("Thrift");
+ includes_list.emplace_back("Thrift");
if (gen_cocoa_ && promise_kit_) {
- includes_list.push_back("PromiseKit");
+ includes_list.emplace_back("PromiseKit");
}
ostringstream includes;
diff --git a/compiler/cpp/src/thrift/generate/t_xml_generator.cc b/compiler/cpp/src/thrift/generate/t_xml_generator.cc
index 35fed14..b669293 100644
--- a/compiler/cpp/src/thrift/generate/t_xml_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_xml_generator.cc
@@ -79,20 +79,20 @@
out_dir_base_ = "gen-xml";
}
- virtual ~t_xml_generator() {}
+ ~t_xml_generator() override = default;
- void init_generator();
- void close_generator();
- void generate_program();
+ void init_generator() override;
+ void close_generator() override;
+ void generate_program() override;
void iterate_program(t_program* program);
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override;
void generate_function(t_function* tfunc);
void generate_field(t_field* field);
- void generate_service(t_service* tservice);
- void generate_struct(t_struct* tstruct);
+ void generate_service(t_service* tservice) override;
+ void generate_struct(t_struct* tstruct) override;
void generate_annotations(std::map<std::string, std::string> annotations);
@@ -245,8 +245,8 @@
string t_xml_generator::escape_xml_string(const string& input) {
std::ostringstream ss;
- for (std::string::const_iterator iter = input.begin(); iter != input.end(); iter++) {
- switch (*iter) {
+ for (char iter : input) {
+ switch (iter) {
case '&':
ss << "&";
break;
@@ -263,7 +263,7 @@
ss << ">";
break;
default:
- ss << *iter;
+ ss << iter;
break;
}
}
diff --git a/compiler/cpp/src/thrift/generate/t_xsd_generator.cc b/compiler/cpp/src/thrift/generate/t_xsd_generator.cc
index e487ffc..379e5a4 100644
--- a/compiler/cpp/src/thrift/generate/t_xsd_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_xsd_generator.cc
@@ -59,24 +59,24 @@
out_dir_base_ = "gen-xsd";
}
- virtual ~t_xsd_generator() {}
+ ~t_xsd_generator() override = default;
/**
* Init and close methods
*/
- void init_generator();
- void close_generator();
+ void init_generator() override;
+ void close_generator() override;
/**
* Program-level generation functions
*/
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum) { (void)tenum; }
+ void generate_typedef(t_typedef* ttypedef) override;
+ void generate_enum(t_enum* tenum) override { (void)tenum; }
- void generate_service(t_service* tservice);
- void generate_struct(t_struct* tstruct);
+ void generate_service(t_service* tservice) override;
+ void generate_struct(t_struct* tstruct) override;
private:
void generate_element(std::ostream& out,
diff --git a/compiler/cpp/src/thrift/main.cc b/compiler/cpp/src/thrift/main.cc
index adcab83..5b69dc5 100644
--- a/compiler/cpp/src/thrift/main.cc
+++ b/compiler/cpp/src/thrift/main.cc
@@ -983,11 +983,11 @@
// Oooohh, recursive code generation, hot!!
if (gen_recurse) {
const vector<t_program*>& includes = program->get_includes();
- for (size_t i = 0; i < includes.size(); ++i) {
+ for (auto include : includes) {
// Propagate output path from parent to child programs
- includes[i]->set_out_path(program->get_out_path(), program->is_out_path_absolute());
+ include->set_out_path(program->get_out_path(), program->is_out_path_absolute());
- generate(includes[i], generator_strings);
+ generate(include, generator_strings);
}
}
@@ -1110,7 +1110,7 @@
fprintf(stderr, "Missing generator specification\n");
usage();
}
- generator_strings.push_back(arg);
+ generator_strings.emplace_back(arg);
} else if (strcmp(arg, "-I") == 0) {
// An argument of "-I\ asdf" is invalid and has unknown results
arg = argv[++i];
@@ -1119,7 +1119,7 @@
fprintf(stderr, "Missing Include directory\n");
usage();
}
- g_incl_searchpath.push_back(arg);
+ g_incl_searchpath.emplace_back(arg);
} else if ((strcmp(arg, "-o") == 0) || (strcmp(arg, "-out") == 0)) {
out_path_is_absolute = (strcmp(arg, "-out") == 0) ? true : false;
arg = argv[++i];
diff --git a/compiler/cpp/src/thrift/parse/t_program.h b/compiler/cpp/src/thrift/parse/t_program.h
index 8b60611..13cb26e 100644
--- a/compiler/cpp/src/thrift/parse/t_program.h
+++ b/compiler/cpp/src/thrift/parse/t_program.h
@@ -286,7 +286,6 @@
if (language != "*") {
size_t sub_index = language.find('.');
std::string base_language = language.substr(0, sub_index);
- std::string sub_namespace;
if (base_language == "smalltalk") {
pwarning(1, "Namespace 'smalltalk' is deprecated. Use 'st' instead");
diff --git a/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp b/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp
index 952394b..0dac524 100644
--- a/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp
+++ b/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp
@@ -17,10 +17,11 @@
* under the License.
*/
-#include <thrift/async/TConcurrentClientSyncInfo.h>
-#include <thrift/TApplicationException.h>
-#include <thrift/transport/TTransportException.h>
#include <limits>
+#include <memory>
+#include <thrift/TApplicationException.h>
+#include <thrift/async/TConcurrentClientSyncInfo.h>
+#include <thrift/transport/TTransportException.h>
namespace apache { namespace thrift { namespace async {
@@ -140,15 +141,15 @@
{
wakeupSomeone_ = true;
stop_ = true;
- for(auto i = seqidToMonitorMap_.begin(); i != seqidToMonitorMap_.end(); ++i)
- i->second->notify();
+ for(auto & i : seqidToMonitorMap_)
+ i.second->notify();
}
TConcurrentClientSyncInfo::MonitorPtr
TConcurrentClientSyncInfo::newMonitor_(const Guard &)
{
if(freeMonitors_.empty())
- return MonitorPtr(new Monitor(&readMutex_));
+ return std::make_shared<Monitor>(&readMutex_);
MonitorPtr retval;
//swapping to avoid an atomic operation
retval.swap(freeMonitors_.back());
diff --git a/lib/cpp/src/thrift/concurrency/ThreadFactory.cpp b/lib/cpp/src/thrift/concurrency/ThreadFactory.cpp
index 941b993..becb3b2 100644
--- a/lib/cpp/src/thrift/concurrency/ThreadFactory.cpp
+++ b/lib/cpp/src/thrift/concurrency/ThreadFactory.cpp
@@ -27,7 +27,7 @@
namespace concurrency {
std::shared_ptr<Thread> ThreadFactory::newThread(std::shared_ptr<Runnable> runnable) const {
- std::shared_ptr<Thread> result = std::shared_ptr<Thread>(new Thread(isDetached(), runnable));
+ std::shared_ptr<Thread> result = std::make_shared<Thread>(isDetached(), runnable);
runnable->thread(result);
return result;
}
diff --git a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
index c889660..25b838a 100644
--- a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
+++ b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
@@ -344,7 +344,7 @@
std::set<shared_ptr<Thread> > newThreads;
for (size_t ix = 0; ix < value; ix++) {
shared_ptr<ThreadManager::Worker> worker
- = shared_ptr<ThreadManager::Worker>(new ThreadManager::Worker(this));
+ = std::make_shared<ThreadManager::Worker>(this);
newThreads.insert(threadFactory_->newThread(worker));
}
@@ -352,13 +352,12 @@
workerMaxCount_ += value;
workers_.insert(newThreads.begin(), newThreads.end());
- for (auto ix = newThreads.begin(); ix != newThreads.end();
- ++ix) {
+ for (const auto & newThread : newThreads) {
shared_ptr<ThreadManager::Worker> worker
- = dynamic_pointer_cast<ThreadManager::Worker, Runnable>((*ix)->runnable());
+ = dynamic_pointer_cast<ThreadManager::Worker, Runnable>(newThread->runnable());
worker->state_ = ThreadManager::Worker::STARTING;
- (*ix)->start();
- idMap_.insert(std::pair<const Thread::id_t, shared_ptr<Thread> >((*ix)->getId(), *ix));
+ newThread->start();
+ idMap_.insert(std::pair<const Thread::id_t, shared_ptr<Thread> >(newThread->getId(), newThread));
}
while (workerCount_ != workerMaxCount_) {
@@ -430,17 +429,15 @@
workerMonitor_.wait();
}
- for (auto ix = deadWorkers_.begin();
- ix != deadWorkers_.end();
- ++ix) {
+ for (const auto & deadWorker : deadWorkers_) {
// when used with a joinable thread factory, we join the threads as we remove them
if (!threadFactory_->isDetached()) {
- (*ix)->join();
+ deadWorker->join();
}
- idMap_.erase((*ix)->getId());
- workers_.erase(*ix);
+ idMap_.erase(deadWorker->getId());
+ workers_.erase(deadWorker);
}
deadWorkers_.clear();
@@ -480,7 +477,7 @@
}
}
- tasks_.push_back(shared_ptr<ThreadManager::Task>(new ThreadManager::Task(value, expiration)));
+ tasks_.push_back(std::make_shared<ThreadManager::Task>(value, expiration));
// If idle thread is available notify it, otherwise all worker threads are
// running and will get around to this task in time.
diff --git a/lib/cpp/src/thrift/concurrency/TimerManager.cpp b/lib/cpp/src/thrift/concurrency/TimerManager.cpp
index df59900..003f564 100644
--- a/lib/cpp/src/thrift/concurrency/TimerManager.cpp
+++ b/lib/cpp/src/thrift/concurrency/TimerManager.cpp
@@ -22,6 +22,7 @@
#include <assert.h>
#include <iostream>
+#include <memory>
#include <set>
namespace apache {
@@ -121,10 +122,8 @@
}
}
- for (auto ix = expiredTasks.begin();
- ix != expiredTasks.end();
- ++ix) {
- (*ix)->run();
+ for (const auto & expiredTask : expiredTasks) {
+ expiredTask->run();
}
} while (manager_->state_ == TimerManager::STARTED);
@@ -152,7 +151,7 @@
TimerManager::TimerManager()
: taskCount_(0),
state_(TimerManager::UNINITIALIZED),
- dispatcher_(shared_ptr<Dispatcher>(new Dispatcher(this))) {
+ dispatcher_(std::make_shared<Dispatcher>(this)) {
}
#if defined(_MSC_VER)
diff --git a/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp b/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp
index 35592f0..28d0da2 100644
--- a/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp
+++ b/lib/cpp/src/thrift/protocol/TJSONProtocol.cpp
@@ -20,8 +20,6 @@
#include <thrift/protocol/TJSONProtocol.h>
#include <boost/locale.hpp>
-#include <boost/math/special_functions/fpclassify.hpp>
-#include <boost/math/special_functions/sign.hpp>
#include <cmath>
#include <limits>
@@ -537,9 +535,9 @@
std::string val;
bool special = false;
- switch (boost::math::fpclassify(num)) {
+ switch (std::fpclassify(num)) {
case FP_INFINITE:
- if (boost::math::signbit(num)) {
+ if (std::signbit(num)) {
val = kThriftNegativeInfinity;
} else {
val = kThriftInfinity;
diff --git a/lib/cpp/src/thrift/protocol/TJSONProtocol.h b/lib/cpp/src/thrift/protocol/TJSONProtocol.h
index 020e61c..420995e 100644
--- a/lib/cpp/src/thrift/protocol/TJSONProtocol.h
+++ b/lib/cpp/src/thrift/protocol/TJSONProtocol.h
@@ -248,7 +248,7 @@
class LookaheadReader {
public:
- LookaheadReader(TTransport& trans) : trans_(&trans), hasData_(false) {}
+ LookaheadReader(TTransport& trans) : trans_(&trans), hasData_(false), data_(0) {}
uint8_t read() {
if (hasData_) {
diff --git a/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp b/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp
index 78c3b39..1537fc6 100644
--- a/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp
+++ b/lib/cpp/src/thrift/qt/TQIODeviceTransport.cpp
@@ -46,7 +46,7 @@
}
}
-bool TQIODeviceTransport::isOpen() {
+bool TQIODeviceTransport::isOpen() const {
return dev_->isOpen();
}
diff --git a/lib/cpp/src/thrift/qt/TQIODeviceTransport.h b/lib/cpp/src/thrift/qt/TQIODeviceTransport.h
index e0cdd18..a3b511d 100644
--- a/lib/cpp/src/thrift/qt/TQIODeviceTransport.h
+++ b/lib/cpp/src/thrift/qt/TQIODeviceTransport.h
@@ -40,7 +40,7 @@
~TQIODeviceTransport() override;
void open() override;
- bool isOpen();
+ bool isOpen() const override;
bool peek() override;
void close() override;
diff --git a/lib/cpp/src/thrift/qt/TQTcpServer.cpp b/lib/cpp/src/thrift/qt/TQTcpServer.cpp
index bd39893..0404482 100644
--- a/lib/cpp/src/thrift/qt/TQTcpServer.cpp
+++ b/lib/cpp/src/thrift/qt/TQTcpServer.cpp
@@ -90,7 +90,7 @@
}
ctxMap_[connection.get()]
- = shared_ptr<ConnectionContext>(new ConnectionContext(connection, transport, iprot, oprot));
+ = std::make_shared<ConnectionContext>(connection, transport, iprot, oprot);
connect(connection.get(), SIGNAL(readyRead()), SLOT(beginDecode()));
diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp
index 4e62324..eea0427 100644
--- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp
@@ -1074,8 +1074,8 @@
void TNonblockingServer::stop() {
// Breaks the event loop in all threads so that they end ASAP.
- for (uint32_t i = 0; i < ioThreads_.size(); ++i) {
- ioThreads_[i]->stop();
+ for (auto & ioThread : ioThreads_) {
+ ioThread->stop();
}
}
@@ -1162,10 +1162,13 @@
bool useHighPriority)
: server_(server),
number_(number),
+ threadId_{},
listenSocket_(listenSocket),
useHighPriority_(useHighPriority),
eventBase_(nullptr),
- ownEventBase_(false) {
+ ownEventBase_(false),
+ serverEvent_{},
+ notificationEvent_{} {
notificationPipeFDs_[0] = -1;
notificationPipeFDs_[1] = -1;
}
@@ -1186,13 +1189,13 @@
listenSocket_ = THRIFT_INVALID_SOCKET;
}
- for (int i = 0; i < 2; ++i) {
- if (notificationPipeFDs_[i] >= 0) {
- if (0 != ::THRIFT_CLOSESOCKET(notificationPipeFDs_[i])) {
+ for (auto notificationPipeFD : notificationPipeFDs_) {
+ if (notificationPipeFD >= 0) {
+ if (0 != ::THRIFT_CLOSESOCKET(notificationPipeFD)) {
GlobalOutput.perror("TNonblockingIOThread notificationPipe close(): ",
THRIFT_GET_SOCKET_ERROR);
}
- notificationPipeFDs_[i] = THRIFT_INVALID_SOCKET;
+ notificationPipeFD = THRIFT_INVALID_SOCKET;
}
}
}
@@ -1208,13 +1211,13 @@
::THRIFT_CLOSESOCKET(notificationPipeFDs_[1]);
throw TException("TNonblockingServer::createNotificationPipe() THRIFT_O_NONBLOCK");
}
- for (int i = 0; i < 2; ++i) {
+ for (auto notificationPipeFD : notificationPipeFDs_) {
#if LIBEVENT_VERSION_NUMBER < 0x02000000
int flags;
- if ((flags = THRIFT_FCNTL(notificationPipeFDs_[i], F_GETFD, 0)) < 0
- || THRIFT_FCNTL(notificationPipeFDs_[i], F_SETFD, flags | FD_CLOEXEC) < 0) {
+ if ((flags = THRIFT_FCNTL(notificationPipeFD, F_GETFD, 0)) < 0
+ || THRIFT_FCNTL(notificationPipeFD, F_SETFD, flags | FD_CLOEXEC) < 0) {
#else
- if (evutil_make_socket_closeonexec(notificationPipeFDs_[i]) < 0) {
+ if (evutil_make_socket_closeonexec(notificationPipeFD) < 0) {
#endif
::THRIFT_CLOSESOCKET(notificationPipeFDs_[0]);
::THRIFT_CLOSESOCKET(notificationPipeFDs_[1]);
diff --git a/lib/cpp/src/thrift/transport/TBufferTransports.h b/lib/cpp/src/thrift/transport/TBufferTransports.h
index a008fa1..df06586 100644
--- a/lib/cpp/src/thrift/transport/TBufferTransports.h
+++ b/lib/cpp/src/thrift/transport/TBufferTransports.h
@@ -217,7 +217,7 @@
void open() override { transport_->open(); }
- bool isOpen() { return transport_->isOpen(); }
+ bool isOpen() const override { return transport_->isOpen(); }
bool peek() override {
if (rBase_ == rBound_) {
@@ -345,7 +345,7 @@
void open() override { transport_->open(); }
- bool isOpen() { return transport_->isOpen(); }
+ bool isOpen() const override { return transport_->isOpen(); }
bool peek() override { return (rBase_ < rBound_) || transport_->peek(); }
@@ -550,7 +550,7 @@
}
}
- bool isOpen() { return true; }
+ bool isOpen() const override { return true; }
bool peek() override { return (rBase_ < wBase_); }
diff --git a/lib/cpp/src/thrift/transport/TFDTransport.h b/lib/cpp/src/thrift/transport/TFDTransport.h
index ede5ccb..a3cf519 100644
--- a/lib/cpp/src/thrift/transport/TFDTransport.h
+++ b/lib/cpp/src/thrift/transport/TFDTransport.h
@@ -53,7 +53,7 @@
}
}
- bool isOpen() { return fd_ >= 0; }
+ bool isOpen() const override { return fd_ >= 0; }
void open() override {}
diff --git a/lib/cpp/src/thrift/transport/TFileTransport.cpp b/lib/cpp/src/thrift/transport/TFileTransport.cpp
index 1eefb89..53e5136 100644
--- a/lib/cpp/src/thrift/transport/TFileTransport.cpp
+++ b/lib/cpp/src/thrift/transport/TFileTransport.cpp
@@ -977,7 +977,7 @@
inputTransport_(inputTransport) {
// default the output transport to a null transport (common case)
- outputTransport_ = shared_ptr<TNullTransport>(new TNullTransport());
+ outputTransport_ = std::make_shared<TNullTransport>();
}
TFileProcessor::TFileProcessor(shared_ptr<TProcessor> processor,
@@ -990,7 +990,7 @@
inputTransport_(inputTransport) {
// default the output transport to a null transport (common case)
- outputTransport_ = shared_ptr<TNullTransport>(new TNullTransport());
+ outputTransport_ = std::make_shared<TNullTransport>();
}
TFileProcessor::TFileProcessor(shared_ptr<TProcessor> processor,
diff --git a/lib/cpp/src/thrift/transport/THttpTransport.h b/lib/cpp/src/thrift/transport/THttpTransport.h
index 1cf36b2..75f0d8c 100644
--- a/lib/cpp/src/thrift/transport/THttpTransport.h
+++ b/lib/cpp/src/thrift/transport/THttpTransport.h
@@ -42,7 +42,7 @@
void open() override { transport_->open(); }
- bool isOpen() { return transport_->isOpen(); }
+ bool isOpen() const override { return transport_->isOpen(); }
bool peek() override { return transport_->peek(); }
diff --git a/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp b/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
index 51990b0..9902b90 100644
--- a/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
@@ -20,6 +20,7 @@
#include <thrift/thrift-config.h>
#include <cstring>
+#include <memory>
#include <stdexcept>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
@@ -532,7 +533,7 @@
}
shared_ptr<TSocket> TNonblockingServerSocket::createSocket(THRIFT_SOCKET clientSocket) {
- return shared_ptr<TSocket>(new TSocket(clientSocket));
+ return std::make_shared<TSocket>(clientSocket);
}
void TNonblockingServerSocket::close() {
diff --git a/lib/cpp/src/thrift/transport/TPipeServer.cpp b/lib/cpp/src/thrift/transport/TPipeServer.cpp
index 55c3580..47d8822 100644
--- a/lib/cpp/src/thrift/transport/TPipeServer.cpp
+++ b/lib/cpp/src/thrift/transport/TPipeServer.cpp
@@ -333,8 +333,22 @@
SetEntriesInAcl(1, &ea, NULL, &acl);
PSECURITY_DESCRIPTOR sd = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
- InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(sd, TRUE, acl, FALSE);
+ if (!InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION)) {
+ auto lastError = GetLastError();
+ LocalFree(sd);
+ LocalFree(acl);
+ GlobalOutput.perror("TPipeServer::InitializeSecurityDescriptor() GLE=", lastError);
+ throw TTransportException(TTransportException::NOT_OPEN, "InitializeSecurityDescriptor() failed",
+ lastError);
+ }
+ if (!SetSecurityDescriptorDacl(sd, TRUE, acl, FALSE)) {
+ auto lastError = GetLastError();
+ LocalFree(sd);
+ LocalFree(acl);
+ GlobalOutput.perror("TPipeServer::SetSecurityDescriptorDacl() GLE=", lastError);
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "SetSecurityDescriptorDacl() failed", lastError);
+ }
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
@@ -353,7 +367,7 @@
0, // client time-out
&sa)); // security attributes
- DWORD lastError = GetLastError();
+ auto lastError = GetLastError();
LocalFree(sd);
LocalFree(acl);
FreeSid(everyone_sid);
@@ -364,7 +378,6 @@
throw TTransportException(TTransportException::NOT_OPEN,
"TCreateNamedPipe() failed",
lastError);
- return false;
}
Pipe_.reset(hPipe.release());
@@ -375,8 +388,17 @@
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; // security information for pipes
- InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(&sd, true, NULL, false);
+ if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
+ {
+ GlobalOutput.perror("TPipeServer InitializeSecurityDescriptor (anon) failed, GLE=", GetLastError());
+ return false;
+ }
+ if (!SetSecurityDescriptorDacl(&sd, true, NULL, false))
+ {
+ GlobalOutput.perror("TPipeServer SetSecurityDescriptorDacl (anon) failed, GLE=",
+ GetLastError());
+ return false;
+ }
sa.lpSecurityDescriptor = &sd;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true; // allow passing handle to child
diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.cpp b/lib/cpp/src/thrift/transport/TSSLSocket.cpp
index 636bb2d..b413002 100644
--- a/lib/cpp/src/thrift/transport/TSSLSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSSLSocket.cpp
@@ -19,9 +19,10 @@
#include <thrift/thrift-config.h>
-#include <errno.h>
-#include <string>
#include <cstring>
+#include <errno.h>
+#include <memory>
+#include <string>
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
@@ -266,7 +267,7 @@
eventSafe_ = false;
}
-bool TSSLSocket::isOpen() {
+bool TSSLSocket::isOpen() const {
if (ssl_ == nullptr || !TSocket::isOpen()) {
return false;
}
@@ -291,11 +292,10 @@
if (!checkHandshake())
throw TSSLException("SSL_peek: Handshake is not completed");
int rc;
- uint8_t byte;
do {
+ uint8_t byte;
rc = SSL_peek(ssl_, &byte, 1);
if (rc < 0) {
-
int errno_copy = THRIFT_GET_SOCKET_ERROR;
int error = SSL_get_error(ssl_, rc);
switch (error) {
@@ -318,6 +318,8 @@
} else if (rc == 0) {
ERR_clear_error();
break;
+ } else {
+ break;
}
} while (true);
return (rc > 0);
@@ -857,7 +859,7 @@
randomize();
}
count_++;
- ctx_ = std::shared_ptr<SSLContext>(new SSLContext(protocol));
+ ctx_ = std::make_shared<SSLContext>(protocol);
}
TSSLSocketFactory::~TSSLSocketFactory() {
diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.h b/lib/cpp/src/thrift/transport/TSSLSocket.h
index 4d46998..87a9601 100644
--- a/lib/cpp/src/thrift/transport/TSSLSocket.h
+++ b/lib/cpp/src/thrift/transport/TSSLSocket.h
@@ -73,7 +73,7 @@
/**
* TTransport interface.
*/
- bool isOpen();
+ bool isOpen() const override;
bool peek() override;
void open() override;
void close() override;
diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp
index 1732c82..ece0544 100644
--- a/lib/cpp/src/thrift/transport/TServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp
@@ -20,6 +20,7 @@
#include <thrift/thrift-config.h>
#include <cstring>
+#include <memory>
#include <stdexcept>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
@@ -641,9 +642,9 @@
shared_ptr<TSocket> TServerSocket::createSocket(THRIFT_SOCKET clientSocket) {
if (interruptableChildren_) {
- return shared_ptr<TSocket>(new TSocket(clientSocket, pChildInterruptSockReader_));
+ return std::make_shared<TSocket>(clientSocket, pChildInterruptSockReader_);
} else {
- return shared_ptr<TSocket>(new TSocket(clientSocket));
+ return std::make_shared<TSocket>(clientSocket);
}
}
diff --git a/lib/cpp/src/thrift/transport/TShortReadTransport.h b/lib/cpp/src/thrift/transport/TShortReadTransport.h
index 2151606..185c78d 100644
--- a/lib/cpp/src/thrift/transport/TShortReadTransport.h
+++ b/lib/cpp/src/thrift/transport/TShortReadTransport.h
@@ -41,7 +41,7 @@
TShortReadTransport(std::shared_ptr<TTransport> transport, double full_prob)
: transport_(transport), fullProb_(full_prob) {}
- bool isOpen() { return transport_->isOpen(); }
+ bool isOpen() const override { return transport_->isOpen(); }
bool peek() override { return transport_->peek(); }
diff --git a/lib/cpp/src/thrift/transport/TSocketPool.cpp b/lib/cpp/src/thrift/transport/TSocketPool.cpp
index 89eee6e..b6e79d3 100644
--- a/lib/cpp/src/thrift/transport/TSocketPool.cpp
+++ b/lib/cpp/src/thrift/transport/TSocketPool.cpp
@@ -21,6 +21,7 @@
#include <algorithm>
#include <iostream>
+#include <memory>
#if __cplusplus >= 201703L
#include <random>
#endif
@@ -94,8 +95,8 @@
maxConsecutiveFailures_(1),
randomize_(true),
alwaysTryLast_(true) {
- for (unsigned i = 0; i < servers.size(); ++i) {
- addServer(servers[i].first, servers[i].second);
+ for (const auto & server : servers) {
+ addServer(server.first, server.second);
}
}
@@ -129,7 +130,7 @@
}
void TSocketPool::addServer(const string& host, int port) {
- servers_.push_back(shared_ptr<TSocketPoolServer>(new TSocketPoolServer(host, port)));
+ servers_.push_back(std::make_shared<TSocketPoolServer>(host, port));
}
void TSocketPool::addServer(shared_ptr<TSocketPoolServer>& server) {
diff --git a/lib/cpp/src/thrift/transport/TTransportUtils.h b/lib/cpp/src/thrift/transport/TTransportUtils.h
index 6cff76a..28c93d2 100644
--- a/lib/cpp/src/thrift/transport/TTransportUtils.h
+++ b/lib/cpp/src/thrift/transport/TTransportUtils.h
@@ -46,7 +46,7 @@
~TNullTransport() override = default;
- bool isOpen() { return true; }
+ bool isOpen() const override { return true; }
void open() override {}
diff --git a/lib/cpp/src/thrift/transport/TZlibTransport.cpp b/lib/cpp/src/thrift/transport/TZlibTransport.cpp
index ddceb99..437190b 100644
--- a/lib/cpp/src/thrift/transport/TZlibTransport.cpp
+++ b/lib/cpp/src/thrift/transport/TZlibTransport.cpp
@@ -110,7 +110,7 @@
delete wstream_;
}
-bool TZlibTransport::isOpen() {
+bool TZlibTransport::isOpen() const {
return (readAvail() > 0) || (rstream_->avail_in > 0) || transport_->isOpen();
}
@@ -131,7 +131,7 @@
// In standalone objects, we set input_ended_ to true when inflate returns
// Z_STREAM_END. This allows to make sure that a checksum was verified.
-inline int TZlibTransport::readAvail() {
+inline int TZlibTransport::readAvail() const {
return urbuf_size_ - rstream_->avail_out - urpos_;
}
diff --git a/lib/cpp/src/thrift/transport/TZlibTransport.h b/lib/cpp/src/thrift/transport/TZlibTransport.h
index be2d198..29afae0 100644
--- a/lib/cpp/src/thrift/transport/TZlibTransport.h
+++ b/lib/cpp/src/thrift/transport/TZlibTransport.h
@@ -138,7 +138,7 @@
*/
~TZlibTransport() override;
- bool isOpen();
+ bool isOpen() const override;
bool peek() override;
void open() override { transport_->open(); }
@@ -185,7 +185,7 @@
protected:
inline void checkZlibRv(int status, const char* msg);
inline void checkZlibRvNothrow(int status, const char* msg);
- inline int readAvail();
+ inline int readAvail() const;
void flushToTransport(int flush);
void flushToZlib(const uint8_t* buf, int len, int flush);
bool readFromZlib();
diff --git a/lib/cpp/test/TBufferBaseTest.cpp b/lib/cpp/test/TBufferBaseTest.cpp
index 430302c..7203f82 100644
--- a/lib/cpp/test/TBufferBaseTest.cpp
+++ b/lib/cpp/test/TBufferBaseTest.cpp
@@ -165,8 +165,8 @@
// Repeatability. Kind of.
std::srand(42);
- for (size_t i = 0; i < (sizeof(data)/sizeof(data[0])); ++i) {
- data[i] = (uint8_t)rand();
+ for (unsigned char & i : data) {
+ i = (uint8_t)rand();
}
data_str.assign((char*)data, sizeof(data));
@@ -178,14 +178,14 @@
BOOST_AUTO_TEST_CASE( test_MemoryBuffer_Write_GetBuffer ) {
init_data();
- for (int d1 = 0; d1 < 3; d1++) {
+ for (auto & d1 : dist) {
TMemoryBuffer buffer(16);
int offset = 0;
int index = 0;
while (offset < 1<<15) {
- buffer.write(&data[offset], dist[d1][index]);
- offset += dist[d1][index];
+ buffer.write(&data[offset], d1[index]);
+ offset += d1[index];
index++;
}
@@ -197,8 +197,8 @@
BOOST_AUTO_TEST_CASE( test_MemoryBuffer_Write_Read ) {
init_data();
- for (int d1 = 0; d1 < 3; d1++) {
- for (int d2 = 0; d2 < 3; d2++) {
+ for (auto & d1 : dist) {
+ for (auto & d2 : dist) {
TMemoryBuffer buffer(16);
uint8_t data_out[1<<15];
int offset;
@@ -207,17 +207,17 @@
offset = 0;
index = 0;
while (offset < 1<<15) {
- buffer.write(&data[offset], dist[d1][index]);
- offset += dist[d1][index];
+ buffer.write(&data[offset], d1[index]);
+ offset += d1[index];
index++;
}
offset = 0;
index = 0;
while (offset < 1<<15) {
- unsigned int got = buffer.read(&data_out[offset], dist[d2][index]);
- BOOST_CHECK_EQUAL(got, dist[d2][index]);
- offset += dist[d2][index];
+ unsigned int got = buffer.read(&data_out[offset], d2[index]);
+ BOOST_CHECK_EQUAL(got, d2[index]);
+ offset += d2[index];
index++;
}
@@ -229,8 +229,8 @@
BOOST_AUTO_TEST_CASE( test_MemoryBuffer_Write_ReadString ) {
init_data();
- for (int d1 = 0; d1 < 3; d1++) {
- for (int d2 = 0; d2 < 3; d2++) {
+ for (auto & d1 : dist) {
+ for (auto & d2 : dist) {
TMemoryBuffer buffer(16);
string output;
int offset;
@@ -239,17 +239,17 @@
offset = 0;
index = 0;
while (offset < 1<<15) {
- buffer.write(&data[offset], dist[d1][index]);
- offset += dist[d1][index];
+ buffer.write(&data[offset], d1[index]);
+ offset += d1[index];
index++;
}
offset = 0;
index = 0;
while (offset < 1<<15) {
- unsigned int got = buffer.readAppendToString(output, dist[d2][index]);
- BOOST_CHECK_EQUAL(got, dist[d2][index]);
- offset += dist[d2][index];
+ unsigned int got = buffer.readAppendToString(output, d2[index]);
+ BOOST_CHECK_EQUAL(got, d2[index]);
+ offset += d2[index];
index++;
}
@@ -263,8 +263,8 @@
// Do shorter writes and reads so we don't align to power-of-two boundaries.
- for (int d1 = 0; d1 < 3; d1++) {
- for (int d2 = 0; d2 < 3; d2++) {
+ for (auto & d1 : dist) {
+ for (auto & d2 : dist) {
TMemoryBuffer buffer(16);
uint8_t data_out[1<<15];
int offset;
@@ -274,16 +274,16 @@
offset = 0;
index = 0;
while (offset < (1<<15)-42) {
- buffer.write(&data[offset], dist[d1][index]);
- offset += dist[d1][index];
+ buffer.write(&data[offset], d1[index]);
+ offset += d1[index];
index++;
}
offset = 0;
index = 0;
while (offset < (1<<15)-42) {
- buffer.read(&data_out[offset], dist[d2][index]);
- offset += dist[d2][index];
+ buffer.read(&data_out[offset], d2[index]);
+ offset += d2[index];
index++;
}
@@ -303,8 +303,8 @@
// Pull the buffer out of the loop so its state gets worked harder.
TMemoryBuffer buffer(16);
- for (int d1 = 0; d1 < 3; d1++) {
- for (int d2 = 0; d2 < 3; d2++) {
+ for (auto & d1 : dist) {
+ for (auto & d2 : dist) {
uint8_t data_out[1<<15];
int offset;
int index;
@@ -313,16 +313,16 @@
offset = 0;
index = 0;
while (offset < (1<<15)-42) {
- buffer.write(&data[offset], dist[d1][index]);
- offset += dist[d1][index];
+ buffer.write(&data[offset], d1[index]);
+ offset += d1[index];
index++;
}
offset = 0;
index = 0;
while (offset < (1<<15)-42) {
- buffer.read(&data_out[offset], dist[d2][index]);
- offset += dist[d2][index];
+ buffer.read(&data_out[offset], d2[index]);
+ offset += d2[index];
index++;
}
@@ -341,8 +341,8 @@
// Do shorter writes and reads so we don't align to power-of-two boundaries.
// Pull the buffer out of the loop so its state gets worked harder.
- for (int d1 = 0; d1 < 3; d1++) {
- for (int d2 = 0; d2 < 3; d2++) {
+ for (auto & d1 : dist) {
+ for (auto & d2 : dist) {
TMemoryBuffer buffer(16);
uint8_t data_out[1<<13];
@@ -350,7 +350,7 @@
int write_index = 0;
unsigned int to_write = (1<<14)-42;
while (to_write > 0) {
- int write_amt = (std::min)(dist[d1][write_index], to_write);
+ int write_amt = (std::min)(d1[write_index], to_write);
buffer.write(&data[write_offset], write_amt);
write_offset += write_amt;
write_index++;
@@ -361,7 +361,7 @@
int read_index = 0;
unsigned int to_read = (1<<13)-42;
while (to_read > 0) {
- int read_amt = (std::min)(dist[d2][read_index], to_read);
+ int read_amt = (std::min)(d2[read_index], to_read);
int got = buffer.read(&data_out[read_offset], read_amt);
BOOST_CHECK_EQUAL(got, read_amt);
read_offset += read_amt;
@@ -375,7 +375,7 @@
int second_index = write_index-1;
unsigned int to_second = (1<<14)+42;
while (to_second > 0) {
- int second_amt = (std::min)(dist[d1][second_index], to_second);
+ int second_amt = (std::min)(d1[second_index], to_second);
//printf("%d\n", second_amt);
buffer.write(&data[second_offset], second_amt);
second_offset += second_amt;
@@ -399,17 +399,16 @@
1<<14, 1<<17,
};
- for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
- int size = sizes[i];
- for (int d1 = 0; d1 < 3; d1++) {
+ for (int size : sizes) {
+ for (auto & d1 : dist) {
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(16));
TBufferedTransport trans(buffer, size);
int offset = 0;
int index = 0;
while (offset < 1<<15) {
- trans.write(&data[offset], dist[d1][index]);
- offset += dist[d1][index];
+ trans.write(&data[offset], d1[index]);
+ offset += d1[index];
index++;
}
trans.flush();
@@ -430,9 +429,8 @@
1<<14, 1<<17,
};
- for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
- int size = sizes[i];
- for (int d1 = 0; d1 < 3; d1++) {
+ for (int size : sizes) {
+ for (auto & d1 : dist) {
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(data, sizeof(data)));
TBufferedTransport trans(buffer, size);
uint8_t data_out[1<<15];
@@ -443,8 +441,8 @@
// Note: this doesn't work with "read" because TBufferedTransport
// doesn't try loop over reads, so we get short reads. We don't
// check the return value, so that messes us up.
- trans.readAll(&data_out[offset], dist[d1][index]);
- offset += dist[d1][index];
+ trans.readAll(&data_out[offset], d1[index]);
+ offset += d1[index];
index++;
}
@@ -463,9 +461,8 @@
1<<14, 1<<17,
};
- for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
- int size = sizes[i];
- for (int d1 = 0; d1 < 3; d1++) {
+ for (int size : sizes) {
+ for (auto & d1 : dist) {
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(data, sizeof(data)));
shared_ptr<TShortReadTransport> tshort(new TShortReadTransport(buffer, 0.125));
TBufferedTransport trans(buffer, size);
@@ -477,8 +474,8 @@
// Note: this doesn't work with "read" because TBufferedTransport
// doesn't try loop over reads, so we get short reads. We don't
// check the return value, so that messes us up.
- trans.readAll(&data_out[offset], dist[d1][index]);
- offset += dist[d1][index];
+ trans.readAll(&data_out[offset], d1[index]);
+ offset += d1[index];
index++;
}
@@ -497,17 +494,16 @@
1<<14, 1<<17,
};
- for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
- int size = sizes[i];
- for (int d1 = 0; d1 < 3; d1++) {
+ for (int size : sizes) {
+ for (auto & d1 : dist) {
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(16));
TFramedTransport trans(buffer, size);
int offset = 0;
int index = 0;
while (offset < 1<<15) {
- trans.write(&data[offset], dist[d1][index]);
- offset += dist[d1][index];
+ trans.write(&data[offset], d1[index]);
+ offset += d1[index];
index++;
}
trans.flush();
@@ -526,7 +522,7 @@
BOOST_AUTO_TEST_CASE( test_FramedTransport_Read ) {
init_data();
- for (int d1 = 0; d1 < 3; d1++) {
+ for (auto & d1 : dist) {
uint8_t data_out[1<<15];
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
TFramedTransport trans(buffer);
@@ -539,8 +535,8 @@
int index = 0;
while (offset < 1<<15) {
// This should work with read because we have one huge frame.
- trans.read(&data_out[offset], dist[d1][index]);
- offset += dist[d1][index];
+ trans.read(&data_out[offset], d1[index]);
+ offset += d1[index];
index++;
}
@@ -560,11 +556,9 @@
int probs[] = { 1, 2, 4, 8, 16, 32, };
- for (size_t i = 0; i < sizeof (sizes) / sizeof (sizes[0]); i++) {
- int size = sizes[i];
- for (size_t j = 0; j < sizeof (probs) / sizeof (probs[0]); j++) {
- int prob = probs[j];
- for (int d1 = 0; d1 < 3; d1++) {
+ for (int size : sizes) {
+ for (int prob : probs) {
+ for (auto & d1 : dist) {
shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(16));
TFramedTransport trans(buffer, size);
std::vector<uint8_t> data_out(1<<17, 0);
@@ -574,9 +568,9 @@
int write_index = 0;
int flush_size = 0;
while (write_offset < 1<<15) {
- trans.write(&data[write_offset], dist[d1][write_index]);
- write_offset += dist[d1][write_index];
- flush_size += dist[d1][write_index];
+ trans.write(&data[write_offset], d1[write_index]);
+ write_offset += d1[write_index];
+ flush_size += d1[write_index];
write_index++;
if (flush_size > 0 && rand()%prob == 0) {
flush_sizes.push_back(flush_size);
@@ -593,8 +587,7 @@
int read_offset = 0;
int read_index = 0;
- for (unsigned int k = 0; k < flush_sizes.size(); k++) {
- int fsize = flush_sizes[k];
+ for (int fsize : flush_sizes) {
// We are exploiting an implementation detail of TFramedTransport.
// The read buffer starts empty and it will never do more than one
// readFrame per read, so we should always get exactly one frame.
diff --git a/lib/cpp/test/TFileTransportTest.cpp b/lib/cpp/test/TFileTransportTest.cpp
index ad32185..21c1f3b 100644
--- a/lib/cpp/test/TFileTransportTest.cpp
+++ b/lib/cpp/test/TFileTransportTest.cpp
@@ -279,12 +279,12 @@
BOOST_WARN_GE(calls->size(), static_cast<FsyncLog::CallList::size_type>(1));
const struct timeval* prev_time = nullptr;
- for (auto it = calls->begin(); it != calls->end(); ++it) {
+ for (const auto & call : *calls) {
if (prev_time) {
- int delta = time_diff(prev_time, &it->time);
+ int delta = time_diff(prev_time, &call.time);
BOOST_WARN( delta < max_allowed_delta );
}
- prev_time = &it->time;
+ prev_time = &call.time;
}
}
diff --git a/lib/cpp/test/TMemoryBufferTest.cpp b/lib/cpp/test/TMemoryBufferTest.cpp
index 9206872..42f9711 100644
--- a/lib/cpp/test/TMemoryBufferTest.cpp
+++ b/lib/cpp/test/TMemoryBufferTest.cpp
@@ -81,9 +81,9 @@
}
BOOST_AUTO_TEST_CASE(test_readAppendToString) {
- string* str1 = new string("abcd1234");
- TMemoryBuffer buf((uint8_t*)str1->data(),
- static_cast<uint32_t>(str1->length()),
+ string str1 = "abcd1234";
+ TMemoryBuffer buf((uint8_t*)str1.data(),
+ static_cast<uint32_t>(str1.length()),
TMemoryBuffer::COPY);
string str3 = "wxyz", str4 = "6789";
diff --git a/lib/cpp/test/TNonblockingSSLServerTest.cpp b/lib/cpp/test/TNonblockingSSLServerTest.cpp
index d0d8688..dc40c12 100644
--- a/lib/cpp/test/TNonblockingSSLServerTest.cpp
+++ b/lib/cpp/test/TNonblockingSSLServerTest.cpp
@@ -151,7 +151,7 @@
std::shared_ptr<transport::TNonblockingSSLServerSocket> socket;
Mutex mutex_;
- Runner() {
+ Runner():port(0) {
listenHandler.reset(new ListenEventHandler(&mutex_));
}
diff --git a/lib/cpp/test/TNonblockingServerTest.cpp b/lib/cpp/test/TNonblockingServerTest.cpp
index 434217e..f9aab4c 100644
--- a/lib/cpp/test/TNonblockingServerTest.cpp
+++ b/lib/cpp/test/TNonblockingServerTest.cpp
@@ -83,6 +83,7 @@
Mutex mutex_;
Runner() {
+ port = 0;
listenHandler.reset(new ListenEventHandler(&mutex_));
}
diff --git a/lib/cpp/test/TServerTransportTest.cpp b/lib/cpp/test/TServerTransportTest.cpp
index 15177a8..18a393e 100644
--- a/lib/cpp/test/TServerTransportTest.cpp
+++ b/lib/cpp/test/TServerTransportTest.cpp
@@ -39,7 +39,7 @@
protected:
shared_ptr<TTransport> acceptImpl() override {
- return valid_ ? shared_ptr<TestTTransport>(new TestTTransport)
+ return valid_ ? std::make_shared<TestTTransport>()
: shared_ptr<TestTTransport>();
}
};
diff --git a/lib/cpp/test/TransportTest.cpp b/lib/cpp/test/TransportTest.cpp
index b0c84b6..a890aa8 100644
--- a/lib/cpp/test/TransportTest.cpp
+++ b/lib/cpp/test/TransportTest.cpp
@@ -140,8 +140,8 @@
std::shared_ptr<Transport_> out;
private:
- CoupledTransports(const CoupledTransports&);
- CoupledTransports& operator=(const CoupledTransports&);
+ CoupledTransports(const CoupledTransports&) = delete;
+ CoupledTransports& operator=(const CoupledTransports&) = delete;
};
/**
diff --git a/lib/cpp/test/concurrency/Tests.cpp b/lib/cpp/test/concurrency/Tests.cpp
index f2b0111..8c734c2 100644
--- a/lib/cpp/test/concurrency/Tests.cpp
+++ b/lib/cpp/test/concurrency/Tests.cpp
@@ -31,8 +31,6 @@
int main(int argc, char** argv) {
- std::string arg;
-
std::vector<std::string> args(argc - 1 > 1 ? argc - 1 : 1);
args[0] = "all";