https://github.com/themanyone/classreg
Object-oriented C Class Factory Methods
https://github.com/themanyone/classreg
Last synced: 7 months ago
JSON representation
Object-oriented C Class Factory Methods
- Host: GitHub
- URL: https://github.com/themanyone/classreg
- Owner: themanyone
- Created: 2016-03-12T03:01:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-12T05:01:47.000Z (over 9 years ago)
- Last Synced: 2025-01-29T20:36:34.120Z (8 months ago)
- Language: C
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
Object-oriented C Class Factory Methods
* Class and Method macros
* String array handling, creation, destruction
* String split, forEach
* Factory Methods and reusable class templates
* Data Access Objects (DAO) and class database
* Reusable bootstrapped reference counting
* Automatic registration of destructors
* Model Facades for Proxying in-line functions
* Automatic reference counting and cleanupBuild instructions
Requires Anch to build, but not to run.
Get it from https://github.com/themanyone/anch# make shared
# ./testDocs?
Should probably just look at the code.
Easy example (doesn't look much like C, does it).
Can be mixed with "regular" C code though because it is C
Compiles to C.// testclass
IMPLEMENTS (INFO, SET_INTS)
class (void testclass, ...)
public methods
method INFO:
printf "*************************\n"
printf "* Test class activated. *\n"
printf "*************************\n"
break
method SET_INTS:
param iArray, int**
int *item; forEach iArray, item *item=getrandom 12,24
break
end_class// testclass2 extends testclass
IMPLEMENTS (SET_VAR, GET_VAR)
class (int testclass2, ...)
static int ret
public methods
method INFO:
printf "**************************\n"
printf "* Test class2 activated. *\n"
printf "**************************\n"
break
method SET_VAR:
param var, int
ret = var
break
method GET_VAR:
printf "My value is %i\n",ret
break
default: // extend test class here
param iArray, int**
testclass methods, iArray
printf "Test Class Extended.\n"
end_class
return retint main void
//~ initialize Data Access Objects (DAO) and class database
use_classes
ClInstance _INFO //optionally say what we are doing
testclass INFO //using the INFO methods
testclass2 SET_VAR,15
//~ create a pre-defined array and string
char *array[] = "This is","an","array.",NULL
char test[25] = "This is a string."
int length=5, j=0 //~ counter
//~ create a few dynamnic arrays
new_array char, cArray, length, testclass2(GET_VAR)
new_array int , iArray, length, 1
//~ populate one with random ints
testclass2 SET_INTS, iArray//~ Print each array member as s
char *s; forEach array, s puts s ;endl
//~ split test string into words as char *s
split test, " ", s
//~ insert the pieces into a dynamic array
sprintf cArray[j],"%i \"%s\"",*iArray[j], s ;j++
FREE cArray[j] //~ NULL-terminate the end
//~ print out the final array
forEach cArray, s puts s ;endl
return 0 //no cleanup necessary!