solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit bbfbebc2af3f906765a2aee5f245b0a394db35be
parent 3eedd7eff4a70c4157e18034746e043ad283ba36
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 17 Nov 2016 15:57:13 +0100

Implement the entity iterator

Diffstat:
Msrc/solstice_entity.h | 14++++++++++++++
Msrc/solstice_parser.c | 29++++++++++++++++++++++++++++-
Msrc/solstice_parser.h | 48++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/src/solstice_entity.h b/src/solstice_entity.h @@ -112,5 +112,19 @@ solstice_entity_copy_and_release return RES_OK; } +static INLINE size_t +solstice_entity_get_children_count(const struct solstice_entity* entity) +{ + ASSERT(entity); + return darray_child_size_get(&entity->children); +} + +static INLINE struct solstice_entity_id +solstice_entity_get_child(const struct solstice_entity* entity, const size_t i) +{ + ASSERT(entity && i < solstice_entity_get_children_count(entity)); + return darray_child_cdata_get(&entity->children)[i]; +} + #endif /* SOLSTICE_ENTITY_H */ diff --git a/src/solstice_parser.c b/src/solstice_parser.c @@ -1947,7 +1947,7 @@ entity_register_name pisolent = htable_str2sols_find(htable, &solent->name); if(pisolent) { - log_err(parser, entity, + log_err(parser, entity, "an entity with the name `%s' is already defined in the current context.\n", str_cget(&solent->name)); return RES_BAD_ARG; @@ -2763,3 +2763,30 @@ error: goto exit; } +const struct solstice_entity* +solstice_parser_get_entity + (const struct solstice_parser* parser, + const struct solstice_entity_id entity) +{ + ASSERT(parser && entity.i < darray_entity_size_get(&parser->entities)); + return darray_entity_cdata_get(&parser->entities) + entity.i; +} + +void +solstice_parser_entity_iterator_begin + (struct solstice_parser* parser, + struct solstice_entity_iterator* it) +{ + ASSERT(parser && it); + htable_str2sols_begin(&parser->str2entities, &it->it__); +} + +void +solstice_parser_entity_iterator_end + (struct solstice_parser* parser, + struct solstice_entity_iterator* it) +{ + ASSERT(parser && it); + htable_str2sols_end(&parser->str2entities, &it->it__); +} + diff --git a/src/solstice_parser.h b/src/solstice_parser.h @@ -16,11 +16,19 @@ #ifndef SOLSTICE_PARSER_H #define SOLSTICE_PARSER_H +#include "solstice_entity.h" #include <rsys/rsys.h> struct mem_allocator; struct solstice_parser; +struct solstice_entity_iterator { + struct htable_str2sols_iterator it__; /* Internal data */ +}; + +/******************************************************************************* + * Solstice parser API. + ******************************************************************************/ extern LOCAL_SYM res_T solstice_parser_create (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */ @@ -45,5 +53,45 @@ extern LOCAL_SYM res_T solstice_parser_load (struct solstice_parser* parser); +extern LOCAL_SYM const struct solstice_entity* +solstice_parser_get_entity + (const struct solstice_parser* parser, + const struct solstice_entity_id entity); + +extern LOCAL_SYM void +solstice_parser_entity_iterator_begin + (struct solstice_parser* parser, + struct solstice_entity_iterator* it); + +extern LOCAL_SYM void +solstice_parser_entity_iterator_end + (struct solstice_parser* parser, + struct solstice_entity_iterator* it); + +static FINLINE void +solstice_entity_iterator_next(struct solstice_entity_iterator* it) +{ + ASSERT(it); + htable_str2sols_iterator_next(&it->it__); +} + +static FINLINE int +solstice_entity_iterator_eq + (struct solstice_entity_iterator* a, + struct solstice_entity_iterator* b) +{ + ASSERT(a && b); + return htable_str2sols_iterator_eq(&a->it__, &b->it__); +} + +static FINLINE struct solstice_entity_id +solstice_entity_iterator_get(struct solstice_entity_iterator* it) +{ + struct solstice_entity_id id; + ASSERT(it); + id.i = *htable_str2sols_iterator_data_get(&it->it__); + return id; +} + #endif /* SOLSTICE_PARSER_H */