1 /*
2  * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_BASE_MEMORY_MEMORY_MONITOR_DEF_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_MEMORY_MEMORY_MONITOR_DEF_H
18 
19 #include <string>
20 
21 #include "base/utils/macros.h"
22 
23 
24 #define VERIFY_CLASSNAME(classname, p) \
25     OHOS::Ace::VerifyClass<std::is_same_v<classname, std::remove_cv_t<std::remove_pointer_t<decltype(p)>>>>::Success()
26 
27 #define VERIFY_DECLARED_CLASS(classname) \
28     OHOS::Ace::VerifyClass<std::is_same_v<classname, typename classname::SelfType>>::Success()
29 
30 #define DECLARE_CLASS_TYPE_SIZE(classname)                              \
31     typedef classname SelfType;                                         \
32     static size_t TypeSize()                                            \
33     {                                                                   \
34         return sizeof(classname);                                       \
35     }
36 
37 #define DECLARE_CLASS_GET_TYPE_SIZE(classname)                          \
38     size_t GetTypeSize() const override                                 \
39     {                                                                   \
40         VERIFY_CLASSNAME(classname, this);                              \
41         return TypeSize();                                              \
42     }
43 
44 namespace OHOS::Ace {
45 
46 template<bool>
47 struct VerifyClass;
48 
49 template<>
50 struct VerifyClass<true> {
51     static void Success() {}
52 };
53 
54 } // namespace OHOS::Ace
55 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_MEMORY_MEMORY_MONITOR_DEF_H
56