Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <string>
#include <type_traits>
#include <variant>
 
#include "core/common/inlined_containers.h"
 
namespace onnxruntime::training::api {
 
using PropertyDataType = std::variant<int64_t, float, std::string>;
 
/**
 * @brief Collection of user defined properties.
 * Currently supported scalar value of type int64_t, float, and std::string only.
 */
struct PropertyBag {
 public:
  PropertyBag() = default;
 
  void AddProperty(const std::string& name, const PropertyDataType& val) {
    auto it = named_properties_.find(name);
    if (it == named_properties_.end()) {
      named_properties_.insert({name, val});
    } else {
      it->second = val;
    }
  }
 
  template <typename T>
  T GetProperty(const std::string& name) const {
    auto it = named_properties_.find(name);
    ORT_ENFORCE(it != named_properties_.end(), "No property named ", name);
 
    const T* tval = std::get_if<T>(&it->second);
    ORT_ENFORCE(tval, "Fail to get the property value using specified type.");
    return *tval;
  }
 
  auto begin() const {
    return named_properties_.begin();
  }
 
  auto end() const {
    return named_properties_.end();
  }
 
  size_t size() const {
    return named_properties_.size();
  }
 
  bool HasProperty(const std::string& property_name) const {
    return named_properties_.count(property_name);
  }
 
 private:
  InlinedHashMap<std::string, PropertyDataType> named_properties_;
};
 
template <>
inline PropertyDataType PropertyBag::GetProperty<PropertyDataType>(const std::string& name) const {
  auto it = named_properties_.find(name);
  ORT_ENFORCE(it != named_properties_.end(), "No property named ", name);
 
  return it->second;
}
 
}  // namespace onnxruntime::training::api