mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-06-28 12:35:39 +02:00
particles: name private structs and variables consistently
This commit is contained in:
parent
3135f1d36d
commit
5fc29f7bbe
4 changed files with 63 additions and 63 deletions
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct map {
|
||||
struct private {
|
||||
char *tag;
|
||||
struct particle *default_particle;
|
||||
struct particle_map *map;
|
||||
|
@ -14,17 +14,17 @@ struct map {
|
|||
static struct exposable *
|
||||
instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||
{
|
||||
const struct map *map = particle->private;
|
||||
const struct tag *tag = tag_for_name(tags, map->tag);
|
||||
assert(tag != NULL || map->default_particle != NULL);
|
||||
const struct private *p = particle->private;
|
||||
const struct tag *tag = tag_for_name(tags, p->tag);
|
||||
assert(tag != NULL || p->default_particle != NULL);
|
||||
|
||||
if (tag == NULL)
|
||||
return map->default_particle->instantiate(map->default_particle, tags);
|
||||
return p->default_particle->instantiate(p->default_particle, tags);
|
||||
|
||||
|
||||
const char *tag_value = tag->as_string(tag);
|
||||
for (size_t i = 0; i < map->count; i++) {
|
||||
const struct particle_map *e = &map->map[i];
|
||||
for (size_t i = 0; i < p->count; i++) {
|
||||
const struct particle_map *e = &p->map[i];
|
||||
|
||||
if (strcmp(e->tag_value, tag_value) != 0)
|
||||
continue;
|
||||
|
@ -32,27 +32,27 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
|||
return e->particle->instantiate(e->particle, tags);
|
||||
}
|
||||
|
||||
assert(map->default_particle != NULL);
|
||||
return map->default_particle->instantiate(map->default_particle, tags);
|
||||
assert(p->default_particle != NULL);
|
||||
return p->default_particle->instantiate(p->default_particle, tags);
|
||||
}
|
||||
|
||||
static void
|
||||
particle_destroy(struct particle *particle)
|
||||
{
|
||||
struct map *map = particle->private;
|
||||
struct private *p = particle->private;
|
||||
|
||||
if (map->default_particle != NULL)
|
||||
map->default_particle->destroy(map->default_particle);
|
||||
if (p->default_particle != NULL)
|
||||
p->default_particle->destroy(p->default_particle);
|
||||
|
||||
for (size_t i = 0; i < map->count; i++) {
|
||||
struct particle *p = map->map[i].particle;
|
||||
p->destroy(p);
|
||||
free((char *)map->map[i].tag_value);
|
||||
for (size_t i = 0; i < p->count; i++) {
|
||||
struct particle *pp = p->map[i].particle;
|
||||
pp->destroy(pp);
|
||||
free((char *)p->map[i].tag_value);
|
||||
}
|
||||
|
||||
free(map->map);
|
||||
free(map->tag);
|
||||
free(map);
|
||||
free(p->map);
|
||||
free(p->tag);
|
||||
free(p);
|
||||
particle_default_destroy(particle);
|
||||
}
|
||||
|
||||
|
@ -69,17 +69,17 @@ particle_map_new(const char *tag, const struct particle_map *particle_map,
|
|||
particle->destroy = &particle_destroy;
|
||||
particle->instantiate = &instantiate;
|
||||
|
||||
struct map *map = malloc(sizeof(*map));
|
||||
map->tag = strdup(tag);
|
||||
map->default_particle = default_particle;
|
||||
map->count = count;
|
||||
map->map = malloc(count * sizeof(map->map[0]));
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
priv->tag = strdup(tag);
|
||||
priv->default_particle = default_particle;
|
||||
priv->count = count;
|
||||
priv->map = malloc(count * sizeof(priv->map[0]));
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
map->map[i].tag_value = strdup(particle_map[i].tag_value);
|
||||
map->map[i].particle = particle_map[i].particle;
|
||||
priv->map[i].tag_value = strdup(particle_map[i].tag_value);
|
||||
priv->map[i].particle = particle_map[i].particle;
|
||||
}
|
||||
|
||||
particle->private = map;
|
||||
particle->private = priv;
|
||||
return particle;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue