oop_in_c/Figure.h

54 lines
1.1 KiB
C
Raw Permalink Normal View History

2012-04-30 18:59:30 +04:00
#ifndef __FIGURE_H__
#define __FIGURE_H__
#include "Object.h"
2012-05-02 18:25:52 +04:00
typedef struct Figure
2012-04-30 18:59:30 +04:00
{
2012-05-02 18:25:52 +04:00
struct Figure_vtable
{
/* derived from Object */
const char* (*type) ();
struct Figure* (*clone) (const struct Figure *this);
void (*destroy) (struct Figure *this);
2012-04-30 18:59:30 +04:00
2012-05-02 18:25:52 +04:00
/* Figure virtual methods */
void (*draw) (const struct Figure *this);
double (*area) (const struct Figure *this);
2012-04-30 18:59:30 +04:00
2012-05-02 18:25:52 +04:00
} *vtable;
2012-04-30 18:59:30 +04:00
2012-05-02 18:25:52 +04:00
} Figure;
static inline const char* Figure_type (const Figure *this)
2012-04-30 18:59:30 +04:00
{
2012-05-02 18:25:52 +04:00
return this->vtable->type ();
}
2012-05-03 16:03:48 +04:00
2012-05-02 18:25:52 +04:00
static inline Figure* Figure_clone (const Figure *this)
{
return this->vtable->clone (this);
}
2012-05-03 16:03:48 +04:00
2012-05-02 18:25:52 +04:00
static inline void Figure_destroy (Figure *this)
{
this->vtable->destroy (this);
}
2012-05-03 16:03:48 +04:00
static inline void Figure_draw (const Figure *this)
2012-05-02 18:25:52 +04:00
{
this->vtable->draw (this);
}
2012-05-03 16:03:48 +04:00
static inline double Figure_area (const Figure *this)
2012-05-02 18:25:52 +04:00
{
return this->vtable->area (this);
}
2012-04-30 18:59:30 +04:00
2012-05-02 18:25:52 +04:00
/* considered to be protected */
void Figure_constructor (Figure *this);
void Figure_destructor (Figure *this);
void Figure_copy (Figure *dest, const Figure *src);
2012-04-30 18:59:30 +04:00
#endif // __FIGURE_H__