mirror of
https://github.com/OpenCMT/uLib.git
synced 2025-12-06 07:21:31 +01:00
[uLib Geometry]
non working version! + adds ProgrammableAccessor + renaming of some Image structures ...
This commit is contained in:
5
tmp/c_vtable/Object.c
Normal file
5
tmp/c_vtable/Object.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#define OBJECT_C
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
|
||||
138
tmp/c_vtable/Object.h
Normal file
138
tmp/c_vtable/Object.h
Normal file
@@ -0,0 +1,138 @@
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define C_BEGIN_DECLS extern "C" {
|
||||
# define C_END_DECLS }
|
||||
#define BEGIN_NAMESPACE(name) namespace name {
|
||||
#define END_NAMESPACE }
|
||||
#else
|
||||
# define C_BEGIN_DECLS
|
||||
# define C_END_DECLS
|
||||
#define BEGIN_NAMESPACE(name)
|
||||
#define END_NAMESPACE
|
||||
#endif
|
||||
|
||||
#ifndef INLINE
|
||||
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
||||
# define INLINE extern inline
|
||||
# else
|
||||
# define INLINE inline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef OBJECT_H
|
||||
#define OBJECT_H
|
||||
|
||||
|
||||
#ifdef OBJECT_C
|
||||
#undef INLINE
|
||||
#define INLINE
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
BEGIN_NAMESPACE(ltk)
|
||||
|
||||
typedef void *ltkPointer;
|
||||
|
||||
C_BEGIN_DECLS
|
||||
|
||||
|
||||
struct _Object {
|
||||
int element;
|
||||
};
|
||||
#define OBJECT(ob) ((struct _Object *)ob)
|
||||
#define OBJECT_CLASS (ltk_object_get_class())
|
||||
|
||||
|
||||
INLINE void ltk_object_ctr (ltkPointer self) { OBJECT(self)->element = 5552368; }
|
||||
INLINE void ltk_object_dtr (ltkPointer self) { OBJECT(self)->element = 555; }
|
||||
INLINE int ltk_object_get_element(ltkPointer self) { return OBJECT(self)->element; }
|
||||
|
||||
|
||||
struct _ObjectClass {
|
||||
size_t size;
|
||||
void (* ctr)(ltkPointer);
|
||||
void (* dtr)(ltkPointer);
|
||||
int (* get)(ltkPointer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
INLINE const struct _ObjectClass *ltk_object_get_class() {
|
||||
// vtable is defined as ...
|
||||
// static: to be filled up in code segment
|
||||
// const : to make compiler able to inline function pointers
|
||||
static const struct _ObjectClass vtable =
|
||||
{
|
||||
sizeof(struct _Object),
|
||||
ltk_object_ctr,
|
||||
ltk_object_dtr,
|
||||
ltk_object_get_element
|
||||
};
|
||||
return &vtable;
|
||||
}
|
||||
|
||||
INLINE ltkPointer ltk_object_allocator(const struct _ObjectClass *klass)
|
||||
{
|
||||
struct _Object *ob = (struct _Object *)malloc(klass->size);
|
||||
return (ltkPointer)ob;
|
||||
}
|
||||
|
||||
INLINE struct _Object *ltk_object_new()
|
||||
{
|
||||
struct _Object *ob = (struct _Object *)ltk_object_allocator(OBJECT_CLASS);
|
||||
ltk_object_ctr(ob);
|
||||
return ob;
|
||||
}
|
||||
|
||||
|
||||
C_END_DECLS
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
typedef struct _Object *Object;
|
||||
typedef struct _ObjectClass *ObjectClass;
|
||||
|
||||
#else // CPP ------------------------------------------->
|
||||
class Object {
|
||||
typedef struct _Object ObjectData;
|
||||
ObjectData *d;
|
||||
public:
|
||||
Object() : d(new ObjectData()) { ltk_object_ctr(d); }
|
||||
int Get() { ltk_object_get_element(d); }
|
||||
};
|
||||
|
||||
#endif // <------------------------------------------ CPP
|
||||
|
||||
|
||||
// FUNCTIONS SHARED BETWEEN C AND CPP THAT CAN BE INLINED //
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // OBJEC_H
|
||||
15
tmp/c_vtable/Project.ede
Normal file
15
tmp/c_vtable/Project.ede
Normal file
@@ -0,0 +1,15 @@
|
||||
;; Object vtable
|
||||
;; EDE Project Files are auto generated: Do Not Edit
|
||||
(ede-proj-project "vtable"
|
||||
:file "Project.ede"
|
||||
:name "vtable"
|
||||
:targets (list
|
||||
(ede-proj-target-makefile-program "c"
|
||||
:name "c"
|
||||
:path ""
|
||||
:source '("main.c" "Object.c" "Vector.c")
|
||||
:auxsource '("Vector.h")
|
||||
)
|
||||
)
|
||||
:makefile-type 'Makefile.am
|
||||
)
|
||||
3
tmp/c_vtable/Vector.c
Normal file
3
tmp/c_vtable/Vector.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#define VECTOR_C
|
||||
#include "Vector.h"
|
||||
|
||||
89
tmp/c_vtable/Vector.h
Normal file
89
tmp/c_vtable/Vector.h
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
#include "Object.h" // before VECTOR_C inline
|
||||
|
||||
|
||||
#ifdef VECTOR_C
|
||||
#undef INLINE
|
||||
#define INLINE
|
||||
#endif
|
||||
|
||||
BEGIN_NAMESPACE(ltk)
|
||||
|
||||
|
||||
C_BEGIN_DECLS
|
||||
|
||||
|
||||
struct _Vector {
|
||||
struct _Object parent;
|
||||
int data[3];
|
||||
};
|
||||
#define VECTOR(ob) ((struct _Vector *)ob)
|
||||
#define VECTOR_CLASS (ltk_vector_get_class())
|
||||
|
||||
INLINE void ltk_vector_ctr (ltkPointer self)
|
||||
{
|
||||
ltk_object_ctr(self); // ctr parent //
|
||||
OBJECT(self)->element = 5552369;
|
||||
}
|
||||
|
||||
INLINE void ltk_vector_dtr (ltkPointer self)
|
||||
{
|
||||
OBJECT(self)->element = 556;
|
||||
ltk_object_dtr(self); // dtr parent //
|
||||
}
|
||||
|
||||
INLINE int ltk_vector_get_element(ltkPointer self) { return OBJECT(self)->element + 1; }
|
||||
|
||||
|
||||
struct _VectorClass {
|
||||
size_t size;
|
||||
void (* ctr)(ltkPointer);
|
||||
void (* dtr)(ltkPointer);
|
||||
int (* get)(ltkPointer);
|
||||
int *(* get_data)(ltkPointer);
|
||||
};
|
||||
|
||||
|
||||
INLINE const struct _VectorClass *ltk_vector_get_class()
|
||||
{
|
||||
static const struct _VectorClass vtable =
|
||||
{
|
||||
sizeof(struct _Vector),
|
||||
ltk_object_ctr,
|
||||
ltk_object_dtr,
|
||||
ltk_vector_get_element,
|
||||
NULL
|
||||
};
|
||||
return &vtable;
|
||||
}
|
||||
|
||||
INLINE struct _Vector *ltk_vector_new()
|
||||
{
|
||||
struct _ObjectClass *klass = (struct _ObjectClass *)ltk_vector_get_class();
|
||||
struct _Vector *vec = (struct _Vector *)ltk_object_allocator(klass);
|
||||
ltk_vector_ctr(vec);
|
||||
return vec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
C_END_DECLS
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
typedef struct _Vector *Vector;
|
||||
typedef struct _VecotrClass *VectorClass;
|
||||
|
||||
|
||||
#else // CPP ------------------------------------------->
|
||||
class Vector {
|
||||
typedef struct _Vector VectorData;
|
||||
VectorData *d;
|
||||
public:
|
||||
Vector() : d(new VectorData()) { ltk_vector_ctr(d); }
|
||||
int Get() { ltk_vector_get_element(d); }
|
||||
};
|
||||
|
||||
#endif // <------------------------------------------ CPP
|
||||
|
||||
END_NAMESPACE
|
||||
42
tmp/c_vtable/main.c
Normal file
42
tmp/c_vtable/main.c
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
#include "Object.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
using namespace ltk;
|
||||
int main()
|
||||
{
|
||||
Object ob;
|
||||
printf("%d\n",ob.Get());
|
||||
|
||||
Vector vec;
|
||||
printf("%d\n",vec.Get());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
static inline do_main() {
|
||||
Object ob = ltk_object_new();
|
||||
printf("%d\n",OBJECT_CLASS->get(ob));
|
||||
|
||||
|
||||
Vector vec = ltk_vector_new();
|
||||
printf("%d\n",VECTOR_CLASS->get(vec));
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
do_main();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user