Just some cosmetics.
This commit is contained in:
parent
f59561fdfb
commit
6ca258f882
6 changed files with 21 additions and 21 deletions
|
|
@ -38,8 +38,8 @@
|
||||||
*/
|
*/
|
||||||
static char *dupstr(const char *text)
|
static char *dupstr(const char *text)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *copy;
|
char *copy;
|
||||||
|
|
||||||
if (!text)
|
if (!text)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ struct AnimalVTable {
|
||||||
* struct as their first member, which makes the upcast free.
|
* struct as their first member, which makes the upcast free.
|
||||||
*/
|
*/
|
||||||
struct Animal {
|
struct Animal {
|
||||||
ooc_object object;
|
ooc_object object;
|
||||||
const AnimalVTable *vtable;
|
const AnimalVTable *vtable;
|
||||||
char *name;
|
char *name;
|
||||||
int age;
|
int age;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Two fields that belong to the class alone, told apart by their leading
|
* Two fields that belong to the class alone, told apart by their leading
|
||||||
|
|
@ -52,8 +52,8 @@ struct Animal {
|
||||||
* nothing outside Animal can read or write it by name at all. Both are set
|
* nothing outside Animal can read or write it by name at all. Both are set
|
||||||
* from the struct definition below, where the members are in view.
|
* from the struct definition below, where the members are in view.
|
||||||
*/
|
*/
|
||||||
int _id;
|
int _id;
|
||||||
int __legs;
|
int __legs;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@
|
||||||
*/
|
*/
|
||||||
static char *dupstr(const char *text)
|
static char *dupstr(const char *text)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *copy;
|
char *copy;
|
||||||
|
|
||||||
if (!text)
|
if (!text)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -157,10 +157,10 @@ static const ooc_field Cat_fields[] = {
|
||||||
* Dog stay distinguishable while both are passed around as Animal.
|
* Dog stay distinguishable while both are passed around as Animal.
|
||||||
*/
|
*/
|
||||||
const ooc_class Cat_class = {
|
const ooc_class Cat_class = {
|
||||||
.size = sizeof(Cat),
|
.size = sizeof(Cat),
|
||||||
.destroy = destroy,
|
.destroy = destroy,
|
||||||
.super = &Animal_class,
|
.super = &Animal_class,
|
||||||
.fields = Cat_fields,
|
.fields = Cat_fields,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -203,8 +203,8 @@ Cat *cat_new(const char *name, int age, const char *colour)
|
||||||
}
|
}
|
||||||
|
|
||||||
cat->animal.vtable = &vt;
|
cat->animal.vtable = &vt;
|
||||||
cat->colour = dupstr(colour);
|
cat->colour = dupstr(colour);
|
||||||
cat->_lives = 9;
|
cat->_lives = 9;
|
||||||
|
|
||||||
if (!cat->colour) {
|
if (!cat->colour) {
|
||||||
ooc_release(cat);
|
ooc_release(cat);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ typedef struct Cat Cat;
|
||||||
*/
|
*/
|
||||||
struct Cat {
|
struct Cat {
|
||||||
Animal animal;
|
Animal animal;
|
||||||
char *colour;
|
char *colour;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private to Cat, and readable by name: one leading underscore stops
|
* Private to Cat, and readable by name: one leading underscore stops
|
||||||
|
|
@ -40,7 +40,7 @@ struct Cat {
|
||||||
* the same way, so the rule is the one in the library rather than something
|
* the same way, so the rule is the one in the library rather than something
|
||||||
* the subclass has to repeat.
|
* the subclass has to repeat.
|
||||||
*/
|
*/
|
||||||
int _lives;
|
int _lives;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@
|
||||||
*/
|
*/
|
||||||
static char *dupstr(const char *text)
|
static char *dupstr(const char *text)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *copy;
|
char *copy;
|
||||||
|
|
||||||
if (!text)
|
if (!text)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -128,7 +128,7 @@ static const AnimalVTable vt = {
|
||||||
*/
|
*/
|
||||||
static const ooc_field Dog_fields[] = {
|
static const ooc_field Dog_fields[] = {
|
||||||
{ "breed", offsetof(Dog, breed), sizeof(((Dog *)0)->breed), 1 },
|
{ "breed", offsetof(Dog, breed), sizeof(((Dog *)0)->breed), 1 },
|
||||||
{ NULL, 0, 0, 0 },
|
{ NULL, 0, 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -181,7 +181,7 @@ Dog *dog_new(const char *name, int age, const char *breed)
|
||||||
}
|
}
|
||||||
|
|
||||||
dog->animal.vtable = &vt;
|
dog->animal.vtable = &vt;
|
||||||
dog->breed = dupstr(breed);
|
dog->breed = dupstr(breed);
|
||||||
|
|
||||||
if (!dog->breed) {
|
if (!dog->breed) {
|
||||||
ooc_release(dog);
|
ooc_release(dog);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ typedef struct Dog Dog;
|
||||||
*/
|
*/
|
||||||
struct Dog {
|
struct Dog {
|
||||||
Animal animal;
|
Animal animal;
|
||||||
char *breed;
|
char *breed;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue