• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenLightingProject / ola / 20179851591

12 Dec 2025 09:05PM UTC coverage: 45.048% (-0.7%) from 45.72%
20179851591

Pull #2027

github

web-flow
Bump actions/upload-artifact from 4 to 6

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #2027: Bump actions/upload-artifact from 4 to 6

8554 of 19812 branches covered (43.18%)

22094 of 49046 relevant lines covered (45.05%)

50.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.34
/include/ola/ExportMap.h
1
/*
2
 * This library is free software; you can redistribute it and/or
3
 * modify it under the terms of the GNU Lesser General Public
4
 * License as published by the Free Software Foundation; either
5
 * version 2.1 of the License, or (at your option) any later version.
6
 *
7
 * This library is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10
 * Lesser General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU Lesser General Public
13
 * License along with this library; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
 *
16
 * ExportMap.h
17
 * Interface the ExportMap and ExportedVariables
18
 * Copyright (C) 2005 Simon Newton
19
 */
20

21
/**
22
 * @file ExportMap.h
23
 * @brief Export variables on the http server.
24
 *
25
 * Exported variables can be used to expose the internal state on the /debug
26
 * page of the webserver. This allows real time debugging and monitoring of the
27
 * applications.
28
 */
29

30
#ifndef INCLUDE_OLA_EXPORTMAP_H_
31
#define INCLUDE_OLA_EXPORTMAP_H_
32

33
#include <ola/base/Macro.h>
34
#include <ola/StringUtils.h>
35
#include <stdlib.h>
36

37
#include <functional>
38
#include <map>
39
#include <sstream>
40
#include <string>
41
#include <vector>
42

