summaryrefslogtreecommitdiffstats
path: root/Src/nu/ReEntry.h
blob: 87035d296f5c7fe12613284f74a0a8d8f9e12751 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef NULLSOFT_UTILITY_RENTRYH
#define NULLSOFT_UTILITY_RENTRYH

#include <string>


namespace Nullsoft
{
	namespace Utility
	{


		class ReEntryGuard
		{
		public:
			ReEntryGuard() : entered(false)
			{}


			bool FunctionCall(std::string funcName = "Unknown")
			{

				if (entered)
				{
					char errorMsg[256];
					sprintf(errorMsg, "%s branched to %s", firstFunc.c_str(), funcName.c_str());
					::MessageBox(NULL, errorMsg, "Class ReEntry error", MB_OK);
					return false;
				}
				else
				{
					firstFunc = funcName;
					entered = true;
					return true;
				}
	

			}
			void LeaveFunction()
			{
				entered = false;
				firstFunc = "";
			}
		private:
			bool entered;
			std::string firstFunc;

		};
		class ReEntry
		{
		public:
			ReEntry(ReEntryGuard &_entry, std::string funcName = "Unknown") : entry(&_entry)
			{
				entry->FunctionCall(funcName);
			}

			~ReEntry()
			{
				entry->LeaveFunction();
			}

		private:
			ReEntryGuard *entry;

		};
	}
}
#endif