- Timestamp:
- 12/05/11 08:05:14 (18 months ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 9c06054
- Parents:
- 9853bc3
- Location:
- include
- Files:
-
- 5 edited
-
client/command_line_parser.cpp (modified) (7 diffs)
-
client/command_line_parser.hpp (modified) (3 diffs)
-
nscapi/functions.hpp (modified) (12 diffs)
-
strEx.h (modified) (4 diffs)
-
utils.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/client/command_line_parser.cpp
r96c1461 rf33c12f 53 53 54 54 55 int client::command_line_parser:: commandLineExec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) {55 int client::command_line_parser::do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 56 56 if (!config.validate()) 57 57 throw cli_exception("Invalid data: " + config.to_string()); 58 58 if (command == _T("help")) { 59 result = build_help(config); 60 return NSCAPI::returnUNKNOWN; 59 return nscapi::functions::create_simple_exec_response_unknown(command, build_help(config), result); 61 60 } else if (command == _T("query")) { 62 61 std::wstring msg, perf; 63 int ret = query(config, command, arguments, msg, perf); 64 if (perf.empty()) 65 result = msg; 66 else 67 result = msg + _T("|") + perf; 62 int ret = do_query(config, command, arguments, result); 63 nscapi::functions::make_exec_from_query(result); 68 64 return ret; 69 65 } else if (command == _T("exec")) { 70 return exec(config, command, arguments, result);66 return do_exec(config, command, arguments, result); 71 67 } else if (command == _T("submit")) { 72 boost::tuple<int,std::wstring> ret = simple_submit(config, command, arguments); 73 result = ret.get<1>(); 74 return ret.get<0>(); 68 int ret = do_submit(config, command, arguments, result); 69 nscapi::functions::make_exec_from_submit(result); 70 return ret; 71 } 72 return NSCAPI::returnIgnored; 73 } 74 75 int client::command_line_parser::do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 76 if (!config.validate()) 77 throw cli_exception("Invalid data: " + config.to_string()); 78 if (command == _T("help")) { 79 return nscapi::functions::create_simple_query_response_unknown(command, build_help(config), _T(""), result); 80 } else if (command == _T("query")) { 81 return do_query(config, command, arguments, result); 82 } else if (command == _T("exec")) { 83 int ret = do_exec(config, command, arguments, result); 84 nscapi::functions::make_query_from_exec(result); 85 return ret; 86 } else if (command == _T("submit")) { 87 int ret = do_submit(config, command, arguments, result); 88 nscapi::functions::make_query_from_submit(result); 89 return ret; 75 90 } 76 91 return NSCAPI::returnIgnored; … … 97 112 } 98 113 99 int client::command_manager::exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std:: wstring &message, std::wstring &perf) {114 int client::command_manager::exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response) { 100 115 command_type::const_iterator cit = commands.find(command); 101 116 if (cit == commands.end()) … … 112 127 } 113 128 // TODO: Add support for target here! 114 return client::command_line_parser:: commandLineExec(config, ci.command, rendered_arguments, message);115 } 116 int client::command_line_parser:: query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf) {129 return client::command_line_parser::do_execute_command_as_exec(config, ci.command, rendered_arguments, response); 130 } 131 int client::command_line_parser::do_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response) { 117 132 boost::program_options::variables_map vm; 118 133 … … 141 156 nscapi::functions::append_simple_query_request_payload(message.add_payload(), config.data->command, config.data->arguments); 142 157 std::string result; 143 int ret = config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), result); 144 nscapi::functions::parse_simple_query_response(result, msg, perf); 145 return ret; 146 } 147 148 int client::command_line_parser::exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result) { 158 return config.handler->query(config.data, message.mutable_header(), message.SerializeAsString(), result); 159 } 160 161 int client::command_line_parser::do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 149 162 boost::program_options::variables_map vm; 150 163 … … 173 186 std::string response; 174 187 nscapi::functions::append_simple_exec_request_payload(message.add_payload(), config.data->command, config.data->arguments); 175 int ret = config.handler->exec(config.data, message.mutable_header(), message.SerializeAsString(), response); 176 nscapi::functions::parse_simple_exec_result(response, result); 177 return ret; 178 } 179 180 boost::tuple<int,std::wstring> client::command_line_parser::simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments) { 188 return config.handler->exec(config.data, message.mutable_header(), message.SerializeAsString(), response); 189 } 190 191 int client::command_line_parser::do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result) { 181 192 boost::program_options::variables_map vm; 182 193 po::options_description common("Common options"); … … 203 214 nscapi::functions::append_simple_submit_request_payload(message.add_payload(), config.data->command, config.data->result, config.data->message); 204 215 205 std::string response; 206 if (config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), response) != NSCAPI::isSuccess) 207 return boost::make_tuple(NSCAPI::returnUNKNOWN, _T("Failed to submit command")); 208 209 std::wstring messages; 210 int ret = nscapi::functions::parse_simple_submit_response(response, messages); 211 return boost::make_tuple(ret, messages); 216 return config.handler->submit(config.data, message.mutable_header(), message.SerializeAsString(), result); 212 217 } 213 218 void client::command_line_parser::modify_header(configuration &config, ::Plugin::Common_Header* header, nscapi::functions::destination_container &recipient) { … … 225 230 } 226 231 227 int client::command_line_parser:: relay_submit(configuration &config, const std::string &request, std::string &response) {232 int client::command_line_parser::do_relay_submit(configuration &config, const std::string &request, std::string &response) { 228 233 Plugin::SubmitRequestMessage message; 229 234 message.ParseFromString(request); -
include/client/command_line_parser.hpp
r96c1461 rf33c12f 120 120 121 121 std::wstring add_command(std::wstring name, std::wstring args); 122 int exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std:: wstring &message, std::wstring &perf);122 int exec_simple(configuration &config, const std::wstring &target, const std::wstring &command, std::list<std::wstring> &arguments, std::string &response); 123 123 124 124 static std::wstring make_key(std::wstring key) { … … 137 137 static std::wstring build_help(configuration &config); 138 138 139 static int commandLineExec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result); 140 static int relay_submit(configuration &config, const std::string &request, std::string &response); 141 142 static boost::tuple<int,std::wstring> simple_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments); 139 static int do_execute_command_as_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 140 static int do_execute_command_as_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 141 static int do_relay_submit(configuration &config, const std::string &request, std::string &response); 143 142 144 143 static std::wstring parse_command(std::wstring command, std::wstring prefix) { … … 163 162 } 164 163 165 static int query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &msg, std::wstring &perf);166 //static std::list<std::string> submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments);167 static int exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::wstring &result);164 static int do_query(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 165 static int do_exec(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 166 static int do_submit(configuration &config, const std::wstring &command, std::list<std::wstring> &arguments, std::string &result); 168 167 169 168 private: -
include/nscapi/functions.hpp
r96c1461 rf33c12f 41 41 42 42 namespace nscapi { 43 44 namespace traits { 45 46 template<class T> 47 struct perf_data_consts { 48 static const T get_valid_perf_numbers(); 49 static const T get_replace_perf_coma_src(); 50 static const T get_replace_perf_coma_tgt(); 51 }; 52 53 template<> 54 struct perf_data_consts<std::wstring> { 55 static const std::wstring get_valid_perf_numbers() { 56 return _T("0123456789,."); 57 } 58 static const std::wstring get_replace_perf_coma_src() { 59 return _T(","); 60 } 61 static const std::wstring get_replace_perf_coma_tgt() { 62 return _T("."); 63 } 64 }; 65 template<> 66 struct perf_data_consts<std::string> { 67 static const std::string get_valid_perf_numbers() { 68 return "0123456789,."; 69 } 70 static const std::string get_replace_perf_coma_src() { 71 return ","; 72 } 73 static const std::string get_replace_perf_coma_tgt() { 74 return "."; 75 } 76 }; 77 } 43 78 class functions { 44 79 public: … … 71 106 return NSCAPI::hasFailed; 72 107 } 108 static Plugin::Common::ResultCode gbp_status_to_gbp_nagios(Plugin::Common::Status::StatusType ret) { 109 if (ret == Plugin::Common_Status_StatusType_OK) 110 return Plugin::Common_ResultCode_OK; 111 return Plugin::Common_ResultCode_UNKNOWN; 112 } 113 static Plugin::Common::Status::StatusType gbp_to_nagios_gbp_status(Plugin::Common::ResultCode ret) { 114 if (ret == Plugin::Common_ResultCode_UNKNOWN||ret == Plugin::Common_ResultCode_WARNING||ret == Plugin::Common_ResultCode_CRITCAL) 115 return Plugin::Common_Status_StatusType_CRITICAL; 116 return Plugin::Common_Status_StatusType_OK; 117 } 118 73 119 static Plugin::LogEntry::Entry::Level log_to_gpb(NSCAPI::messageTypes ret) { 74 120 if (ret == NSCAPI::critical) … … 98 144 } 99 145 100 static double trim_to_double(std::wstring s) { 101 std::wstring::size_type pend = s.find_first_not_of(_T("0123456789,.")); 102 if (pend != std::wstring::npos) 146 147 template<class T> 148 static double trim_to_double(T s) { 149 typename T::size_type pend = s.find_first_not_of(nscapi::traits::perf_data_consts<T>::get_valid_perf_numbers()); 150 if (pend != T::npos) 103 151 s = s.substr(0,pend); 104 strEx::replace(s, _T(","), _T("."));152 strEx::replace(s, nscapi::traits::perf_data_consts<T>::get_replace_perf_coma_src(), nscapi::traits::perf_data_consts<T>::get_replace_perf_coma_tgt()); 105 153 return strEx::stod(s); 106 154 } 155 156 107 157 108 158 struct decoded_simple_command_data { … … 280 330 Plugin::SubmitRequestMessage request; 281 331 request.mutable_header()->CopyFrom(response.header()); 332 request.mutable_header()->set_source_id(request.mutable_header()->recipient_id()); 282 333 request.set_channel(to_string(channel)); 283 334 for (int i=0;i<response.payload_size();++i) { … … 287 338 } 288 339 message = request.SerializeAsString(); 340 } 341 342 static void make_query_from_exec(std::string &data) { 343 Plugin::ExecuteResponseMessage exec_response_message; 344 exec_response_message.ParseFromString(data); 345 Plugin::QueryResponseMessage query_response_message; 346 query_response_message.mutable_header()->CopyFrom(exec_response_message); 347 for (int i=0;i<exec_response_message.payload_size();++i) { 348 Plugin::ExecuteResponseMessage::Response p = exec_response_message.payload(i); 349 append_simple_query_response_payload(query_response_message.add_payload(), p.command(), p.result(), p.message()); 350 } 351 data = query_response_message.SerializeAsString(); 352 } 353 static void make_query_from_submit(std::string &data) { 354 Plugin::SubmitResponseMessage submit_response_message; 355 submit_response_message.ParseFromString(data); 356 Plugin::QueryResponseMessage query_response_message; 357 query_response_message.mutable_header()->CopyFrom(submit_response_message); 358 for (int i=0;i<submit_response_message.payload_size();++i) { 359 Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i); 360 append_simple_query_response_payload(query_response_message.add_payload(), p.command(), gbp_status_to_gbp_nagios(p.status().status()), p.status().message(), ""); 361 } 362 data = query_response_message.SerializeAsString(); 363 } 364 365 static void make_exec_from_submit(std::string &data) { 366 Plugin::SubmitResponseMessage submit_response_message; 367 submit_response_message.ParseFromString(data); 368 Plugin::ExecuteResponseMessage exec_response_message; 369 exec_response_message.mutable_header()->CopyFrom(submit_response_message); 370 for (int i=0;i<submit_response_message.payload_size();++i) { 371 Plugin::SubmitResponseMessage::Response p = submit_response_message.payload(i); 372 append_simple_exec_response_payload(exec_response_message.add_payload(), p.command(), gbp_status_to_gbp_nagios(p.status().status()), p.status().message()); 373 } 374 data = exec_response_message.SerializeAsString(); 375 } 376 static void make_exec_from_query(std::string &data) { 377 Plugin::QueryResponseMessage query_response_message; 378 query_response_message.ParseFromString(data); 379 Plugin::ExecuteResponseMessage exec_response_message; 380 exec_response_message.mutable_header()->CopyFrom(query_response_message); 381 for (int i=0;i<query_response_message.payload_size();++i) { 382 Plugin::QueryResponseMessage::Response p = query_response_message.payload(i); 383 std::string s = build_performance_data(p); 384 if (!s.empty()) 385 s = p.message() + "|" + s; 386 else 387 s = p.message(); 388 append_simple_exec_response_payload(exec_response_message.add_payload(), p.command(), p.result(), s); 389 } 390 data = exec_response_message.SerializeAsString(); 391 } 392 393 394 static void make_return_header(::Plugin::Common_Header *target, const ::Plugin::Common_Header &source) { 395 target->CopyFrom(source); 396 target->set_source_id(target->recipient_id()); 289 397 } 290 398 … … 409 517 return NSCAPI::returnUNKNOWN; 410 518 } 519 static NSCAPI::nagiosReturn create_simple_query_response_unknown(std::wstring command, std::wstring msg, std::string &buffer) { 520 create_simple_query_response(command, NSCAPI::returnUNKNOWN, msg, _T(""), buffer); 521 return NSCAPI::returnUNKNOWN; 522 } 411 523 412 524 static void create_simple_query_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring msg, std::wstring perf, std::string &buffer) { … … 436 548 } 437 549 438 static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::wstring command, NSCAPI::nagiosReturn ret, std::wstring msg) { 550 template<class T> 551 static void append_response_payloads(T &target_message, std::string &payload) { 552 T source_message; 553 source_message.ParseFromString(payload); 554 for (int i=0;i<source_message.payload_size();++i) 555 target_message.add_payload()->CopyFrom(source_message.payload(i)); 556 } 557 558 static void append_simple_query_response_payload(Plugin::QueryResponseMessage::Response *payload, std::string command, NSCAPI::nagiosReturn ret, std::string msg, std::string perf = "") { 439 559 payload->set_command(to_string(command)); 440 560 payload->set_message(to_string(msg)); 441 561 payload->set_result(nagios_status_to_gpb(ret)); 562 if (!perf.empty()) 563 parse_performance_data(payload, perf); 564 } 565 /* 566 static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::string command, Plugin::Common::ResultCode ret, std::string msg) { 567 payload->set_command(command); 568 payload->set_message(msg); 569 payload->set_result(ret); 570 } 571 */ 572 static void append_simple_exec_response_payload(Plugin::ExecuteResponseMessage::Response *payload, std::string command, int ret, std::string msg) { 573 payload->set_command(command); 574 payload->set_message(msg); 575 payload->set_result(nagios_status_to_gpb(ret)); 576 } 577 /* 578 static void append_simple_submit_response_payload(Plugin::SubmitResponseMessage::Response *payload, std::string command, Plugin::Common::ResultCode ret, std::string msg) { 579 payload->set_command(command); 580 payload->mutable_status()->set_status(gbp_to_nagios_gbp_status(ret)); 581 payload->mutable_status()->set_message(msg); 582 } 583 */ 584 static void append_simple_submit_response_payload(Plugin::SubmitResponseMessage::Response *payload, std::string command, int ret, std::string msg) { 585 payload->set_command(command); 586 payload->mutable_status()->set_status(status_to_gpb(ret)); 587 payload->mutable_status()->set_message(msg); 442 588 } 443 589 … … 546 692 } 547 693 548 static void create_simple_exec_response(std::wstring command, NSCAPI::nagiosReturn ret, std::wstring result, std::string &response) { 694 template<class T> 695 static int create_simple_exec_response(T command, NSCAPI::nagiosReturn ret, T result, std::string &response) { 549 696 Plugin::ExecuteResponseMessage message; 550 697 create_simple_header(message.mutable_header()); … … 556 703 payload->set_result(nagios_status_to_gpb(ret)); 557 704 message.SerializeToString(&response); 705 return ret; 706 } 707 template<class T> 708 static int create_simple_exec_response_unknown(T command, T result, std::string &response) { 709 Plugin::ExecuteResponseMessage message; 710 create_simple_header(message.mutable_header()); 711 712 Plugin::ExecuteResponseMessage::Response *payload = message.add_payload(); 713 payload->set_command(to_string(command)); 714 payload->set_message(to_string(result)); 715 716 payload->set_result(nagios_status_to_gpb(NSCAPI::returnUNKNOWN)); 717 message.SerializeToString(&response); 718 return NSCAPI::returnUNKNOWN; 558 719 } 559 720 static decoded_simple_command_data parse_simple_exec_request(const wchar_t* char_command, const std::string &request) { … … 587 748 ////////////////////////////////////////////////////////////////////////// 588 749 589 static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::wstring &perf) { 590 boost::tokenizer<boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring> tok(perf, boost::escaped_list_separator<wchar_t>(L'\\', L' ', L'\'')); 591 BOOST_FOREACH(std::wstring s, tok) { 750 template<class T, class U> 751 struct tokenizer_data { 752 boost::escaped_list_separator<U> separator; // \\, ' ', \' 753 T perf_item_splitter; // ; 754 T perf_equal_sign; // = 755 T perf_valid_number; // 0123456789., 756 757 }; 758 759 template<class T, class U> 760 static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, T &perf, tokenizer_data<T, U> tokenizer_data) { 761 boost::tokenizer<boost::escaped_list_separator<U>, typename T::const_iterator, T> tok(perf, tokenizer_data.separator); 762 BOOST_FOREACH(const T s, tok) { 592 763 if (s.size() == 0) 593 764 break; 594 st rEx::splitVector items = strEx::splitV(s, _T(";"));765 std::vector<T> items = strEx::splitV(s, tokenizer_data.perf_item_splitter); 595 766 if (items.size() < 1) { 596 767 Plugin::Common::PerformanceData* perfData = payload->add_perf(); 597 768 perfData->set_type(Plugin::Common_DataType_STRING); 598 std::pair< std::wstring,std::wstring> fitem = strEx::split(_T(""), _T("="));769 std::pair<T,T> fitem = strEx::split(T(), tokenizer_data.perf_equal_sign); 599 770 perfData->set_alias("invalid"); 600 771 Plugin::Common_PerformanceData_StringValue* stringPerfData = perfData->mutable_string_value(); … … 605 776 Plugin::Common::PerformanceData* perfData = payload->add_perf(); 606 777 perfData->set_type(Plugin::Common_DataType_FLOAT); 607 std::pair< std::wstring,std::wstring> fitem = strEx::split(items[0], _T("="));778 std::pair<T,T> fitem = strEx::split(items[0], tokenizer_data.perf_equal_sign); 608 779 perfData->set_alias(to_string(fitem.first)); 609 780 Plugin::Common_PerformanceData_FloatValue* floatPerfData = perfData->mutable_float_value(); 610 781 611 std::wstring::size_type pend = fitem.second.find_first_not_of(_T("0123456789,."));612 if (pend == std::wstring::npos) {613 floatPerfData->set_value(trim_to_double(fitem.second .c_str()));782 typename T::size_type pend = fitem.second.find_first_not_of(tokenizer_data.perf_valid_number); 783 if (pend == T::npos) { 784 floatPerfData->set_value(trim_to_double(fitem.second)); 614 785 } else { 615 floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend) .c_str()));786 floatPerfData->set_value(trim_to_double(fitem.second.substr(0,pend))); 616 787 floatPerfData->set_unit(to_string(fitem.second.substr(pend))); 617 788 } … … 625 796 } 626 797 } 627 // std::wcout << _T("Converting performance data") << perf << _T(" -- ") << utf8::cvt<std::wstring>(build_performance_data(*resp)) << std::endl; 628 } 798 } 799 static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::wstring &perf) { 800 typedef std::wstring t_string; 801 typedef wchar_t t_char; 802 tokenizer_data<t_string, t_char> data; 803 data.separator = boost::escaped_list_separator<t_char>(L'\\', L' ', L'\''); 804 data.perf_equal_sign = _T("="); 805 data.perf_item_splitter = _T(";"); 806 data.perf_valid_number = _T("0123456789,."); 807 parse_performance_data<t_string, t_char>(payload, perf, data); 808 } 809 static void parse_performance_data(Plugin::QueryResponseMessage::Response *payload, std::string &perf) { 810 typedef std::string t_string; 811 typedef char t_char; 812 tokenizer_data<t_string, t_char> data; 813 data.separator = boost::escaped_list_separator<t_char>('\\', ' ', '\''); 814 data.perf_equal_sign = "="; 815 data.perf_item_splitter = ";"; 816 data.perf_valid_number = "0123456789,."; 817 parse_performance_data<t_string, t_char>(payload, perf, data); 818 } 819 629 820 static std::string build_performance_data(Plugin::QueryResponseMessage::Response const &payload) { 630 821 std::stringstream ss; -
include/strEx.h
r96c1461 rf33c12f 548 548 return boost::lexical_cast<int>(s.c_str()); 549 549 } 550 inline double stod(std::wstring s) { 550 template<class T> 551 inline double stod(T s) { 551 552 return boost::lexical_cast<double>(s.c_str()); 552 553 } … … 749 750 } 750 751 typedef std::vector<std::wstring> splitVector; 751 inline splitVector splitV(const std::wstring str, const std::wstring key) { 752 splitVector ret; 753 std::wstring::size_type pos = 0, lpos = 0; 754 while ((pos = str.find(key, pos)) != std::wstring::npos) { 752 template<class T> 753 inline std::vector<T> splitV(const T str, const T key) { 754 std::vector<T> ret; 755 typename T::size_type pos = 0, lpos = 0; 756 while ((pos = str.find(key, pos)) != T::npos) { 755 757 ret.push_back(str.substr(lpos, pos-lpos)); 756 758 lpos = ++pos; … … 789 791 return trim_left( trim_right( str , t) , t ); 790 792 } 791 inline std::pair<std::wstring,std::wstring> split(std::wstring str, std::wstring key) { 792 std::wstring::size_type pos = str.find(key); 793 if (pos == std::wstring::npos) 794 return std::pair<std::wstring,std::wstring>(str, _T("")); 795 return std::pair<std::wstring,std::wstring>(str.substr(0, pos), str.substr(pos+key.length())); 793 template<class T> 794 inline std::pair<T,T> split(T str, T key) { 795 typename T::size_type pos = str.find(key); 796 if (pos == T::npos) 797 return std::pair<T,T>(str, T()); 798 return std::pair<T,T>(str.substr(0, pos), str.substr(pos+key.length())); 796 799 } 797 800 typedef std::pair<std::wstring,std::wstring> token; … … 1056 1059 return utf8::cvt<std::string>(arg); 1057 1060 } 1061 template <typename T> std::string to_string(const wchar_t* arg) { 1062 return utf8::cvt<std::string>(std::wstring(arg)); 1063 } 1058 1064 template <typename T> std::wstring to_wstring(const T& arg) { 1059 1065 try { -
include/utils.h
r7443b58 rf33c12f 31 31 #define MAP_OPTIONS_BEGIN(args) \ 32 32 for (std::list<std::wstring>::const_iterator cit__=args.begin();cit__!=args.end();++cit__) { \ 33 std::pair<std::wstring,std::wstring> p__ = strEx::split(*cit__, _T("=")); if (false) {}33 std::pair<std::wstring,std::wstring> p__ = strEx::split(*cit__,std::wstring(_T("="))); if (false) {} 34 34 35 35 #define MAP_OPTIONS_SHOWALL(obj) \ … … 108 108 #define MAP_OPTIONS_SECONDARY_BEGIN(splt, arg) \ 109 109 else if (p__.first.find(splt) != std::wstring::npos) { \ 110 std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,s plt); if (false) {}110 std::pair<std::wstring,std::wstring> arg = strEx::split(p__.first,std::wstring(splt)); if (false) {} 111 111 112 112 #define MAP_OPTIONS_SECONDARY_STR_AND(opt, value, objfirst, objsecond, extra) \
Note: See TracChangeset
for help on using the changeset viewer.








