Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#pragma once
 
#include <napi.h>
 
#include <sstream>
#include <vector>
 
inline void MakeStringInternal(std::ostringstream& /*ss*/) noexcept {}
 
template <typename T>
inline void MakeStringInternal(std::ostringstream& ss, const T& t) noexcept { ss << t; }
 
template <typename T, typename... Args>
inline void MakeStringInternal(std::ostringstream& ss, const T& t, const Args&... args) noexcept {
  ::MakeStringInternal(ss, t);
  ::MakeStringInternal(ss, args...);
}
 
template <typename... Args>
std::string MakeString(const Args&... args) {
  std::ostringstream ss;
  ::MakeStringInternal(ss, args...);
  return std::string(ss.str());
}
 
#define ORT_NAPI_THROW(ERROR, ENV, ...)                     \
  do {                                                      \
    throw Napi::ERROR::New((ENV), MakeString(__VA_ARGS__)); \
  } while (false)
#define ORT_NAPI_THROW_ERROR(ENV, ...) ORT_NAPI_THROW(Error, ENV, __VA_ARGS__)
#define ORT_NAPI_THROW_TYPEERROR(ENV, ...) ORT_NAPI_THROW(TypeError, ENV, __VA_ARGS__)
#define ORT_NAPI_THROW_RANGEERROR(ENV, ...) ORT_NAPI_THROW(RangeError, ENV, __VA_ARGS__)
 
#define ORT_NAPI_THROW_IF(COND, ERROR, ENV, ...) \
  if (COND) {                                    \
    ORT_NAPI_THROW(ERROR, ENV, __VA_ARGS__);     \
  }
#define ORT_NAPI_THROW_ERROR_IF(COND, ENV, ...) ORT_NAPI_THROW_IF(COND, Error, ENV, __VA_ARGS__)
#define ORT_NAPI_THROW_TYPEERROR_IF(COND, ENV, ...) ORT_NAPI_THROW_IF(COND, TypeError, ENV, __VA_ARGS__)
#define ORT_NAPI_THROW_RANGEERROR_IF(COND, ENV, ...) ORT_NAPI_THROW_IF(COND, RangeError, ENV, __VA_ARGS__)
 
template <typename T>
Napi::Value CreateNapiArrayFrom(napi_env env, const std::vector<T>& vec) {
  Napi::EscapableHandleScope scope(env);
  auto array = Napi::Array::New(env, vec.size());
  for (uint32_t i = 0; i < vec.size(); i++) {
    array.Set(i, Napi::Value::From(env, vec[i]));
  }
  return scope.Escape(array);
}