2323 * Author: hendrik
2424 */
2525
26+ #include < cstddef>
27+ #include < cstdint>
28+ #include < exception>
29+ #include < fstream>
2630#include < functional>
27-
28- #include < boost/algorithm/string.hpp>
29- #include < boost/algorithm/string/join.hpp>
30- #include < boost/filesystem.hpp>
31+ #include < ios>
32+ #include < iostream>
33+ #include < ostream>
34+ #include < stdexcept>
35+ #include < string>
36+ #include < utility>
37+ #include < vector>
38+
39+ #include < boost/algorithm/string/split.hpp>
40+ #include < boost/filesystem/directory.hpp>
41+ #include < boost/filesystem/operations.hpp>
42+ #include < boost/filesystem/path.hpp>
3143#include < boost/iostreams/device/file.hpp>
3244#include < boost/iostreams/filter/gzip.hpp>
3345#include < boost/iostreams/filtering_stream.hpp>
3446#include < boost/lexical_cast.hpp>
35- #include < boost/program_options.hpp>
36- #include < boost/range/adaptor/map.hpp>
37- #include < boost/range/iterator_range.hpp>
47+ #include < boost/lexical_cast/bad_lexical_cast.hpp>
48+ #include < boost/program_options.hpp> // NOLINT
49+ #include < boost/program_options/options_description.hpp>
50+ #include < boost/program_options/positional_options.hpp>
51+ #include < boost/program_options/value_semantic.hpp>
52+ #include < boost/program_options/variables_map.hpp>
53+ #include < boost/range/adaptor/map.hpp> // NOLINT
54+ #include < boost/range/iterator_range_core.hpp>
3855
39- #include " keyvi/dictionary/dictionary_compiler.h"
4056#include " keyvi/dictionary/dictionary_types.h"
57+ #include " keyvi/dictionary/fsa/internal/constants.h"
4158#include " keyvi/util/configuration.h"
4259
43- void callback (size_t added, size_t overall, void *) {
44- std::cout << " Processed " << added << " /" << overall << " (" << ((100 * added) / overall) << " %)." << std::endl ;
60+ void callback (size_t added, size_t overall, void * /* unused */ ) {
61+ std::cout << " Processed " << added << " /" << overall << " (" << ((100 * added) / overall) << " %)." << ' \n ' ;
4562}
4663
4764template <typename CompilerType, typename ValueType>
@@ -50,7 +67,7 @@ void compile_multiple(CompilerType* compiler, std::function<std::pair<std::strin
5067 boost::iostreams::filtering_istream input_stream;
5168 std::string line;
5269
53- for (auto input_as_string : inputs) {
70+ for (const auto & input_as_string : inputs) {
5471 auto input = boost::filesystem::path (input_as_string);
5572
5673 if (boost::filesystem::is_directory (input)) {
@@ -60,7 +77,7 @@ void compile_multiple(CompilerType* compiler, std::function<std::pair<std::strin
6077 input_stream.push (boost::iostreams::gzip_decompressor ());
6178 }
6279
63- boost::iostreams::file_source file (entry.path ().string (), std::ios_base::in | std::ios_base::binary);
80+ boost::iostreams::file_source const file (entry.path ().string (), std::ios_base::in | std::ios_base::binary);
6481 input_stream.push (file);
6582 ++files_added;
6683 while (std::getline (input_stream, line)) {
@@ -79,7 +96,7 @@ void compile_multiple(CompilerType* compiler, std::function<std::pair<std::strin
7996 input_stream.push (boost::iostreams::gzip_decompressor ());
8097 }
8198
82- boost::iostreams::file_source file (input.string (), std::ios_base::in | std::ios_base::binary);
99+ boost::iostreams::file_source const file (input.string (), std::ios_base::in | std::ios_base::binary);
83100
84101 input_stream.push (file);
85102 while (std::getline (input_stream, line)) {
@@ -107,19 +124,21 @@ void compile_completion(const std::vector<std::string>& input, const std::string
107124 const keyvi::util::parameters_t & value_store_params = keyvi::util::parameters_t ()) {
108125 keyvi::dictionary::CompletionDictionaryCompiler compiler (value_store_params);
109126
110- std::function<std::pair<std::string, uint32_t >(std::string)> parser = [](std::string line) {
111- size_t tab = line.find (' \t ' );
127+ std::function<std::pair<std::string, uint32_t >(std::string)> const parser = [](const std::string& line) {
128+ size_t const tab = line.find (' \t ' );
112129
113- if (tab == std::string::npos) return std::pair<std::string, uint32_t >();
130+ if (tab == std::string::npos) {
131+ return std::pair<std::string, uint32_t >();
132+ }
114133
115- std::string key = line.substr (0 , tab);
116- std::string value_as_string = line.substr (tab + 1 );
117- uint32_t value;
134+ std::string const key = line.substr (0 , tab);
135+ std::string const value_as_string = line.substr (tab + 1 );
136+ uint32_t value = 0 ;
118137
119138 try {
120139 value = boost::lexical_cast<uint32_t >(value_as_string);
121140 } catch (boost::bad_lexical_cast const &) {
122- std::cout << " Error: value was not valid: " << line << std::endl ;
141+ std::cout << " Error: value was not valid: " << line << ' \n ' ;
123142 return std::pair<std::string, uint32_t >();
124143 }
125144 return std::pair<std::string, uint32_t >(key, value);
@@ -133,19 +152,21 @@ void compile_integer(const std::vector<std::string>& input, const std::string& o
133152 const keyvi::util::parameters_t & value_store_params = keyvi::util::parameters_t ()) {
134153 keyvi::dictionary::IntDictionaryCompiler compiler (value_store_params);
135154
136- std::function<std::pair<std::string, uint32_t >(std::string)> parser = [](std::string line) {
137- size_t tab = line.find (' \t ' );
155+ std::function<std::pair<std::string, uint32_t >(std::string)> const parser = [](const std::string& line) {
156+ size_t const tab = line.find (' \t ' );
138157
139- if (tab == std::string::npos) return std::pair<std::string, uint32_t >();
158+ if (tab == std::string::npos) {
159+ return std::pair<std::string, uint32_t >();
160+ }
140161
141- std::string key = line.substr (0 , tab);
142- std::string value_as_string = line.substr (tab + 1 );
143- uint32_t value;
162+ std::string const key = line.substr (0 , tab);
163+ std::string const value_as_string = line.substr (tab + 1 );
164+ uint32_t value = 0 ;
144165
145166 try {
146167 value = boost::lexical_cast<uint32_t >(value_as_string);
147168 } catch (boost::bad_lexical_cast const &) {
148- std::cout << " Error: value was not valid: " << line << std::endl ;
169+ std::cout << " Error: value was not valid: " << line << ' \n ' ;
149170 return std::pair<std::string, uint32_t >();
150171 }
151172 return std::pair<std::string, uint32_t >(key, value);
@@ -158,11 +179,13 @@ void compile_integer(const std::vector<std::string>& input, const std::string& o
158179template <class Compiler >
159180void compile_strings_inner (Compiler* compiler, const std::vector<std::string>& input, const std::string& output,
160181 const std::string& manifest = {}) {
161- std::function<std::pair<std::string, std::string>(std::string)> parser = [](std::string line) {
162- size_t tab = line.find (' \t ' );
163- if (tab == std::string::npos) return std::pair<std::string, std::string>();
164- std::string key = line.substr (0 , tab);
165- std::string value = line.substr (tab + 1 );
182+ std::function<std::pair<std::string, std::string>(std::string)> const parser = [](const std::string& line) {
183+ size_t const tab = line.find (' \t ' );
184+ if (tab == std::string::npos) {
185+ return std::pair<std::string, std::string>();
186+ }
187+ std::string const key = line.substr (0 , tab);
188+ std::string const value = line.substr (tab + 1 );
166189
167190 return std::pair<std::string, std::string>(key, value);
168191 };
@@ -183,9 +206,9 @@ void compile_key_only(const std::vector<std::string>& input, const std::string&
183206 const keyvi::util::parameters_t & value_store_params = keyvi::util::parameters_t ()) {
184207 keyvi::dictionary::KeyOnlyDictionaryCompiler compiler (value_store_params);
185208
186- std::function<std::pair<std::string, uint32_t >(std::string)> parser = [](std::string line) {
209+ std::function<std::pair<std::string, uint32_t >(std::string)> const parser = [](const std::string& line) {
187210 std::string key = line;
188- size_t tab = line.find (' \t ' );
211+ size_t const tab = line.find (' \t ' );
189212
190213 if (tab != std::string::npos) {
191214 key = line.substr (0 , tab);
@@ -208,9 +231,9 @@ void compile_json(const std::vector<std::string>& input, const std::string& outp
208231/* * Extracts the parameters. */
209232keyvi::util::parameters_t extract_parameters (const boost::program_options::variables_map& vm) {
210233 keyvi::util::parameters_t ret;
211- for (auto & v : vm[" parameter" ].as <std::vector<std::string>>()) {
234+ for (const auto & v : vm[" parameter" ].as <std::vector<std::string>>()) {
212235 std::vector<std::string> key_value;
213- boost::split (key_value, v, std::bind ( std::equal_to<char >(), std::placeholders::_1 , ' =' ));
236+ boost::split (key_value, v, []( auto && PH1) { return std::equal_to<char >()( std::forward< decltype (PH1)>(PH1) , ' =' ); } );
214237 if (key_value.size () == 2 ) {
215238 ret[key_value[0 ]] = key_value[1 ];
216239 } else {
@@ -260,22 +283,22 @@ int main(int argc, char** argv) {
260283 boost::program_options::command_line_parser (argc, argv).options (description).positional (p).run (), vm);
261284 boost::program_options::notify (vm);
262285
263- if (vm.count (" help" )) {
286+ if (vm.count (" help" ) != 0U ) {
264287 std::cout << description;
265288 return 0 ;
266289 }
267290
268- std::string manifest = vm[" manifest" ].as <std::string>();
269- std::cout << manifest << std::endl ;
291+ std::string const manifest = vm[" manifest" ].as <std::string>();
292+ std::cout << manifest << ' \n ' ;
270293
271- std::string dictionary_type = vm[" dictionary-type" ].as <std::string>();
294+ std::string const dictionary_type = vm[" dictionary-type" ].as <std::string>();
272295 keyvi::util::parameters_t value_store_params = extract_parameters (vm);
273296
274- if (vm.count (" memory-limit" )) {
297+ if (vm.count (" memory-limit" ) != 0U ) {
275298 value_store_params[MEMORY_LIMIT_KEY] = vm[" memory-limit" ].as <std::string>();
276299 }
277300
278- if (vm.count (" input-file" ) && vm.count (" output-file" )) {
301+ if (( vm.count (" input-file" ) != 0U ) && ( vm.count (" output-file" ) != 0U )) {
279302 input_files = vm[" input-file" ].as <std::vector<std::string>>();
280303 output_file = vm[" output-file" ].as <std::string>();
281304
@@ -290,19 +313,19 @@ int main(int argc, char** argv) {
290313 } else if (dictionary_type == " completion" ) {
291314 compile_completion (input_files, output_file, manifest, value_store_params);
292315 } else {
293- std::cout << " ERROR: unknown dictionary type." << std::endl << std::endl ;
316+ std::cout << " ERROR: unknown dictionary type." << ' \n ' << ' \n ' ;
294317 std::cout << description;
295318 return 1 ;
296319 }
297320 } else {
298- std::cout << " ERROR: arguments wrong or missing." << std::endl << std::endl ;
321+ std::cout << " ERROR: arguments wrong or missing." << ' \n ' << ' \n ' ;
299322 std::cout << description;
300323 return 1 ;
301324 }
302325 } catch (std::exception& e) {
303- std::cout << " ERROR: arguments wrong or missing." << std::endl << std::endl ;
326+ std::cout << " ERROR: arguments wrong or missing." << ' \n ' << ' \n ' ;
304327
305- std::cout << e.what () << std::endl << std::endl ;
328+ std::cout << e.what () << ' \n ' << ' \n ' ;
306329 std::cout << description;
307330
308331 return 1 ;
0 commit comments