/vhost/mculabs/snippet_db/pclass/pclass.h
1
2 /*
3 file: pclass.h
4 version: 1.00
5 description: Enables use of [pseudo] classes. (type of C++ / OOP)
6 compiler: CCS C
7 written by : Michael Bradley
8
9 Notes:
10 This was based on my 1.01 source of class.h
11 I created as pclass, due to large amount of code already
12 written for class.c, so I didnt want to replace it
13
14 Some Pre-Processor fun :)
15
16
17
18 Usage:
19 You must setup a "class name" for your instance;
20
21 ClassDef gpsBuffer
22 ClassInclude "cls_circbuffer.c"
23 ClassEnd
24
25 ClassDef compassBuffer
26 ClassInclude "cls_circbuffer.c"
27 ClassEnd
28
29 To access a function or variable in the above class;
30
31 c = gpsBuffer_getChr();
32 c = compassBuffer_getChr();
33
34
35 In each included class file, all functions must be prefaced
36 with clsFn(), and all global variables with clsVar()
37
38 example source of cls_circbuffer.c:
39
40 char clsVar(buf[256]);
41 unsigned int8 clsVar(bpIn);
42 unsigned int8 clsVar(bpOut);
43
44 char clsFn(getChr(void))
45 {
46 char b;
47 b = clsVar(buf[clsVar(bpOut)]);
48 clsVar(bpOut++);
49 return b;
50 }
51
52
53 */
54
55
56 #ifndef __PCLASS_HEADER
57 #define __PCLASS_HEADER
58
59
60 #define ClassDef #define __pclass
61 #define ClassEnd #undef __pclass
62 #define ClassInclude #include
63
64
65
66 #define __mDEFCLASS(cls,def) ##cls##_##def
67 #define clsFn(f) __mDEFCLASS(__pclass,f)
68 #define clsVar(v) __mDEFCLASS(__pclass,v)
69
70
71 #endif
72
|