/////////////////////////////////////////////////////////////////////////// Re-implementation, using direct Task access instead of data copies that require re-parsing. Essentially a static implementation of a dynamic operator<.
| 114 | // |
| 115 | // Essentially a static implementation of a dynamic operator<. |
| 116 | static bool sort_compare(int left, int right) { |
| 117 | std::string field; |
| 118 | bool ascending; |
| 119 | bool breakIndicator; |
| 120 | Column* column; |
| 121 | int left_number; |
| 122 | int right_number; |
| 123 | float left_real; |
| 124 | float right_real; |
| 125 | |
| 126 | for (auto& k : global_keys) { |
| 127 | Context::getContext().decomposeSortField(k, field, ascending, breakIndicator); |
| 128 | |
| 129 | // Random. |
| 130 | if (field == "random") { |
| 131 | // For "random" sort, we produce a stable number for each task based on a hash of its |
| 132 | // UUID plus the random seed. |
| 133 | std::string left_uuid = (*global_data)[left].get("uuid"); |
| 134 | std::string right_uuid = (*global_data)[right].get("uuid"); |
| 135 | |
| 136 | std::string left_scrambled = |
| 137 | std::to_string(std::hash<std::string>{}(left_uuid + std::to_string(sort_random_seed))); |
| 138 | std::string right_scrambled = |
| 139 | std::to_string(std::hash<std::string>{}(right_uuid + std::to_string(sort_random_seed))); |
| 140 | |
| 141 | if (left_scrambled == right_scrambled) continue; |
| 142 | |
| 143 | return ascending ? (left_scrambled < right_scrambled) : (left_scrambled > right_scrambled); |
| 144 | } |
| 145 | |
| 146 | // Urgency. |
| 147 | else if (field == "urgency") { |
| 148 | left_real = (*global_data)[left].urgency(); |
| 149 | right_real = (*global_data)[right].urgency(); |
| 150 | |
| 151 | if (left_real == right_real) continue; |
| 152 | |
| 153 | return ascending ? (left_real < right_real) : (left_real > right_real); |
| 154 | } |
| 155 | |
| 156 | // Number. |
| 157 | else if (field == "id") { |
| 158 | left_number = (*global_data)[left].id; |
| 159 | right_number = (*global_data)[right].id; |
| 160 | |
| 161 | if (left_number == right_number) continue; |
| 162 | |
| 163 | return ascending ? (left_number < right_number) : (left_number > right_number); |
| 164 | } |
| 165 | |
| 166 | // String. |
| 167 | else if (field == "description" || field == "project" || field == "status" || field == "tags" || |
| 168 | field == "uuid" || field == "parent" || field == "imask" || field == "mask") { |
| 169 | auto left_string = (*global_data)[left].get_ref(field); |
| 170 | auto right_string = (*global_data)[right].get_ref(field); |
| 171 | |
| 172 | if (left_string == right_string) continue; |
| 173 |
nothing calls this directly
no test coverage detected