cg.h (2351B)
1 /* Copyright (C) 2022 Université de Pau et des Pays de l'Adour UPPA 2 * Copyright (C) 2022 CNRS 3 * Copyright (C) 2022 Sorbonne Université 4 * Copyright (C) 2022 Université Paul Sabatier 5 * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 #ifndef CG_H 21 #define CG_H 22 23 #include "cg_cyaml.h" 24 25 #include <rsys/rsys.h> 26 27 #define ERR(Expr) if((res = (Expr)) != RES_OK) goto error; else (void)0 28 29 /* 30 * Some constants used in city_generator 31 */ 32 33 #define CLIPPER_PRECISON 2 /* Input footprints are rounded to cm */ 34 35 /* Utility functions */ 36 static INLINE void 37 log_prt_fn(const char* msg, void* ctx) 38 { 39 ASSERT(msg); 40 (void)ctx; 41 42 fprintf(stderr, "\x1b[32moutput:\x1b[0m %s", msg); 43 } 44 45 static INLINE void 46 log_warn_fn(const char* msg, void* ctx) 47 { 48 ASSERT(msg); 49 (void)ctx; 50 51 fprintf(stderr, "\x1b[33mwarning:\x1b[0m %s", msg); 52 } 53 54 static INLINE void 55 log_err_fn(const char* msg, void* ctx) 56 { 57 ASSERT(msg); 58 (void)ctx; 59 60 fprintf(stderr, "\x1b[31merror:\x1b[0m %s", msg); 61 } 62 63 static INLINE void 64 log_prt_fn_ne(const char* msg, void* ctx) 65 { 66 ASSERT(msg); 67 (void)ctx; 68 69 fprintf(stderr, "output: %s", msg); 70 } 71 72 static INLINE void 73 log_warn_fn_ne(const char* msg, void* ctx) 74 { 75 ASSERT(msg); 76 (void)ctx; 77 78 fprintf(stderr, "warning: %s", msg); 79 } 80 81 static INLINE void 82 log_err_fn_ne(const char* msg, void* ctx) 83 { 84 ASSERT(msg); 85 (void)ctx; 86 87 fprintf(stderr, "error: %s", msg); 88 } 89 90 static INLINE res_T 91 cyaml_err_to_res_T(const cyaml_err_t err) 92 { 93 res_T res = RES_OK; 94 95 switch(err) { 96 case CYAML_OK: res = RES_OK; break; 97 case CYAML_ERR_OOM: res = RES_MEM_ERR; break; 98 case CYAML_ERR_FILE_OPEN: res = RES_IO_ERR; break; 99 default: res = RES_UNKNOWN_ERR; break; 100 } 101 return res; 102 } 103 104 #endif /*CG_H*/ 105