aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/winapi/debug/address.hpp
blob: a5f186e164b45e59ced6dfa078759ae84ee49f89 (plain) (blame)
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
// Copyright (c) 2017 Egor Tensin <Egor.Tensin@gmail.com>
// This file is part of the "winapi-debug" project.
// For details, see https://github.com/egor-tensin/winapi-debug.
// Distributed under the MIT License.

#pragma once

#include <windows.h>

#include <charconv>
#include <format>
#include <string>

namespace winapi {

typedef DWORD64 Address;

namespace address {

inline std::string format(Address address) {
    return std::format("{:#x}", address);
}

inline std::string format(void* address) {
    return format(reinterpret_cast<Address>(address));
}

inline bool parse(Address& dest, const std::string& src) {
    Address result;
    const auto [ptr, ec] = std::from_chars(src.c_str(), src.c_str() + src.length(), result, 16);
    if (ec == std::errc()) {
        dest = result;
        return true;
    }
    return false;
}

} // namespace address
} // namespace winapi