• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef OHOS_DISTRIBUTED_DATA_INTERFACE_GDB_GRAPH_VERTEX_H
17 #define OHOS_DISTRIBUTED_DATA_INTERFACE_GDB_GRAPH_VERTEX_H
18 #include <cstdint>
19 #include <functional>
20 #include <memory>
21 #include <string>
22 #include <variant>
23 #include <vector>
24 
25 #include "nlohmann/json.hpp"
26 #include "rdb_visibility.h"
27 
28 namespace OHOS::DistributedDataAip {
29 using PropType = std::variant<int64_t, double, std::string, bool, std::nullptr_t>;
30 class Vertex {
31 public:
32     API_EXPORT Vertex();
33     API_EXPORT Vertex(std::string id, std::string label);
34     API_EXPORT Vertex(std::string id, std::string label, const std::unordered_map<std::string, PropType> &properties);
35     static std::shared_ptr<Vertex> Parse(const nlohmann::json &json, int32_t &errCode);
36 
37     API_EXPORT std::string GetId() const;
38     API_EXPORT void SetId(std::string id);
39 
40     API_EXPORT const std::string &GetLabel() const;
41     API_EXPORT const std::vector<std::string> &GetLabels() const;
42     API_EXPORT void SetLabel(const std::string &label);
43 
44     API_EXPORT const std::unordered_map<std::string, PropType> &GetProperties() const;
45     API_EXPORT void SetProperty(const std::string &key, PropType value);
46 
47     static constexpr const char *ID = "identity";
48     static constexpr const char *LABEL = "label";
49     static constexpr const char *PROPERTIES = "properties";
50 
51 protected:
52     std::string id_;
53     std::string label_;
54     std::vector<std::string> labels_;
55     std::unordered_map<std::string, PropType> properties_;
56 };
57 } // namespace OHOS::DistributedDataAip
58 #endif //OHOS_DISTRIBUTED_DATA_INTERFACE_GDB_GRAPH_VERTEX_H
59