• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTERFACE_OBJECTS_BASE_STRING_TABLE_H
17 #define COMMON_INTERFACE_OBJECTS_BASE_STRING_TABLE_H
18 
19 #include "objects/readonly_handle.h"
20 #include "thread/thread_holder.h"
21 
22 namespace common {
23 class BaseString;
24 
25 template <typename Impl>
26 class BaseStringTableInterface {
27 public:
BaseStringTableInterface()28     BaseStringTableInterface() {}
29 
30     using HandleCreator = std::function<ReadOnlyHandle<BaseString>(ThreadHolder *, BaseString *)>;
31 
GetOrInternFlattenString(ThreadHolder * holder,const HandleCreator & handleCreator,BaseString * string)32     BaseString *GetOrInternFlattenString(ThreadHolder *holder, const HandleCreator &handleCreator, BaseString *string)
33     {
34         return static_cast<Impl *>(this)->GetOrInternFlattenString(holder, handleCreator, string);
35     }
36 
GetOrInternStringFromCompressedSubString(ThreadHolder * holder,const HandleCreator & handleCreator,const ReadOnlyHandle<BaseString> & string,uint32_t offset,uint32_t utf8Len)37     BaseString *GetOrInternStringFromCompressedSubString(ThreadHolder *holder, const HandleCreator &handleCreator,
38                                                          const ReadOnlyHandle<BaseString> &string,
39                                                          uint32_t offset, uint32_t utf8Len)
40     {
41         return static_cast<Impl *>(this)->GetOrInternStringFromCompressedSubString(
42             holder, handleCreator, string, offset, utf8Len);
43     }
44 
GetOrInternString(ThreadHolder * holder,const HandleCreator & handleCreator,const uint8_t * utf8Data,uint32_t utf8Len,bool canBeCompress)45     BaseString *GetOrInternString(ThreadHolder *holder, const HandleCreator &handleCreator, const uint8_t *utf8Data,
46                                   uint32_t utf8Len, bool canBeCompress)
47     {
48         return static_cast<Impl *>(this)->GetOrInternString(holder, handleCreator, utf8Data, utf8Len, canBeCompress);
49     }
50 
GetOrInternString(ThreadHolder * holder,const HandleCreator & handleCreator,const uint16_t * utf16Data,uint32_t utf16Len,bool canBeCompress)51     BaseString *GetOrInternString(ThreadHolder *holder, const HandleCreator &handleCreator, const uint16_t *utf16Data,
52                                   uint32_t utf16Len, bool canBeCompress)
53     {
54         return static_cast<Impl *>(this)->GetOrInternString(holder, handleCreator, utf16Data, utf16Len, canBeCompress);
55     }
56 
TryGetInternString(const ReadOnlyHandle<BaseString> & string)57     BaseString *TryGetInternString(const ReadOnlyHandle<BaseString> &string)
58     {
59         return static_cast<Impl *>(this)->TryGetInternString(string);
60     }
61 
62     // Runtime module interfaces
Init()63     void Init() {};
64 
Fini()65     void Fini() {};
66 
67 private:
68     NO_COPY_SEMANTIC_CC(BaseStringTableInterface);
69     NO_MOVE_SEMANTIC_CC(BaseStringTableInterface);
70 };
71 }
72 #endif //COMMON_INTERFACE_OBJECTS_BASE_STRING_TABLE_H