Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef DGW_STRATEGY_MANAGER_H
12 : #define DGW_STRATEGY_MANAGER_H
13 :
14 : #include <map>
15 : #include "common/type_def.h"
16 : #include "dgw_client.h"
17 : #include "strategy.h"
18 :
19 : namespace dgw {
20 :
21 : class StrategyManager {
22 : public:
23 1 : explicit StrategyManager() = default;
24 1 : ~StrategyManager() = default;
25 :
26 : StrategyManager(const StrategyManager&) = delete;
27 : StrategyManager(const StrategyManager&&) = delete;
28 : StrategyManager& operator=(const StrategyManager&) = delete;
29 : StrategyManager& operator=(StrategyManager&&) = delete;
30 :
31 : public:
32 : static StrategyManager& GetInstance();
33 : void RegisterStrategy(const bqs::GroupPolicy policy, Strategy* strategy, const char_t* const strategyDesc);
34 : Strategy* GetStrategy(const bqs::GroupPolicy policy) const;
35 : const std::string& GetStrategyDesc(const bqs::GroupPolicy policy) const;
36 :
37 : private:
38 : std::map<bqs::GroupPolicy, Strategy*> strategy_;
39 : std::map<bqs::GroupPolicy, std::string> strategyDesc_;
40 : };
41 :
42 : // strategy register
43 : class StrategyRegister {
44 : public:
45 2 : StrategyRegister(const bqs::GroupPolicy policy, Strategy* strategy, const char_t* const strategyDesc)
46 : {
47 2 : StrategyManager::GetInstance().RegisterStrategy(policy, strategy, strategyDesc);
48 2 : }
49 :
50 : ~StrategyRegister() = default;
51 : StrategyRegister(const StrategyRegister&) = delete;
52 : StrategyRegister(const StrategyRegister&&) = delete;
53 : StrategyRegister& operator=(const StrategyRegister&) = delete;
54 : StrategyRegister& operator=(StrategyRegister&&) = delete;
55 : };
56 :
57 : #define REGISTER_STRATEGY(policy, strategy) \
58 : strategy g_##strategy; \
59 : StrategyRegister g_##strategy##_register(bqs::GroupPolicy::policy, &g_##strategy, #policy)
60 : } // namespace dgw
61 : #endif
|