1 // Copyright 2021 The Abseil Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ABSL_STRINGS_INTERNAL_CORD_REP_CONSUME_H_ 16 #define ABSL_STRINGS_INTERNAL_CORD_REP_CONSUME_H_ 17 18 #include <functional> 19 20 #include "absl/functional/function_ref.h" 21 #include "absl/strings/internal/cord_internal.h" 22 23 namespace absl { 24 ABSL_NAMESPACE_BEGIN 25 namespace cord_internal { 26 27 // Functor for the Consume() and ReverseConsume() functions: 28 // void ConsumeFunc(CordRep* rep, size_t offset, size_t length); 29 // See the Consume() and ReverseConsume() function comments for documentation. 30 using ConsumeFn = FunctionRef<void(CordRep*, size_t, size_t)>; 31 32 // Consume() and ReverseConsume() consume CONCAT based trees and invoke the 33 // provided functor with the contained nodes in the proper forward or reverse 34 // order, which is used to convert CONCAT trees into other tree or cord data. 35 // All CONCAT and SUBSTRING nodes are processed internally. The 'offset` 36 // parameter of the functor is non-zero for any nodes below SUBSTRING nodes. 37 // It's up to the caller to form these back into SUBSTRING nodes or otherwise 38 // store offset / prefix information. These functions are intended to be used 39 // only for migration / transitional code where due to factors such as ODR 40 // violations, we can not 100% guarantee that all code respects 'new format' 41 // settings and flags, so we need to be able to parse old data on the fly until 42 // all old code is deprecated / no longer the default format. 43 void Consume(CordRep* rep, ConsumeFn consume_fn); 44 void ReverseConsume(CordRep* rep, ConsumeFn consume_fn); 45 46 } // namespace cord_internal 47 ABSL_NAMESPACE_END 48 } // namespace absl 49 50 #endif // ABSL_STRINGS_INTERNAL_CORD_REP_CONSUME_H_ 51