1/*
2 * Copyright (c) 2024 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#ifndef META_SRC_PROPERTY_DEPENDENCIES_H
16#define META_SRC_PROPERTY_DEPENDENCIES_H
17
18#include "property.h"
19
20META_BEGIN_NAMESPACE()
21namespace Internal {
22
23// changing this will disable the check in property GetValue
24constexpr bool ENABLE_DEPENDENCY_CHECK = true;
25
26class Dependencies {
27public:
28    bool IsActive() const;
29
30    void Start();
31    void End();
32
33    ReturnError AddDependency(const IProperty::ConstPtr& prop);
34    ReturnError GetImmediateDependencies(BASE_NS::vector<IProperty::ConstPtr>& deps) const;
35    bool HasDependency(const IProperty*) const;
36
37private:
38    bool active_ {};
39    uint32_t depth_ {};
40
41    ReturnError state_ { GenericError::SUCCESS };
42
43    struct Dependancy {
44        IProperty::ConstPtr property;
45        uint64_t depth {};
46    };
47    BASE_NS::vector<Dependancy> deps_;
48    BASE_NS::vector<Dependancy> deps_branch_;
49};
50
51Dependencies& GetDeps();
52
53} // namespace Internal
54META_END_NAMESPACE()
55
56#endif