Files
UnrealEngineUWP/Engine/Source/Developer/Windows/LiveCoding/Private/External/LC_PointerUtil.h
ben marsh e40dec9ee0 Integrating live coding feature (aka Live++) into UE4.
Allows fast iteration of C++ changes without restarting the application. To use, select the "Live Coding (Experimental)" mode from the drop down menu next to the editor's compile button, or type "LiveCoding" into the console for a monolithic build. Press Ctrl+Alt+F11 to find changes and compile.

Changes vs standalone Live++ version:

* UBT is used to execute builds. This allows standard UE4 adaptive unity mode, allows us to reuse object files when we do regular builds, supports using any build executor allowed by UBT (XGE, SNDBS, etc..).
* Adding new source files is supported.
* Custom visualizer for FNames is supported via a weakly linked symbol in a static library (Engine/Extras/NatvisHelpers).
* Settings are exposed in the editor's project settings dialog.
* Standalone application has been rewritten as a Slate app ("LiveCodingConsole"). There is an additional option to start the program as hidden, where it will not be visible until Ctrl+Alt+F11 is hit. Similarly, closing the window will hide it instead of closing the application.
* Does not require a standalone licensed version of Live++.

Known issues:

* Does not currently support class layout changes / object reinstancing

#rb none
[FYI] Marc.Audy, Stefan.Boberg, Nick.Penwarden
#jira

#ROBOMERGE-OWNER: ryan.vance
#ROBOMERGE-AUTHOR: ben.marsh
#ROBOMERGE-SOURCE: CL 5304722 in //UE4/Release-4.22/... via CL 5309051
#ROBOMERGE-BOT: DEVVR (Main -> Dev-VR)

[CL 5329502 by ben marsh in Dev-VR branch]
2019-03-06 18:34:25 -05:00

154 lines
3.1 KiB
C++

// Copyright 2011-2019 Molecular Matters GmbH, all rights reserved.
#pragma once
#include "CoreTypes.h"
#include <type_traits>
namespace pointer
{
template <typename T>
T AsInteger(const void* anyPointer)
{
// unfortunately, conversion from pointers to integers is implementation-defined, which is sign-extended in MSVC and GCC.
// this means that e.g. converting directly from void* to uint64_t would sign-extend on 32-bit, which is not what we want.
// in order to convert without sign-extension on both 32-bit and 64-bit targets, we need to go via uintptr_t first.
return static_cast<T>(reinterpret_cast<const uintptr_t>(anyPointer));
}
template <typename T>
T AlignBottom(void* anyPointer, size_t alignment)
{
union
{
void* as_void;
uintptr_t as_uintptr_t;
};
as_void = anyPointer;
const size_t mask = alignment - 1u;
as_uintptr_t &= ~mask;
return As<T>(as_void);
}
template <typename T>
T AlignBottom(const void* anyPointer, size_t alignment)
{
union
{
const void* as_void;
uintptr_t as_uintptr_t;
};
as_void = anyPointer;
const size_t mask = alignment - 1u;
as_uintptr_t &= ~mask;
return As<T>(as_void);
}
template <typename T>
T AlignTop(void* anyPointer, size_t alignment)
{
union
{
void* as_void;
uintptr_t as_uintptr_t;
};
as_void = anyPointer;
const size_t mask = alignment - 1u;
as_uintptr_t += mask;
as_uintptr_t &= ~mask;
return As<T>(as_void);
}
template <typename T>
T AlignTop(const void* anyPointer, size_t alignment)
{
union
{
const void* as_void;
uintptr_t as_uintptr_t;
};
as_void = anyPointer;
const size_t mask = alignment - 1u;
as_uintptr_t += mask;
as_uintptr_t &= ~mask;
return As<T>(as_void);
}
template <typename T>
T As(void* anyPointer)
{
// only a check for pointer-type needed here.
// T can point to const or non-const type.
static_assert(std::is_pointer<T>::value == true, "Expected pointer type");
union
{
void* as_void;
T as_T;
};
as_void = anyPointer;
return as_T;
}
template <typename T>
T As(const void* anyPointer)
{
static_assert(std::is_pointer<T>::value == true, "Expected pointer type");
// enforce T being a pointer to const elements
static_assert(std::is_const<std::remove_pointer<T>::type>::value == true, "Wrong cv-qualifiers.");
union
{
const void* as_void;
T as_T;
};
as_void = anyPointer;
return as_T;
}
template <typename T, typename U>
T Offset(void* anyPointer, U howManyBytes)
{
static_assert(std::is_pointer<T>::value == true, "Expected pointer type");
return As<T>((As<char*>(anyPointer) + howManyBytes));
}
template <typename T, typename U>
T Offset(const void* anyPointer, U howManyBytes)
{
static_assert(std::is_pointer<T>::value == true, "Expected pointer type");
return As<T>((As<const char*>(anyPointer) + howManyBytes));
}
template <typename T>
T Displacement(const void* from, const void* to)
{
static_assert(std::is_pointer<T>::value == false, "Expected value type");
return static_cast<T>(As<const char*>(to) - As<const char*>(from));
}
}