1
0

ReEntry.h 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef NULLSOFT_UTILITY_RENTRYH
  2. #define NULLSOFT_UTILITY_RENTRYH
  3. #include <string>
  4. namespace Nullsoft
  5. {
  6. namespace Utility
  7. {
  8. class ReEntryGuard
  9. {
  10. public:
  11. ReEntryGuard() : entered(false)
  12. {}
  13. bool FunctionCall(std::string funcName = "Unknown")
  14. {
  15. if (entered)
  16. {
  17. char errorMsg[256];
  18. sprintf(errorMsg, "%s branched to %s", firstFunc.c_str(), funcName.c_str());
  19. ::MessageBox(NULL, errorMsg, "Class ReEntry error", MB_OK);
  20. return false;
  21. }
  22. else
  23. {
  24. firstFunc = funcName;
  25. entered = true;
  26. return true;
  27. }
  28. }
  29. void LeaveFunction()
  30. {
  31. entered = false;
  32. firstFunc = "";
  33. }
  34. private:
  35. bool entered;
  36. std::string firstFunc;
  37. };
  38. class ReEntry
  39. {
  40. public:
  41. ReEntry(ReEntryGuard &_entry, std::string funcName = "Unknown") : entry(&_entry)
  42. {
  43. entry->FunctionCall(funcName);
  44. }
  45. ~ReEntry()
  46. {
  47. entry->LeaveFunction();
  48. }
  49. private:
  50. ReEntryGuard *entry;
  51. };
  52. }
  53. }
  54. #endif