Исходный код СУБД 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
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2019 Microsoft Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEAK_BUFFER_H
#define WEAK_BUFFER_H
 
#include <wrl.h>
#include <wrl/client.h>
 
#include <windows.storage.streams.h>
#include <robuffer.h>
 
namespace WinMLTest {
 
template <typename T>
struct WeakBuffer
  : public Microsoft::WRL::RuntimeClass<
      Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix | Microsoft::WRL::InhibitRoOriginateError>,
      ABI::Windows::Storage::Streams::IBuffer,
      Windows::Storage::Streams::IBufferByteAccess> {
 InspectableClass(L"WinMLTest.WeakBuffer", BaseTrust)
 
   private : const T* m_p_begin;
  const T* m_p_end;
 
 public:
  HRESULT RuntimeClassInitialize(_In_ const T* p_begin, _In_ const T* p_end) {
    m_p_begin = p_begin;
    m_p_end = p_end;
 
    return S_OK;
  }
 
  virtual HRESULT STDMETHODCALLTYPE get_Capacity(UINT32* value) {
    if (value == nullptr) {
      return E_POINTER;
    }
 
    *value = static_cast<uint32_t>(m_p_end - m_p_begin) * sizeof(T);
    return S_OK;
  }
 
  virtual HRESULT STDMETHODCALLTYPE get_Length(UINT32* value) {
    if (value == nullptr) {
      return E_POINTER;
    }
    *value = static_cast<uint32_t>(m_p_end - m_p_begin) * sizeof(T);
    return S_OK;
  }
 
  virtual HRESULT STDMETHODCALLTYPE put_Length(UINT32 /*value*/) { return E_NOTIMPL; }
 
  STDMETHOD(Buffer)(uint8_t** value) {
    if (value == nullptr) {
      return E_POINTER;
    }
 
    *value = reinterpret_cast<uint8_t*>(const_cast<T*>(m_p_begin));
    return S_OK;
  }
};
 
}  // namespace WinMLTest
 
#endif  // WEAK_BUFFER_H