1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 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 * http://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 16 #ifndef COMMON_INTERFACES_OBJECTS_STRING_TREE_STRING_H 17 #define COMMON_INTERFACES_OBJECTS_STRING_TREE_STRING_H 18 19 #include "common_interfaces/objects/string/base_string_declare.h" 20 21 namespace common { 22 /* 23 +-----------------------------+ <-- offset 0 24 | BaseObject fields | 25 +-----------------------------+ 26 | LengthAndFlags (uint32_t) | 27 +-----------------------------+ 28 | RawHashcode (uint32_t) | 29 +-----------------------------+ <-- offset = BaseString::SIZE 30 | First (BaseString *) | <-- FIRST_OFFSET 31 +-----------------------------+ 32 | Second (BaseString *) | <-- SECOND_OFFSET 33 +-----------------------------+ <-- SIZE 34 */ 35 class TreeString : public BaseString { 36 public: 37 BASE_CAST_CHECK(TreeString, IsTreeString); 38 39 NO_MOVE_SEMANTIC_CC(TreeString); 40 NO_COPY_SEMANTIC_CC(TreeString); 41 // Minimum length for a tree string 42 static constexpr uint32_t MIN_TREE_STRING_LENGTH = 13; 43 44 static constexpr size_t FIRST_OFFSET = BaseString::SIZE; 45 POINTER_FIELD(First, FIRST_OFFSET, SECOND_OFFSET); 46 POINTER_FIELD(Second, SECOND_OFFSET, SIZE); 47 48 template <typename ReadBarrier> 49 bool IsFlat(ReadBarrier &&readBarrier) const; 50 51 template <bool verify = true, typename ReadBarrier> 52 uint16_t Get(ReadBarrier &&readBarrier, int32_t index) const; 53 }; 54 } 55 #endif //COMMON_INTERFACES_OBJECTS_STRING_TREE_STRING_H