rewrite SESSION_PROTO.search
rewrite ASIO NETSERVICE.asyncReceive rewrite ASIO NETSESSION
This commit is contained in:
@@ -41,52 +41,67 @@ struct AdcStopSeqSessionProto {
|
||||
return "STOP SEQUENCE PROTO";
|
||||
}
|
||||
|
||||
// template <traits::adc_input_char_range R>
|
||||
// auto search(const R& r)
|
||||
// {
|
||||
// std::tuple<std::ranges::iterator_t<R>, std::ranges::iterator_t<R>, bool> res{r.begin(), r.end(), false};
|
||||
|
||||
// if (!r.size()) {
|
||||
// return res;
|
||||
// }
|
||||
|
||||
// // std::get<1>(res) = std::search(r.begin(), r.end(), STOP_SEQ.begin(), STOP_SEQ.end());
|
||||
// auto found = std::ranges::search(r, STOP_SEQ);
|
||||
// // if (std::get<1>(res) != r.end()) { // move iterator to the one-past-the-end position
|
||||
// if (!found.empty()) { // move iterator to the one-past-the-end position
|
||||
// // std::advance(std::get<1>(res), STOP_SEQ_SIZE);
|
||||
// // std::get<1>(res) = found.begin() + STOP_SEQ_SIZE;
|
||||
// std::get<1>(res) = found.end();
|
||||
// std::get<2>(res) = true;
|
||||
// }
|
||||
|
||||
// return res;
|
||||
// }
|
||||
|
||||
template <traits::adc_input_char_range R>
|
||||
auto search(const R& r)
|
||||
{
|
||||
std::tuple<std::ranges::iterator_t<R>, std::ranges::iterator_t<R>, bool> res{r.begin(), r.end(), false};
|
||||
|
||||
if (!r.size()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// std::get<1>(res) = std::search(r.begin(), r.end(), STOP_SEQ.begin(), STOP_SEQ.end());
|
||||
auto found = std::ranges::search(r, STOP_SEQ);
|
||||
// if (std::get<1>(res) != r.end()) { // move iterator to the one-past-the-end position
|
||||
if (!found.empty()) { // move iterator to the one-past-the-end position
|
||||
// std::advance(std::get<1>(res), STOP_SEQ_SIZE);
|
||||
// std::get<1>(res) = found.begin() + STOP_SEQ_SIZE;
|
||||
std::get<1>(res) = found.end();
|
||||
std::get<2>(res) = true;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
template <std::input_iterator IT>
|
||||
auto search(IT begin, IT end)
|
||||
{
|
||||
std::tuple<IT, IT, bool> res{begin, end, false};
|
||||
|
||||
if (begin == end) {
|
||||
if constexpr (std::ranges::viewable_range<R>) {
|
||||
return found.empty() ? std::span(r.begin(), r.begin()) : std::span(r.begin(), found.end());
|
||||
} else {
|
||||
std::vector<char> res; // to guaranty adc_output_char_range
|
||||
if (!found.empty()) {
|
||||
std::copy(r.begin(), found.end(), std::back_inserter(res));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
auto it = std::search(begin, end, STOP_SEQ.begin(), STOP_SEQ.end());
|
||||
if (it != end) {
|
||||
// std::advance(it, STOP_SEQ_SIZE); // move iterator to the one-past-the-end position
|
||||
std::get<1>(res) = it + STOP_SEQ_SIZE;
|
||||
std::get<2>(res) = true;
|
||||
} else {
|
||||
// may be only a part of valid byte sequence was received,
|
||||
// so start next matching from previous begin-iterator
|
||||
std::get<1>(res) = begin;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// template <std::input_iterator IT>
|
||||
// auto search(IT begin, IT end)
|
||||
// {
|
||||
// std::tuple<IT, IT, bool> res{begin, end, false};
|
||||
|
||||
// if (begin == end) {
|
||||
// return res;
|
||||
// }
|
||||
|
||||
// auto it = std::search(begin, end, STOP_SEQ.begin(), STOP_SEQ.end());
|
||||
// if (it != end) {
|
||||
// // std::advance(it, STOP_SEQ_SIZE); // move iterator to the one-past-the-end position
|
||||
// std::get<1>(res) = it + STOP_SEQ_SIZE;
|
||||
// std::get<2>(res) = true;
|
||||
// } else {
|
||||
// // may be only a part of valid byte sequence was received,
|
||||
// // so start next matching from previous begin-iterator
|
||||
// std::get<1>(res) = begin;
|
||||
// }
|
||||
|
||||
// return res;
|
||||
// }
|
||||
|
||||
template <traits::adc_input_char_range R>
|
||||
auto toProto(const R& r)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user