Freeciv21
Develop your civilization from humble roots to a global empire
section_file.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 /* This header contains internals of section_file that its users should
14  * not care about. This header should be included by source files
15  * implementing registry itself. */
16 
17 // utility
18 #include "registry_ini.h"
19 #include "support.h"
20 
21 #include <QString>
22 
23 #include <stddef.h>
24 
25 template <class Key, class T> class QMultiHash;
26 
27 // Section structure.
28 struct section {
29  struct section_file *secfile; // Parent structure.
31  char *name; // Name of the section.
32  struct entry_list *entries; // The list of the children.
33 };
34 
35 // The section file struct itself.
36 struct section_file {
37  char *name; // Can be nullptr.
38  size_t num_entries;
39  /* num_includes should be size_t, but as there's no truly portable
40  * printf format for size_t and we need to construct string containing
41  * num_includes with fc_snprintf(), we set for unsigned int. */
42  unsigned int num_includes;
43  unsigned int num_long_comments;
44  struct section_list *sections;
47  struct {
50  } hash;
51 };
52 
53 void secfile_log(const struct section_file *secfile,
54  const struct section *psection, const char *file,
55  const char *function, int line, const char *format, ...)
56  fc__attribute((__format__(__printf__, 6, 7)));
57 
58 #define SECFILE_LOG(secfile, psection, format, ...) \
59  secfile_log(secfile, psection, __FILE__, __FUNCTION__, __LINE__, format, \
60  ##__VA_ARGS__)
61 #define SECFILE_RETURN_IF_FAIL(secfile, psection, condition) \
62  if (!(condition)) { \
63  SECFILE_LOG(secfile, psection, "Assertion '%s' failed.", #condition); \
64  return; \
65  }
66 #define SECFILE_RETURN_VAL_IF_FAIL(secfile, psection, condition, value) \
67  if (!(condition)) { \
68  SECFILE_LOG(secfile, psection, "Assertion '%s' failed.", #condition); \
69  return value; \
70  }
71 
72 bool entry_from_token(struct section *psection, const QString &name,
73  const QString &tok);
const char * name
Definition: inputfile.cpp:118
entry_special_type
Definition: registry_ini.h:71
bool entry_from_token(struct section *psection, const QString &name, const QString &tok)
Add entry to section from token.
void secfile_log(const struct section_file *secfile, const struct section *psection, const char *file, const char *function, int line, const char *format,...) fc__attribute((__format__(__printf__
struct section_file::@7 hash
QMultiHash< QString, struct entry * > * entries
Definition: section_file.h:49
struct section_list * sections
Definition: section_file.h:44
bool allow_digital_boolean
Definition: section_file.h:46
bool allow_duplicates
Definition: section_file.h:45
unsigned int num_includes
Definition: section_file.h:42
unsigned int num_long_comments
Definition: section_file.h:43
size_t num_entries
Definition: section_file.h:38
QMultiHash< QString, struct section * > * sections
Definition: section_file.h:48
struct entry_list * entries
Definition: section_file.h:32
char * name
Definition: section_file.h:31
enum entry_special_type special
Definition: section_file.h:30
struct section_file * secfile
Definition: section_file.h:29
int fc__attribute((nonnull(1, 3)))