Created
May 10, 2014 21:33
-
-
Save fire/3c9242fa11ecab30edab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shambler[Bishop author | |
// Hack for accessing private members in various Engine classes | |
// This template, is used to link an arbitrary class member, to the GetPrivate function | |
template<typename Getter, typename Getter::Member Member> struct AccessPrivate | |
{ | |
friend typename Getter::Member GetPrivate(Getter InGetter) | |
{ | |
return Member; | |
} | |
}; | |
// Need to define one of these, for every member you want to access | |
// This is used to aid in linking one member in FStackTracker, to the above template | |
struct FStackTrackerbIsEnabledGetter | |
{ | |
typedef bool FStackTracker::*Member; | |
friend Member GetPrivate(FStackTrackerbIsEnabledGetter); | |
}; | |
// These combine the structs above, with the template for accessing private members, pointing to the specified member | |
template struct AccessPrivate<FStackTrackerbIsEnabledGetter, &FStackTracker::bIsEnabled>; | |
// This is a macro to tidy-up actual accessing of private members, in the below code | |
/** | |
* A macro for for tidying up accessing of private members, through the above code | |
* | |
* @param InClass The class being accessed (not a string, just the class, i.e. FStackTracker) | |
* @param InObj Pointer to an instance of the specified class | |
* @param MemberName Name of the member being accessed (again, not a string) | |
* @return The value of the member | |
*/ | |
#define GET_PRIVATE(InClass, InObj, MemberName) (*InObj).*GetPrivate(InClass##MemberName##Getter()) | |
Partial Example: | |
FStackTracker** MapPtr = DebugStackTrackers.Find(TraceName); | |
FStackTracker* CurTracker = (MapPtr != NULL ? *DebugStackTrackers.Find(TraceName) : NULL); | |
// Enable tracing for this particular stack trace name (adding it to tracking if needed) | |
if (FParse::Command(&Cmd, TEXT("enable"))) | |
{ | |
if (CurTracker == NULL) | |
{ | |
CurTracker = DebugStackTrackers.Add(TraceName, new FStackTracker(NULL, NULL, true)); | |
CurTracker->ResetTracking(); | |
} | |
if (GET_PRIVATE(FStackTracker, CurTracker, bIsEnabled) == false) | |
{ | |
CurTracker->ToggleTracking(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment