An open API service indexing awesome lists of open source software.

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

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 cleanup

Build instructions

Requires Anch to build, but not to run.
Get it from https://github.com/themanyone/anch

# make shared
# ./test

Docs?

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 ret

int 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!