43
namespace ola {
44

45
/**
46
 * @class BaseVariable <ola/ExportMap.h>
47
 * @brief The base variable class.
48
 *
49
 * All other exported variables derive from this.
50
 */
51
class BaseVariable {
52
 public:
53
  /**
54
   * @brief Create a new BaseVariable.
55
   * @param name the variable name.
56
   */
57
  explicit BaseVariable(const std::string &name): m_name(name) {}
141✔
58

59
  /**
60
   * The Destructor.
61
   */
62
  virtual ~BaseVariable() {}
282✔
63

64
  /**
65
   * @brief Return the name of this variable.
66
   * @returns the variable name.
67
   */
68
  const std::string Name() const { return m_name; }
23✔
69

70
  /**
71
   * @brief Return the value of the variable as a string.
72
   * @returns the value of the variable.
73
   */
74
  virtual const std::string Value() const = 0;
75

76
 private:
77
  std::string m_name;
78
};
79

80
struct VariableLessThan: public std::binary_function<BaseVariable*,
81
                                                     BaseVariable*, bool> {
82
  bool operator()(BaseVariable *x, BaseVariable *y) {
6✔
83
    return x->Name() < y->Name();
6✔
84
  }
85
};
86

87

88
/**
89
 * @class BoolVariable <ola/ExportMap.h>
90
 * @brief A boolean variable.
91
 */
92
class BoolVariable: public BaseVariable {
93
 public:
94
  /**
95
   * @brief Create a new BoolVariable.
96
   * @param name the variable name.
97
   */
98
  explicit BoolVariable(const std::string &name)
17✔
99
      : BaseVariable(name),
17✔
100
        m_value(false) {}
17✔
101
  ~BoolVariable() {}
1✔
102

103
  /**
104
   * @brief Set the value of the variable.
105
   * @param value the new value.
106
   */
107
  void Set(bool value) { m_value = value; }
16✔
108

109
  /**
110
   * @brief Get the value of this variable.
111
   * @return the value of the boolean variable.
112
   */
113
  bool Get() const { return m_value; }
2✔
114

115
  /**
116
   * @brief Get the value of this variable as a string.
117
   * @return the value of the boolean variable.
118
   *
119
   * Booleans are represented by a 1 or 0.
120
   */
121
  const std::string Value() const { return m_value ? "1" : "0"; }
3✔
122

123
 private:
124
  bool m_value;
125
};
126

127

128
/*
129
 * Represents a string variable
130
 */
131
class StringVariable: public BaseVariable {
132
 public:
133
  explicit StringVariable(const std::string &name)
4✔
134
      : BaseVariable(name),
4✔
135
        m_value("") {}
4✔
136
  ~StringVariable() {}
4✔
137

138
  void Set(const std::string &value) { m_value = value; }
3✔
139
  const std::string Get() const { return m_value; }
2✔
140
  const std::string Value() const { return m_value; }
2✔
141

142
 private:
143
  std::string m_value;
144
};
145

146

147
/*
148
 * Represents a integer variable
149
 */
150
class IntegerVariable: public BaseVariable {
151
 public:
152
  explicit IntegerVariable(const std::string &name)
69✔
153
      : BaseVariable(name),
69✔
154
        m_value(0) {}
69✔
155
  ~IntegerVariable() {}
1✔
156

157
  void Set(int value) { m_value = value; }
3✔
158
  void operator++(int) { m_value++; }
57✔
159
  void operator--(int) { m_value--; }
37✔
160
  void Reset() { m_value = 0; }
161
  int Get() const { return m_value; }
75✔
162
  const std::string Value() const {
4✔
163
    std::ostringstream out;
4✔
164
    out << m_value;
4✔
165
    return out.str();
8✔
166
  }
4✔
167

168
 private:
169
  int m_value;
170
};
171

172

173
/*
174
 * Represents a counter which can only be added to.
175
 */
176
class CounterVariable: public BaseVariable {
177
 public:
178
  explicit CounterVariable(const std::string &name)
34✔
179
      : BaseVariable(name),
34✔
180
        m_value(0) {}
34✔
181
  ~CounterVariable() {}
1✔
182

183
  void operator++(int) { m_value++; }
37✔
184
  void operator+=(unsigned int value) { m_value += value; }
35✔
185
  void Reset() { m_value = 0; }
186
  unsigned int Get() const { return m_value; }
4✔
187
  const std::string Value() const {
4✔
188
    std::ostringstream out;
4✔
189
    out << m_value;
4✔
190
    return out.str();
8✔
191
  }
4✔
192

193
 private:
194
  unsigned int m_value;
195
};
196

197

198
/*
199
 * A Map variable holds string -> type mappings
200
 */
201
template<typename Type>
202
class MapVariable: public BaseVariable {
203
 public:
204
  MapVariable(const std::string &name, const std::string &label)
1✔
205
      : BaseVariable(name),
206
        m_label(label) {}
1✔
207
  ~MapVariable() {}
1✔
208

209
  void Remove(const std::string &key);
210
  void Set(const std::string &key, Type value);
211
  Type &operator[](const std::string &key);
212
  const std::string Value() const;
213
  const std::string Label() const { return m_label; }
4✔
214

215
 protected:
216
  std::map<std::string, Type> m_variables;
217

218
 private:
219
  std::string m_label;
220
};
221

222
typedef MapVariable<std::string> StringMap;
223

224

225
/**
226
 * An map of integer values. This provides an increment operation.
227
 */
228
class IntMap: public MapVariable<int> {
1✔
229
 public:
230
  IntMap(const std::string &name, const std::string &label)
1✔
231
      : MapVariable<int>(name, label) {}
1✔
232

233
  void Increment(const std::string &key) {
1✔
234
    m_variables[key]++;
1✔
235
  }
1✔
236
};
237

238

239
/**
240
 * An IntMap. This provides an increment operation.
241
 */
242
class UIntMap: public MapVariable<unsigned int> {
243
 public:
244
  UIntMap(const std::string &name, const std::string &label)
12✔
245
      : MapVariable<unsigned int>(name, label) {}
12✔
246

247
  void Increment(const std::string &key) {
248
    m_variables[key]++;
249
  }
250
};
251

252

253
/*
254
 * Return a value from the Map Variable, this will create an entry in the map
255
 * if the variable doesn't exist.
256
 */
257
template<typename Type>
258
Type &MapVariable<Type>::operator[](const std::string &key) {
28✔
259
  return m_variables[key];
28✔
260
}
261

262

263
/*
264
 * Set a value in the Map variable.
265
 */
266
template<typename Type>
267
void MapVariable<Type>::Set(const std::string &key, Type value) {
268
  m_variables[key] = value;
269
}
270

271

272
/**
273
 * Remove a value from the map
274
 * @param key the key to remove
275
 */
276
template<typename Type>
277
void MapVariable<Type>::Remove(const std::string &key) {
×
278
  typename std::map<std::string, Type>::iterator iter = m_variables.find(key);
×
279

280
  if (iter != m_variables.end())
×
281
    m_variables.erase(iter);
×
282
}
×
283

284
/*
285
 * Return the string representation of this map variable.
286
 * The form is:
287
 *   var_name  map:label_name key1:value1 key2:value2
288
 * @return the string representation of the variable.
289
 */
290
template<typename Type>
291
inline const std::string MapVariable<Type>::Value() const {
×
292
  std::ostringstream value;
×
293
  value << "map:" << m_label;
×
294
  typename std::map<std::string, Type>::const_iterator iter;
×
295
  for (iter = m_variables.begin(); iter != m_variables.end(); ++iter)
×
296
    value << " " << iter->first << ":" << iter->second;
×
297
  return value.str();
×
298
}
×
299

300

301
/*
302
 * Strings need to be quoted
303
 */
304
template<>
305
inline const std::string MapVariable<std::string>::Value() const {
5✔
306
  std::ostringstream value;
5✔
307
  value << "map:" << m_label;
5✔
308
  std::map<std::string, std::string>::const_iterator iter;
5✔
309
  for (iter = m_variables.begin(); iter != m_variables.end(); ++iter) {
10✔
310
    std::string var = iter->second;
5✔
311
    Escape(&var);
5✔
312
    value << " " << iter->first << ":\"" << var << "\"";
5✔
313
  }
5✔
314
  return value.str();
10✔
315
}
5✔
316

317

318

319

320
/**
321
 * @brief A container for the exported variables.
322
 *
323
 */
324
class ExportMap {
325
 public:
326
  ExportMap() {}
26✔
327
  ~ExportMap();
328

329
  /**
330
   * @brief Lookup or create a BoolVariable.
331
   * @param name the name of this variable.
332
   * @return a pointer to the BoolVariable.
333
   *
334
   * The variable is created if it doesn't already exist. The pointer is
335
   * valid for the lifetime of the ExportMap.
336
   */
337
  BoolVariable *GetBoolVar(const std::string &name);
338

339
  /**
340
   * @brief Lookup or create an IntegerVariable.
341
   * @param name the name of this variable.
342
   * @return an IntegerVariable.
343
   *
344
   * The variable is created if it doesn't already exist. The pointer is
345
   * valid for the lifetime of the ExportMap.
346
   */
347
  IntegerVariable *GetIntegerVar(const std::string &name);
348

349
  /**
350
   * @brief Lookup or create a CounterVariable.
351
   * @param name the name of this variable.
352
   * @return a CounterVariable.
353
   *
354
   * The variable is created if it doesn't already exist. The pointer is
355
   * valid for the lifetime of the ExportMap.
356
   */
357
  CounterVariable *GetCounterVar(const std::string &name);
358

359
  /**
360
   * @brief Lookup or create a StringVariable.
361
   * @param name the name of this variable.
362
   * @return a StringVariable.
363
   *
364
   * The variable is created if it doesn't already exist. The pointer is
365
   * valid for the lifetime of the ExportMap.
366
   */
367
  StringVariable *GetStringVar(const std::string &name);
368

369
  StringMap *GetStringMapVar(const std::string &name,
370
                             const std::string &label = "");
371
  IntMap *GetIntMapVar(const std::string &name, const std::string &label = "");
372
  UIntMap *GetUIntMapVar(const std::string &name,
373
                         const std::string &label = "");
374

375
  /**
376
   * @brief Fetch a list of all known variables.
377
   * @returns a vector of all variables.
378
   */
379
  std::vector<BaseVariable*> AllVariables() const;
380

381
 private :
382
  template<typename Type>
383
  Type *GetVar(std::map<std::string, Type*> *var_map,
384
               const std::string &name);
385

386
  template<typename Type>
387
  Type *GetMapVar(std::map<std::string, Type*> *var_map,
388
                  const std::string &name,
389
                  const std::string &label);
390

391
  std::map<std::string, BoolVariable*> m_bool_variables;
392
  std::map<std::string, CounterVariable*> m_counter_variables;
393
  std::map<std::string, IntegerVariable*> m_int_variables;
394
  std::map<std::string, StringVariable*> m_string_variables;
395

396
  std::map<std::string, StringMap*> m_str_map_variables;
397
  std::map<std::string, IntMap*> m_int_map_variables;
398
  std::map<std::string, UIntMap*> m_uint_map_variables;
399

400
  DISALLOW_COPY_AND_ASSIGN(ExportMap);
401
};
402
}  // namespace ola
403
#endif  // INCLUDE_OLA_EXPORTMAP_H_
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc