| 130 | return params |
| 131 | |
| 132 | def write_headers_and_source(params, out_directory, struct_name, without_castro_class): |
| 133 | |
| 134 | # output |
| 135 | |
| 136 | # find all the namespaces |
| 137 | namespaces = sorted({q.namespace for q in params}) |
| 138 | |
| 139 | for nm in namespaces: |
| 140 | |
| 141 | params_nm = [q for q in params if q.namespace == nm] |
| 142 | # sort by repr since None may be present |
| 143 | ifdefs = sorted({q.ifdef for q in params_nm}, key=repr) |
| 144 | |
| 145 | # write name_params.H |
| 146 | try: |
| 147 | cp = open(f"{out_directory}/{nm}_params.H", "w", encoding="UTF-8") |
| 148 | except OSError: |
| 149 | sys.exit(f"unable to open {nm}_params.H for writing") |
| 150 | |
| 151 | cp.write(CWARNING) |
| 152 | cp.write(f"#ifndef {nm.upper()}_PARAMS_H\n") |
| 153 | cp.write(f"#define {nm.upper()}_PARAMS_H\n") |
| 154 | |
| 155 | cp.write("\n") |
| 156 | cp.write(f"namespace {nm} {{\n") |
| 157 | |
| 158 | for ifdef in ifdefs: |
| 159 | if ifdef is None: |
| 160 | for p in [q for q in params_nm if q.ifdef is None]: |
| 161 | cp.write(p.get_declare_string(with_extern=True)) |
| 162 | else: |
| 163 | cp.write(f"#ifdef {ifdef}\n") |
| 164 | for p in [q for q in params_nm if q.ifdef == ifdef]: |
| 165 | cp.write(p.get_declare_string(with_extern=True)) |
| 166 | cp.write("#endif\n") |
| 167 | cp.write("}\n\n") |
| 168 | cp.write("#endif\n") |
| 169 | cp.close() |
| 170 | |
| 171 | # write name_queries.H |
| 172 | try: |
| 173 | cq = open(f"{out_directory}/{nm}_queries.H", "w", encoding="UTF-8") |
| 174 | except OSError: |
| 175 | sys.exit(f"unable to open {nm}_queries.H for writing") |
| 176 | |
| 177 | cq.write(CWARNING) |
| 178 | |
| 179 | class_name = "Castro" |
| 180 | if without_castro_class: |
| 181 | class_name = None |
| 182 | |
| 183 | for ifdef in ifdefs: |
| 184 | if ifdef is None: |
| 185 | for p in [q for q in params_nm if q.ifdef is None]: |
| 186 | cq.write(p.get_default_string()) |
| 187 | cq.write(p.get_query_string()) |
| 188 | cq.write(p.get_query_struct_string(struct_name=struct_name, class_name=class_name)) |
| 189 | cq.write("\n") |