14#ifndef OR_TOOLS_BASE_PROTOBUF_UTIL_H_
15#define OR_TOOLS_BASE_PROTOBUF_UTIL_H_
19#include "google/protobuf/repeated_field.h"
20#include "google/protobuf/text_format.h"
28inline void Truncate(RepeatedPtrField<T>* array,
int new_size) {
29 const int size = array->size();
31 array->DeleteSubrange(new_size, size - new_size);
36inline void Truncate(RepeatedField<T>* array,
int new_size) {
38 array->Truncate(new_size);
49template <
typename RepeatedType,
typename IndexContainer = std::vector<
int>>
50int RemoveAt(RepeatedType* array,
const IndexContainer& indices) {
51 if (indices.size() == 0) {
54 const int num_indices = indices.size();
55 const int num_elements = array->size();
57 if (num_indices == num_elements) {
62 typename IndexContainer::const_iterator remove_iter = indices.begin();
63 int write_index = *(remove_iter++);
64 for (
int scan = write_index + 1; scan < num_elements; ++scan) {
65 if (remove_iter != indices.end() && *remove_iter == scan) {
68 array->SwapElements(scan, write_index++);
71 DCHECK_EQ(write_index, num_elements - num_indices);
79 CHECK(TextFormat::MergeFromString(
input, &result));
#define DCHECK_LE(val1, val2)
#define DCHECK_GE(val1, val2)
#define DCHECK_EQ(val1, val2)
int RemoveAt(RepeatedType *array, const IndexContainer &indices)
T ParseTextOrDie(const std::string &input)
void Truncate(RepeatedPtrField< T > *array, int new_size)
static int input(yyscan_t yyscanner)