mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-09-01 14:33:18 +08:00
29 lines
654 B
C++
29 lines
654 B
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <iterator>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace crossdesk::server_window_state {
|
|
|
|
inline int ReconcileSelectedController(const std::vector<std::string>& ids,
|
|
std::string* selected_id) {
|
|
if (!selected_id) {
|
|
return 0;
|
|
}
|
|
if (ids.empty()) {
|
|
selected_id->clear();
|
|
return 0;
|
|
}
|
|
|
|
const auto selected = std::find(ids.begin(), ids.end(), *selected_id);
|
|
if (selected == ids.end()) {
|
|
*selected_id = ids.front();
|
|
return 0;
|
|
}
|
|
return static_cast<int>(std::distance(ids.begin(), selected));
|
|
}
|
|
|
|
} // namespace crossdesk::server_window_state
|