Echo Writes Code

windows_utility.cpp

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
#include "crucible/core/windows_utility.hpp"

#include <Windows.h>

namespace crucible::core
{
  Windows_Local_Memory_Guard::Windows_Local_Memory_Guard(void *pointer) :
    my_pointer { pointer }
  {}

  Windows_Local_Memory_Guard::Windows_Local_Memory_Guard(Windows_Local_Memory_Guard &&that) noexcept :
    my_pointer { that.my_pointer }
  {
    that.my_pointer = nullptr;
  }

  Windows_Local_Memory_Guard::~Windows_Local_Memory_Guard() noexcept
  {
    if (my_pointer) {
      ::LocalFree(my_pointer);
    }
  }

  auto Windows_Local_Memory_Guard::operator=(Windows_Local_Memory_Guard &&that) noexcept -> Windows_Local_Memory_Guard &
  {
    if (my_pointer) {
      ::LocalFree(my_pointer);
    }

    my_pointer = that.my_pointer;
    that.my_pointer = nullptr;
  }

  auto Windows_Local_Memory_Guard::pointer() const noexcept -> void *
  {
    return my_pointer;
  }
}