solstice

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

solparser.h (10195B)


      1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016-2018 CNRS
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #ifndef SOLPARSER_H
     18 #define SOLPARSER_H
     19 
     20 #include "solparser_entity.h"
     21 #include "solparser_spectrum.h"
     22 #include <rsys/rsys.h>
     23 #include <stddef.h>
     24 
     25 /* Library symbol management */
     26 #if defined(SPRSR_SHARED_BUILD) /* Build shared library */
     27   #define SPRSR_API extern EXPORT_SYM
     28 #elif defined(SPRSR_STATIC) /* Use/build static library */
     29   #define SPRSR_API extern LOCAL_SYM
     30 #else /* Use shared library */
     31   #define SPRSR_API extern IMPORT_SYM
     32 #endif
     33 
     34 struct mem_allocator;
     35 struct solparser;
     36 
     37 #define SOLPARSER_ID_IS_VALID(Id) ((Id).i != SIZE_MAX)
     38 
     39 struct solparser_entity_iterator {
     40   struct htable_str2sols_iterator it__; /* Internal data */
     41 };
     42 
     43 struct solparser_material_iterator {
     44   /* Internal data */
     45   const struct solparser_material* mtls__;
     46   size_t imtl__;
     47 };
     48 
     49 struct solparser_geometry_iterator {
     50   /* Internal data */
     51   const struct solparser_geometry* geoms__;
     52   size_t igeom__;
     53 };
     54 
     55 /*******************************************************************************
     56  * Solstice parser API.
     57  ******************************************************************************/
     58 SPRSR_API res_T
     59 solparser_create
     60   (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
     61    struct solparser** parser);
     62 
     63 SPRSR_API void
     64 solparser_ref_get
     65   (struct solparser* parser);
     66 
     67 SPRSR_API void
     68 solparser_ref_put
     69   (struct solparser* parser);
     70 
     71 SPRSR_API res_T
     72 solparser_setup
     73   (struct solparser* parser,
     74    const char* stream_name, /* May be NULL */
     75    FILE* stream);
     76 
     77 /* Return RES_BAD_OP if there is no more YAML document to parse */
     78 SPRSR_API res_T
     79 solparser_load
     80   (struct solparser* parser);
     81 
     82 /* Return NULL if no entity is found */
     83 SPRSR_API const struct solparser_anchor*
     84 solparser_find_anchor
     85   (struct solparser* parser,
     86    const char* anchor_name);
     87 
     88 /* Return NULL if no entity is found */
     89 SPRSR_API const struct solparser_entity*
     90 solparser_find_entity
     91   (struct solparser* parser,
     92    const char* entity_name);
     93 
     94 SPRSR_API const struct solparser_anchor*
     95 solparser_get_anchor
     96   (const struct solparser* parser,
     97    const struct solparser_anchor_id anchor);
     98 
     99 SPRSR_API const struct solparser_entity*
    100 solparser_get_entity
    101   (const struct solparser* parser,
    102    const struct solparser_entity_id entity);
    103 
    104 SPRSR_API const struct solparser_image*
    105 solparser_get_image
    106   (const struct solparser* parser,
    107    const struct solparser_image_id image);
    108 
    109 SPRSR_API const struct solparser_geometry*
    110 solparser_get_geometry
    111   (const struct solparser* parser,
    112    const struct solparser_geometry_id geom);
    113 
    114 SPRSR_API const struct solparser_material*
    115 solparser_get_material
    116   (const struct solparser* parser,
    117    const struct solparser_material_id mtl);
    118 
    119 SPRSR_API const struct solparser_material_double_sided*
    120 solparser_get_material_double_sided
    121   (const struct solparser* parser,
    122    const struct solparser_material_double_sided_id mtl2);
    123 
    124 SPRSR_API const struct solparser_material_dielectric*
    125 solparser_get_material_dielectric
    126   (const struct solparser* parser,
    127    const struct solparser_material_dielectric_id dielectric);
    128 
    129 SPRSR_API const struct solparser_material_matte*
    130 solparser_get_material_matte
    131   (const struct solparser* parser,
    132    const struct solparser_material_matte_id matte);
    133 
    134 SPRSR_API const struct solparser_material_mirror*
    135 solparser_get_material_mirror
    136   (const struct solparser* parser,
    137    const struct solparser_material_mirror_id mirror);
    138 
    139 SPRSR_API const struct solparser_material_thin_dielectric*
    140 solparser_get_material_thin_dielectric
    141   (const struct solparser* parser,
    142    const struct solparser_material_thin_dielectric_id thin_dielectric);
    143 
    144 SPRSR_API const struct solparser_medium*
    145 solparser_get_medium
    146   (const struct solparser* parser,
    147    const struct solparser_medium_id medium);
    148 
    149 SPRSR_API const struct solparser_object*
    150 solparser_get_object
    151   (const struct solparser* parser,
    152    const struct solparser_object_id obj);
    153 
    154 SPRSR_API const struct solparser_shape*
    155 solparser_get_shape
    156   (const struct solparser* parser,
    157    const struct solparser_shape_id shape);
    158 
    159 SPRSR_API const struct solparser_shape_cuboid*
    160 solparser_get_shape_cuboid
    161   (const struct solparser* parser,
    162    const struct solparser_shape_cuboid_id cuboid);
    163 
    164 SPRSR_API const struct solparser_shape_cylinder*
    165 solparser_get_shape_cylinder
    166   (const struct solparser* parser,
    167    const struct solparser_shape_cylinder_id cylinder);
    168 
    169 SPRSR_API const struct solparser_shape_imported_geometry*
    170 solparser_get_shape_obj
    171   (const struct solparser* parser,
    172    const struct solparser_shape_imported_geometry_id impgeom);
    173 
    174 SPRSR_API const struct solparser_shape_paraboloid*
    175 solparser_get_shape_parabol
    176   (const struct solparser* parser,
    177    const struct solparser_shape_paraboloid_id paraboloid);
    178 
    179 SPRSR_API const struct solparser_shape_paraboloid*
    180 solparser_get_shape_parabolic_cylinder
    181   (const struct solparser* parser,
    182    const struct solparser_shape_paraboloid_id paraboloid);
    183 
    184 SPRSR_API const struct solparser_shape_hyperboloid*
    185 solparser_get_shape_hyperbol
    186   (const struct solparser* parser,
    187    const struct solparser_shape_hyperboloid_id hyperboloid);
    188 
    189 SPRSR_API const struct solparser_shape_hemisphere*
    190 solparser_get_shape_hemisphere
    191   (const struct solparser* parser,
    192    const struct solparser_shape_hemisphere_id hemisphere);
    193 
    194 SPRSR_API const struct solparser_shape_plane*
    195 solparser_get_shape_plane
    196   (const struct solparser* parser,
    197    const struct solparser_shape_plane_id plane);
    198 
    199 SPRSR_API const struct solparser_shape_sphere*
    200 solparser_get_shape_sphere
    201   (const struct solparser* parser,
    202    const struct solparser_shape_sphere_id sphere);
    203 
    204 SPRSR_API const struct solparser_shape_imported_geometry*
    205 solparser_get_shape_stl
    206   (const struct solparser* parser,
    207    const struct solparser_shape_imported_geometry_id impgeom);
    208 
    209 SPRSR_API const struct solparser_sun*
    210 solparser_get_sun
    211   (const struct solparser* parser);
    212 
    213 SPRSR_API const struct solparser_atmosphere*
    214 solparser_get_atmosphere
    215   (const struct solparser* parser);
    216 
    217 SPRSR_API const struct solparser_x_pivot*
    218 solparser_get_x_pivot
    219   (const struct solparser* parser,
    220    const struct solparser_pivot_id x_pivot);
    221 
    222 SPRSR_API const struct solparser_zx_pivot*
    223 solparser_get_zx_pivot
    224   (const struct solparser* parser,
    225    const struct solparser_pivot_id zx_pivot);
    226 
    227 SPRSR_API const struct solparser_spectrum*
    228 solparser_get_spectrum
    229   (const struct solparser* parser,
    230    const struct solparser_spectrum_id spectrum);
    231 
    232 SPRSR_API int
    233 solparser_has_spectrum
    234   (const struct solparser* parser);
    235 
    236 /*******************************************************************************
    237  * Entity interator
    238  ******************************************************************************/
    239 SPRSR_API void
    240 solparser_entity_iterator_begin
    241   (struct solparser* parser,
    242    struct solparser_entity_iterator* it);
    243 
    244 SPRSR_API void
    245 solparser_entity_iterator_end
    246   (struct solparser* parser,
    247    struct solparser_entity_iterator* it);
    248 
    249 static FINLINE void
    250 solparser_entity_iterator_next(struct solparser_entity_iterator* it)
    251 {
    252   ASSERT(it);
    253   htable_str2sols_iterator_next(&it->it__);
    254 }
    255 
    256 static FINLINE int
    257 solparser_entity_iterator_eq
    258   (const struct solparser_entity_iterator* a,
    259    const struct solparser_entity_iterator* b)
    260 {
    261   ASSERT(a && b);
    262   return htable_str2sols_iterator_eq(&a->it__, &b->it__);
    263 }
    264 
    265 static FINLINE struct solparser_entity_id
    266 solparser_entity_iterator_get(struct solparser_entity_iterator* it)
    267 {
    268   struct solparser_entity_id id;
    269   ASSERT(it);
    270   id.i = *htable_str2sols_iterator_data_get(&it->it__);
    271   return id;
    272 }
    273 
    274 /*******************************************************************************
    275  * Material iterator
    276  ******************************************************************************/
    277 SPRSR_API void
    278 solparser_material_iterator_begin
    279   (struct solparser* parser,
    280    struct solparser_material_iterator* it);
    281 
    282 SPRSR_API void
    283 solparser_material_iterator_end
    284   (struct solparser* parser,
    285    struct solparser_material_iterator* it);
    286 
    287 static FINLINE void
    288 solparser_material_iterator_next(struct solparser_material_iterator* it)
    289 {
    290   ASSERT(it);
    291   ++it->imtl__;
    292 }
    293 
    294 static FINLINE int
    295 solparser_material_iterator_eq
    296   (const struct solparser_material_iterator* a,
    297    const struct solparser_material_iterator* b)
    298 {
    299   ASSERT(a && b);
    300   return a->mtls__ == b->mtls__ && a->imtl__ == b->imtl__;
    301 }
    302 
    303 static FINLINE struct solparser_material_id
    304 solparser_material_iterator_get(struct solparser_material_iterator* it)
    305 {
    306   struct solparser_material_id id;
    307   ASSERT(it);
    308   id.i = it->imtl__;
    309   return id;
    310 }
    311 
    312 /*******************************************************************************
    313  * Geometry iterator
    314  ******************************************************************************/
    315 SPRSR_API void
    316 solparser_geometry_iterator_begin
    317   (struct solparser* parser, struct solparser_geometry_iterator* it);
    318 
    319 SPRSR_API void
    320 solparser_geometry_iterator_end
    321   (struct solparser* parser, struct solparser_geometry_iterator* it);
    322 
    323 static FINLINE void
    324 solparser_geometry_iterator_next(struct solparser_geometry_iterator* it)
    325 {
    326   ASSERT(it);
    327   ++it->igeom__;
    328 }
    329 
    330 static FINLINE int
    331 solparser_geometry_iterator_eq
    332   (const struct solparser_geometry_iterator* a,
    333    const struct solparser_geometry_iterator* b)
    334 {
    335   ASSERT(a && b);
    336   return a->geoms__ == b->geoms__ && a->igeom__ == b->igeom__;
    337 }
    338 
    339 static FINLINE struct solparser_geometry_id
    340 solparser_geometry_iterator_get(struct solparser_geometry_iterator* it)
    341 {
    342   struct solparser_geometry_id id;
    343   ASSERT(it);
    344   id.i = it->igeom__;
    345   return id;
    346 }
    347 
    348 #endif /* SOLPARSER_H */
    349