Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
244 chris 1
#ifndef __MODVAL_H__
2
#define __MODVAL_H__
3
 
4
#include <string>
5
 
6
/*
7
 This module allows for dynamic modification of integer and floating-point
8
 constants at run-time.
9
 
10
 Place the M() around values you want to allow to be changed at run-time.
11
 When you want to modify a value, simply change the value in the source
12
 code file and call ReparseModValues() within your program to re-read the
13
 source files, checking for changes in constants.  Your program will need
14
 to contain some trigger such as a key combination to trigger the
15
 ReparseModValues() call.
16
 
17
 Example:
18
        x = x + M(2.1);
19
 
20
 Caveats:
21
        This module determines which files to parse through (during
22
        ReparseModValues()) at run-time, so if a M() macro has not yet been
23
        executed within a particular source file, its value will not be
24
        updated.
25
 
26
 Performance:
27
        There a small setup cost the first time each M() value is accessed
28
        after program startup and reparsing, but after that there is just the
29
        tiny overhead of a function call and a few vector dereferences.
30
 
31
 */
32
 
33
namespace Sexy
34
{
35
 
36
#if defined(SEXY_DISABLE_MODVAL) || defined(RELEASEFINAL)
37
#define M(val)  (val)
38
#define M1(val) (val)
39
#define M2(val) (val)
40
#define M3(val) (val)
41
#define M4(val) (val)
42
#define M5(val) (val)
43
#define M6(val) (val)
44
#define M7(val) (val)
45
#define M8(val) (val)
46
#define M9(val) (val)
47
#else
48
#define MODVAL_STR_COUNTER2(x,y,z) x#y","#z
49
#define MODVAL_STR_COUNTER1(x,y,z) MODVAL_STR_COUNTER2(x,y,z)
50
#define MODVAL_STR_COUNTER(x) MODVAL_STR_COUNTER1(x,__COUNTER__,__LINE__)
51
#define M(val) ModVal(0, MODVAL_STR_COUNTER("SEXY_SEXYMODVAL"__FILE__), (val))
52
#define M1(val) M(val)
53
#define M2(val) M(val)
54
#define M3(val) M(val)
55
#define M4(val) M(val)
56
#define M5(val) M(val)
57
#define M6(val) M(val)
58
#define M7(val) M(val)
59
#define M8(val) M(val)
60
#define M9(val) M(val)
61
#endif
62
 
63
int                             ModVal(int theAreaNum, const char* theFileName, int theInt);
64
double                  ModVal(int theAreaNum, const char* theFileName, double theDouble);
65
float                   ModVal(int theAreaNum, const char* theFileName, float theFloat);
66
const char*             ModVal(int theAreaNum, const char* theFileName, const char *theStr);
67
bool                    ReparseModValues();
68
void                    AddModValEnum(const std::string &theEnumName, int theVal);
69
 
70
}
71
 
72
#endif //__MODVAL_H__