Skip to content

Entity.hpp

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#pragma once

#include "doxide.hpp"

#include <filesystem>

/**
 * Entity types.
 * 
 * @ingroup developer
 */
enum class EntityType {
  ROOT,
  NAMESPACE,
  TEMPLATE,
  GROUP,
  TYPE,
  CONCEPT,
  VARIABLE,
  FUNCTION,
  OPERATOR,
  ENUMERATOR,
  MACRO,
  DIR,
  FILE
};

/**
 * Entity in a C++ source file, e.g. variable, function, class, etc.
 * 
 * @ingroup developer
 */
struct Entity {
  /**
   * Child entities are stored in a list, rather than map by name, to preserve
   * declaration order. They may be sorted by name on output.
   */
  using list_type = std::list<Entity>;

  /**
   * Constructor.
  */
  Entity();

  /**
   * Add child entity.
   * 
   * @param o Child entity.
   * 
   * If the child has `ingroup` set, then will search for and add to that
   * group instead.
   */
  void add(Entity&& o);

  /**
   * Merge the children of another entity into this one.
   * 
   * @param o Other entity.
   */
  void merge(Entity&& o);

  /**
   * Does a file exist of the given name?
   * 
   * @param path File path.
   */
  bool exists(std::filesystem::path& path) const;

  /**
   * Get a file of the given name. The file must exist (use `exists()`).
   *
   * @param path File path.
   *
   * @return List of entities giving the full path to the file. The last
   * entity represents the file itself, the preceding entities its
   * subdirectories.
   */
  std::list<Entity*> get(std::filesystem::path& path);

  /**
   * Clear the entity.
   */
  void clear();

  /**
   * Child namespaces.
   */
  list_type namespaces;

  /**
   * Child groups.
   */
  list_type groups;

  /**
   * Child types.
   */
  list_type types;

  /**
   * Child concepts.
   */
  list_type concepts;

  /**
   * Child variables.
   */
  list_type variables;

  /**
   * Child functions.
   */
  list_type functions;

  /**
   * Child operators.
   */
  list_type operators;

  /**
   * Child enumerators.
   */
  list_type enums;

  /**
   * Child macros.
   */
  list_type macros;

  /**
   * Child directories.
   */
  list_type dirs;

  /**
   * Child files.
   */
  list_type files;

  /**
   * Entity name (e.g. name of variable, function, class). For a file or
   * directory this is the full path.
   */
  std::string name;

  /**
   * Entity declaration (e.g. function signature). For a file this is its full
   * contents.
   */
  std::string decl;

  /**
   * Entity documentation.
   */
  std::string docs;

  /**
   * Entity title. This is used for the title of the page.
   */
  std::string title;

  /**
   * Alternative brief description.
   */
  std::string brief;

  /**
   * Group to which this belongs.
   */
  std::string ingroup;

  /**
   * Path of source file.
   */
  std::filesystem::path path;

  /**
   * Starting line in the source file.
   */
  uint32_t start_line;

  /**
   * Ending line in the source file.
   */
  uint32_t end_line;

  /**
   * For a file only, execution counts for lines. -1 for a line indicates that
   * it is excluded.
   */
  std::vector<int> line_counts;

  /**
   * Number of lines included in coverage counts.
   */
  int lines_included;

  /**
   * Number of lines covered in coverage counts.
   */
  int lines_covered;

  /**
   * Entity type.
   */
  EntityType type;

  /**
   * Is this node visible? This is a computed quantity, that may be overridden
   * explicitly with @p hide.
   */
  bool visible;

  /**
   * Hide this node?
   */
  bool hide;

private:
  /**
   * Add child entity to a group.
   * 
   * @param o Child entity with `ingroup` set.
   * 
   * @return True if a group of the given name was found, in which case @p o
   * will have been added to it, false otherwise.
   */
  bool addToGroup(Entity&& o);

  /**
   * Add child entity.
   * 
   * @param o Child entity.
   * 
   * If the child has `ingroup` set, it is ignored.
   */
  void addToThis(Entity&& o);
};