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

cyclus / cyclus / 16384544356

19 Jul 2025 03:38AM UTC coverage: 36.53% (-4.7%) from 41.231%
16384544356

push

github

web-flow
Merge pull request #1881 from dean-krueger/clang-format

Clang Format Cyclus src

1517 of 26176 new or added lines in 94 files covered. (5.8%)

309 existing lines in 19 files now uncovered.

51830 of 141883 relevant lines covered (36.53%)

14764.59 hits per line

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

85.88
/src/sqlite_back.cc
1
#include "sqlite_back.h"
2

3
#include <iomanip>
4
#include <sstream>
5
#include <locale>
6

7
#include <boost/lexical_cast.hpp>
8
#include <boost/uuid/uuid_io.hpp>
9
#include <boost/algorithm/string.hpp>
10
#include <boost/archive/tmpdir.hpp>
11
#include <boost/archive/xml_iarchive.hpp>
12
#include <boost/archive/xml_oarchive.hpp>
13
#include <boost/serialization/base_object.hpp>
14
#include <boost/serialization/utility.hpp>
15
#include <boost/serialization/list.hpp>
16
#include <boost/serialization/set.hpp>
17
#include <boost/serialization/vector.hpp>
18
#include <boost/serialization/map.hpp>
19
#include <boost/serialization/assume_abstract.hpp>
20

21
#include "blob.h"
22
#include "datum.h"
23
#include "error.h"
24
#include "logger.h"
25

26
namespace cyclus {
27

28
std::vector<std::string> split(const std::string& s, char delim) {
×
29
  std::vector<std::string> elems;
30
  std::stringstream ss(s);
×
31
  std::string item;
32
  while (std::getline(ss, item, delim)) {
×
33
    elems.push_back(item);
×
34
  }
35
  return elems;
×
36
}
×
37

38
SqliteBack::~SqliteBack() {
290✔
39
  try {
40
    Flush();
188✔
41
    db_.close();
188✔
42
  } catch (Error err) {
×
43
    CLOG(LEV_ERROR) << "Error in SqliteBack destructor: " << err.what();
×
44
  }
×
45
}
290✔
46

47
SqliteBack::SqliteBack(std::string path) : db_(path) {
386✔
48
  path_ = path;
49
  db_.open();
193✔
50

51
  db_.Execute("PRAGMA synchronous=OFF;");
193✔
52
  db_.Execute("PRAGMA journal_mode=MEMORY;");
193✔
53
  db_.Execute("PRAGMA temp_store=MEMORY;");
193✔
54

55
  // cache pre-existing table names
56
  SqlStatement::Ptr stmt;
57
  stmt = db_.Prepare("SELECT name FROM sqlite_master WHERE type='table';");
193✔
58

59
  for (int i = 0; stmt->Step(); ++i) {
193✔
60
    tbl_names_.insert(stmt->GetText(0, NULL));
×
61
  }
62

63
  if (tbl_names_.count("FieldTypes") == 0) {
386✔
64
    std::string cmd = "CREATE TABLE IF NOT EXISTS FieldTypes";
193✔
65
    cmd += "(TableName TEXT,Field TEXT,Type INTEGER);";
66
    db_.Execute(cmd);
386✔
67
  }
68
}
193✔
69

70
void SqliteBack::Notify(DatumList data) {
508✔
71
  db_.Execute("BEGIN TRANSACTION;");
1,016✔
72
  try {
73
    for (DatumList::iterator it = data.begin(); it != data.end(); ++it) {
64,882✔
74
      std::string tbl = (*it)->title();
64,374✔
75
      if (tbl_names_.count(tbl) == 0) {
76
        CreateTable(*it);
3,291✔
77
      }
78
      if (stmts_.count(tbl) == 0) {
79
        BuildStmt(*it);
3,291✔
80
      }
81
      WriteDatum(*it);
64,374✔
82
    }
83
  } catch (ValueError err) {
×
84
    db_.Execute("END TRANSACTION;");
×
85
    throw ValueError(err.what());
×
86
  }
×
87
  db_.Execute("END TRANSACTION;");
508✔
88
  Flush();
508✔
89
}
508✔
90

91
void SqliteBack::Flush() {}
1,204✔
92

93
std::list<ColumnInfo> SqliteBack::Schema(std::string table) {
×
94
  std::list<ColumnInfo> schema;
95
  QueryResult qr = GetTableInfo(table);
×
96
  for (int i = 0; i < qr.fields.size(); ++i) {
×
97
    ColumnInfo info =
NEW
98
        ColumnInfo(table, qr.fields[i], i, qr.types[i], std::vector<int>());
×
99
    schema.push_back(info);
100
  }
×
101
  return schema;
×
102
}
×
103

104
QueryResult SqliteBack::Query(std::string table, std::vector<Cond>* conds) {
6,205✔
105
  QueryResult q = GetTableInfo(table);
6,205✔
106

107
  std::stringstream sql;
5,049✔
108
  sql << "SELECT * FROM " << table;
109
  if (conds != NULL) {
5,049✔
110
    sql << " WHERE ";
4,967✔
111
    for (int i = 0; i < conds->size(); ++i) {
16,014✔
112
      if (i > 0) {
11,047✔
113
        sql << " AND ";
6,080✔
114
      }
115
      Cond c = (*conds)[i];
11,047✔
116
      sql << c.field << " " << c.op << " ?";
11,047✔
117
    }
11,047✔
118
  }
119
  sql << ";";
5,049✔
120

121
  SqlStatement::Ptr stmt = db_.Prepare(sql.str());
5,049✔
122

123
  if (conds != NULL) {
5,049✔
124
    for (int i = 0; i < conds->size(); ++i) {
16,014✔
125
      boost::spirit::hold_any v = (*conds)[i].val;
11,047✔
126
      Bind(v, Type(v), stmt, i + 1);
55,235✔
127
    }
128
  }
129

130
  for (int i = 0; stmt->Step(); ++i) {
12,637✔
131
    QueryRow r;
132
    for (int j = 0; j < q.fields.size(); ++j) {
51,480✔
133
      r.push_back(ColAsVal(stmt, j, q.types[j]));
175,568✔
134
    }
135
    q.rows.push_back(r);
7,588✔
136
  }
7,588✔
137
  return q;
5,049✔
138
}
5,049✔
139

140
std::map<std::string, DbTypes> SqliteBack::ColumnTypes(std::string table) {
1✔
141
  QueryResult qr = GetTableInfo(table);
2✔
142
  std::map<std::string, DbTypes> rtn;
143
  for (int i = 0; i < qr.fields.size(); ++i) rtn[qr.fields[i]] = qr.types[i];
3✔
144
  return rtn;
1✔
145
}
1✔
146

147
std::set<std::string> SqliteBack::Tables() {
105✔
148
  using std::set;
149
  using std::string;
150
  set<string> rtn;
151
  std::string sql = "SELECT name FROM sqlite_master WHERE type='table';";
105✔
152
  SqlStatement::Ptr stmt;
153
  stmt = db_.Prepare(sql);
210✔
154
  while (stmt->Step()) {
2,459✔
155
    rtn.insert(stmt->GetText(0, NULL));
4,708✔
156
  }
157
  rtn.erase("FieldTypes");
210✔
158
  return rtn;
105✔
159
}
160

161
SqliteDb& SqliteBack::db() {
4✔
162
  return db_;
4✔
163
}
164

165
QueryResult SqliteBack::GetTableInfo(std::string table) {
6,206✔
166
  std::string sql =
167
      "SELECT Field,Type FROM FieldTypes WHERE TableName = '" + table + "';";
6,206✔
168
  SqlStatement::Ptr stmt;
169
  stmt = db_.Prepare(sql);
19,774✔
170

171
  int i = 0;
172
  QueryResult info;
173
  for (i = 0; stmt->Step(); ++i) {
35,928✔
174
    info.fields.push_back(stmt->GetText(0, NULL));
29,722✔
175
    info.types.push_back((DbTypes)stmt->GetInt(1));
29,722✔
176
  }
177
  if (i == 0) {
6,206✔
178
    throw ValueError("Invalid table name " + table);
2,312✔
179
  }
180
  return info;
5,050✔
181
}
1,156✔
182

183
std::string SqliteBack::Name() {
×
184
  return path_;
×
185
}
186

187
void SqliteBack::BuildStmt(Datum* d) {
3,291✔
188
  std::string name = d->title();
3,291✔
189
  Datum::Vals vals = d->vals();
3,291✔
190
  std::vector<DbTypes> schema;
191

192
  schema.push_back(Type(vals[0].second));
6,582✔
193
  std::string insert = "INSERT INTO " + name + " VALUES (?";
3,291✔
194
  for (int i = 1; i < vals.size(); ++i) {
15,081✔
195
    schema.push_back(Type(vals[i].second));
23,580✔
196
    insert += ", ?";
197
  }
198
  insert += ");";
199

200
  schemas_[name] = schema;
3,291✔
201
  stmts_[name] = db_.Prepare(insert);
13,164✔
202
}
6,582✔
203

204
void SqliteBack::CreateTable(Datum* d) {
3,291✔
205
  std::string name = d->title();
3,291✔
206
  tbl_names_.insert(name);
207

208
  Datum::Vals vals = d->vals();
3,291✔
209
  Datum::Vals::iterator it = vals.begin();
210

211
  std::stringstream types;
3,291✔
212
  types << "INSERT INTO FieldTypes VALUES ('" << name << "','" << it->first
213
        << "','" << Type(it->second) << "');";
9,873✔
214
  db_.Execute(types.str());
3,291✔
215

216
  std::string cmd = "CREATE TABLE " + name + " (";
6,582✔
217
  cmd += std::string(it->first) + " " + SqlType(it->second);
6,582✔
218
  ++it;
219

220
  while (it != vals.end()) {
15,081✔
221
    cmd += ", " + std::string(it->first) + " " + SqlType(it->second);
35,370✔
222
    std::stringstream types;
11,790✔
223
    types << "INSERT INTO FieldTypes VALUES ('" << name << "','" << it->first
224
          << "','" << Type(it->second) << "');";
35,370✔
225
    db_.Execute(types.str());
23,580✔
226
    ++it;
227
  }
11,790✔
228

229
  cmd += ");";
230
  db_.Execute(cmd);
6,582✔
231
}
6,582✔
232

233
void SqliteBack::WriteDatum(Datum* d) {
64,374✔
234
  Datum::Vals vals = d->vals();
64,374✔
235
  SqlStatement::Ptr stmt = stmts_[d->title()];
64,374✔
236
  std::vector<DbTypes> schema = schemas_[d->title()];
64,374✔
237

238
  for (int i = 0; i < vals.size(); ++i) {
441,319✔
239
    boost::spirit::hold_any v = vals[i].second;
376,945✔
240
    Bind(v, schema[i], stmt, i + 1);
1,884,725✔
241
  }
242

243
  stmt->Exec();
64,374✔
244
}
64,374✔
245

246
void SqliteBack::Bind(boost::spirit::hold_any v, DbTypes type,
387,992✔
247
                      SqlStatement::Ptr stmt, int index) {
248
// serializes the value v of type T and DBType D and binds it to stmt (inside
249
// a case statement.
250
// NOTE: Since we are archiving to a stringstream, the archive must be closed
251
// before the stringstream, so we put it in its own scope. This first became an
252
// issue in Boost v1.66.0.  For more information, see
253
// http://boost.2283326.n4.nabble.com/the-boost-xml-serialization-to-a-stringstream-does-not-have-an-end-tag-tp2580772p2580773.html
254
#define CYCLUS_COMMA ,
255
#define CYCLUS_BINDVAL(D, T)                    \
256
  case D: {                                     \
257
    T vect = v.cast<T>();                       \
258
    std::stringstream ss;                       \
259
    ss.imbue(std::locale(""));                  \
260
    {                                           \
261
      boost::archive::xml_oarchive ar(ss);      \
262
      ar& BOOST_SERIALIZATION_NVP(vect);        \
263
    }                                           \
264
    v = vect;                                   \
265
    std::string s = ss.str();                   \
266
    stmt->BindBlob(index, s.c_str(), s.size()); \
267
    break;                                      \
268
  }
269

270
  switch (type) {
387,992✔
271
    case INT: {
272
      stmt->BindInt(index, v.cast<int>());
222,226✔
273
      break;
222,226✔
274
    }
275
    case BOOL: {
276
      stmt->BindInt(index, v.cast<bool>());
6,675✔
277
      break;
6,675✔
278
    }
279
    case DOUBLE: {
280
      stmt->BindDouble(index, v.cast<double>());
14,371✔
281
      break;
14,371✔
282
    }
283
    case FLOAT: {
NEW
284
      stmt->BindDouble(index, v.cast<float>());
×
NEW
285
      break;
×
286
    }
287
    case BLOB: {
72✔
288
      std::string s = v.cast<Blob>().str();
72✔
289
      stmt->BindBlob(index, s.c_str(), s.size());
72✔
290
      break;
291
    }
292
    case STRING: {
293
      stmt->BindText(index, v.cast<std::string>().c_str());
74,970✔
294
      break;
74,970✔
295
    }
296
    case UUID: {
69,469✔
297
      boost::uuids::uuid ui = v.cast<boost::uuids::uuid>();
69,469✔
298
      stmt->BindBlob(index, ui.data, 16);
69,469✔
299
      break;
300
    }
301
      CYCLUS_BINDVAL(SET_INT, std::set<int>);
5✔
302
      CYCLUS_BINDVAL(SET_STRING, std::set<std::string>);
5✔
303
      CYCLUS_BINDVAL(LIST_INT, std::list<int>);
4✔
NEW
304
      CYCLUS_BINDVAL(LIST_STRING, std::list<std::string>);
×
305
      CYCLUS_BINDVAL(VECTOR_INT, std::vector<int>);
12✔
306
      CYCLUS_BINDVAL(VECTOR_DOUBLE, std::vector<double>);
4✔
307
      CYCLUS_BINDVAL(VECTOR_STRING, std::vector<std::string>);
588✔
308
      CYCLUS_BINDVAL(MAP_INT_DOUBLE, std::map<int CYCLUS_COMMA double>);
205✔
309
      CYCLUS_BINDVAL(MAP_INT_INT, std::map<int CYCLUS_COMMA int>);
5✔
310
      CYCLUS_BINDVAL(MAP_INT_STRING, std::map<int CYCLUS_COMMA std::string>);
5✔
311
      CYCLUS_BINDVAL(MAP_STRING_INT, std::map<std::string CYCLUS_COMMA int>);
5✔
312
      CYCLUS_BINDVAL(MAP_STRING_DOUBLE,
5✔
313
                     std::map<std::string CYCLUS_COMMA double>);
314
      CYCLUS_BINDVAL(MAP_STRING_STRING,
5✔
315
                     std::map<std::string CYCLUS_COMMA std::string>);
316
      CYCLUS_BINDVAL(MAP_STRING_VECTOR_DOUBLE,
5✔
317
                     std::map<std::string CYCLUS_COMMA std::vector<double>>);
318
      CYCLUS_BINDVAL(
5✔
319
          MAP_STRING_MAP_INT_DOUBLE,
320
          std::map<std::string CYCLUS_COMMA std::map<int CYCLUS_COMMA double>>);
321
      CYCLUS_BINDVAL(
5✔
322
          MAP_STRING_PAIR_DOUBLE_MAP_INT_DOUBLE,
323
          std::map<std::string CYCLUS_COMMA std::pair<
324
              double CYCLUS_COMMA std::map<int CYCLUS_COMMA double>>>);
325
      CYCLUS_BINDVAL(
5✔
326
          MAP_INT_MAP_STRING_DOUBLE,
327
          std::map<int CYCLUS_COMMA std::map<std::string CYCLUS_COMMA double>>);
328
      CYCLUS_BINDVAL(
5✔
329
          MAP_STRING_VECTOR_PAIR_INT_PAIR_STRING_STRING,
330
          std::map<std::string CYCLUS_COMMA
331
                       std::vector<std::pair<int CYCLUS_COMMA std::pair<
332
                           std::string CYCLUS_COMMA std::string>>>>);
333

NEW
334
      CYCLUS_BINDVAL(MAP_STRING_PAIR_STRING_VECTOR_DOUBLE,
×
335
                     std::map<std::string CYCLUS_COMMA std::pair<
336
                         std::string CYCLUS_COMMA std::vector<double>>>);
337

338
      CYCLUS_BINDVAL(LIST_PAIR_INT_INT,
4✔
339
                     std::list<std::pair<int CYCLUS_COMMA int>>);
340

341
      CYCLUS_BINDVAL(MAP_STRING_MAP_STRING_INT,
5✔
342
                     std::map<std::string CYCLUS_COMMA
343
                                  std::map<std::string CYCLUS_COMMA int>>);
344

345
      CYCLUS_BINDVAL(
4✔
346
          VECTOR_PAIR_PAIR_DOUBLE_DOUBLE_MAP_STRING_DOUBLE,
347
          std::vector<
348
              std::pair<std::pair<double CYCLUS_COMMA double> CYCLUS_COMMA
349
                            std::map<std::string CYCLUS_COMMA double>>>);
350

351
      CYCLUS_BINDVAL(MAP_PAIR_STRING_STRING_INT,
5✔
352
                     std::map<std::pair<std::string CYCLUS_COMMA std::string>
353
                                  CYCLUS_COMMA int>);
354

NEW
355
      CYCLUS_BINDVAL(MAP_STRING_MAP_STRING_DOUBLE,
×
356
                     std::map<std::string CYCLUS_COMMA
357
                                  std::map<std::string CYCLUS_COMMA double>>);
358

NEW
359
    default: {
×
NEW
360
      throw ValueError("attempted to retrieve unsupported sqlite backend type");
×
361
    }
362
  }
363
#undef CYCLUS_BINDVAL
364
#undef CYCLUS_COMMA
365
}
387,992✔
366

367
boost::spirit::hold_any SqliteBack::ColAsVal(SqlStatement::Ptr stmt,
43,892✔
368
                                             int col,
369
                                             DbTypes type) {
370
  boost::spirit::hold_any v;
371

372
// reconstructs from a serialization in stmt of type T and DbType D and
373
// store it in v.
374
#define CYCLUS_COMMA ,
375
#define CYCLUS_LOADVAL(D, T)               \
376
  case D: {                                \
377
    char* data = stmt->GetText(col, NULL); \
378
    std::stringstream ss;                  \
379
    ss.imbue(std::locale(""));             \
380
    ss << data;                            \
381
    boost::archive::xml_iarchive ar(ss);   \
382
    T vect;                                \
383
    ar& BOOST_SERIALIZATION_NVP(vect);     \
384
    v = vect;                              \
385
    break;                                 \
386
  }
387

388
  switch (type) {
43,892✔
389
    case INT: {
390
      v = stmt->GetInt(col);
21,386✔
391
      break;
392
    }
393
    case BOOL: {
394
      v = static_cast<bool>(stmt->GetInt(col));
1,490✔
395
      break;
396
    }
397
    case DOUBLE: {
398
      v = stmt->GetDouble(col);
3,483✔
399
      break;
400
    }
401
    case FLOAT: {
NEW
402
      v = static_cast<float>(stmt->GetDouble(col));
×
403
      break;
404
    }
405
    case STRING: {
406
      v = std::string(stmt->GetText(col, NULL));
9,686✔
407
      break;
9,686✔
408
    }
409
    case BLOB: {
410
      int n;
411
      char* s = stmt->GetText(col, &n);
2✔
412
      v = Blob(std::string(s, n));
5✔
413
      break;
414
    }
415
    case UUID: {
416
      boost::uuids::uuid u;
417
      memcpy(&u, stmt->GetText(col, NULL), 16);
7,696✔
418
      v = u;
419
      break;
420
    }
421
      CYCLUS_LOADVAL(SET_INT, std::set<int>);
3✔
422
      CYCLUS_LOADVAL(SET_STRING, std::set<std::string>);
3✔
423
      CYCLUS_LOADVAL(LIST_INT, std::list<int>);
3✔
NEW
424
      CYCLUS_LOADVAL(LIST_STRING, std::list<std::string>);
×
425
      CYCLUS_LOADVAL(VECTOR_INT, std::vector<int>);
9✔
426
      CYCLUS_LOADVAL(VECTOR_DOUBLE, std::vector<double>);
3✔
427
      CYCLUS_LOADVAL(VECTOR_STRING, std::vector<std::string>);
381✔
428
      CYCLUS_LOADVAL(MAP_INT_DOUBLE, std::map<int CYCLUS_COMMA double>);
3✔
429
      CYCLUS_LOADVAL(MAP_INT_INT, std::map<int CYCLUS_COMMA int>);
3✔
430
      CYCLUS_LOADVAL(MAP_INT_STRING, std::map<int CYCLUS_COMMA std::string>);
3✔
431
      CYCLUS_LOADVAL(MAP_STRING_DOUBLE,
3✔
432
                     std::map<std::string CYCLUS_COMMA double>);
433
      CYCLUS_LOADVAL(MAP_STRING_INT, std::map<std::string CYCLUS_COMMA int>);
3✔
434
      CYCLUS_LOADVAL(MAP_STRING_STRING,
3✔
435
                     std::map<std::string CYCLUS_COMMA std::string>);
436
      CYCLUS_LOADVAL(MAP_STRING_VECTOR_DOUBLE,
3✔
437
                     std::map<std::string CYCLUS_COMMA std::vector<double>>);
438
      CYCLUS_LOADVAL(
3✔
439
          MAP_STRING_MAP_INT_DOUBLE,
440
          std::map<std::string CYCLUS_COMMA std::map<int CYCLUS_COMMA double>>);
441
      CYCLUS_LOADVAL(
3✔
442
          MAP_STRING_PAIR_DOUBLE_MAP_INT_DOUBLE,
443
          std::map<std::string CYCLUS_COMMA std::pair<
444
              double CYCLUS_COMMA std::map<int CYCLUS_COMMA double>>>);
445
      CYCLUS_LOADVAL(
3✔
446
          MAP_INT_MAP_STRING_DOUBLE,
447
          std::map<int CYCLUS_COMMA std::map<std::string CYCLUS_COMMA double>>);
448
      CYCLUS_LOADVAL(
3✔
449
          MAP_STRING_VECTOR_PAIR_INT_PAIR_STRING_STRING,
450
          std::map<std::string CYCLUS_COMMA
451
                       std::vector<std::pair<int CYCLUS_COMMA std::pair<
452
                           std::string CYCLUS_COMMA std::string>>>>);
453

NEW
454
      CYCLUS_LOADVAL(MAP_STRING_PAIR_STRING_VECTOR_DOUBLE,
×
455
                     std::map<std::string CYCLUS_COMMA std::pair<
456
                         std::string CYCLUS_COMMA std::vector<double>>>);
457

458
      CYCLUS_LOADVAL(LIST_PAIR_INT_INT,
3✔
459
                     std::list<std::pair<int CYCLUS_COMMA int>>);
460

461
      CYCLUS_LOADVAL(MAP_STRING_MAP_STRING_INT,
3✔
462
                     std::map<std::string CYCLUS_COMMA
463
                                  std::map<std::string CYCLUS_COMMA int>>);
464

465
      CYCLUS_LOADVAL(
3✔
466
          VECTOR_PAIR_PAIR_DOUBLE_DOUBLE_MAP_STRING_DOUBLE,
467
          std::vector<
468
              std::pair<std::pair<double CYCLUS_COMMA double> CYCLUS_COMMA
469
                            std::map<std::string CYCLUS_COMMA double>>>);
470

471
      CYCLUS_LOADVAL(MAP_PAIR_STRING_STRING_INT,
3✔
472
                     std::map<std::pair<std::string CYCLUS_COMMA std::string>
473
                                  CYCLUS_COMMA int>);
474

NEW
475
      CYCLUS_LOADVAL(MAP_STRING_MAP_STRING_DOUBLE,
×
476
                     std::map<std::string CYCLUS_COMMA
477
                                  std::map<std::string CYCLUS_COMMA double>>);
478

NEW
479
    default: {
×
NEW
480
      throw ValueError("Attempted to retrieve unsupported backend type");
×
481
    }
482
  }
483

484
#undef CYCLUS_LOADVAL
485
#undef CYCLUS_COMMA
486

487
  return v;
43,892✔
488
}
489

490
std::string SqliteBack::SqlType(boost::spirit::hold_any v) {
15,081✔
491
  switch (Type(v)) {
30,162✔
492
    case INT:  // fallthrough
493
    case BOOL:
494
      return "INTEGER";
6,479✔
495
    case DOUBLE:  // fallthrough
496
    case FLOAT:
497
      return "REAL";
1,098✔
498
    case STRING:
499
      return "TEXT";
3,941✔
500
    case BLOB:  // fallthrough
501
    case UUID:  // fallthrough
502
    default:    // all templated types
503
      return "BLOB";
3,563✔
504
  }
505
}
506

507
struct compare {
508
  bool operator()(const std::type_info* a, const std::type_info* b) const {
509
    return a->before(*b);
618,168✔
510
  }
511
};
512

513
static std::map<const std::type_info*, DbTypes, compare> type_map;
514

515
DbTypes SqliteBack::Type(boost::spirit::hold_any v) {
56,290✔
516
  if (type_map.size() == 0) {
56,290✔
517
    type_map[&typeid(int)] = INT;
1✔
518
    type_map[&typeid(double)] = DOUBLE;
1✔
519
    type_map[&typeid(float)] = FLOAT;
1✔
520
    type_map[&typeid(bool)] = BOOL;
1✔
521
    type_map[&typeid(Blob)] = BLOB;
1✔
522
    type_map[&typeid(boost::uuids::uuid)] = UUID;
1✔
523
    type_map[&typeid(std::string)] = STRING;
1✔
524
    type_map[&typeid(std::set<int>)] = SET_INT;
1✔
525
    type_map[&typeid(std::set<std::string>)] = SET_STRING;
1✔
526
    type_map[&typeid(std::vector<int>)] = VECTOR_INT;
1✔
527
    type_map[&typeid(std::vector<double>)] = VECTOR_DOUBLE;
1✔
528
    type_map[&typeid(std::vector<std::string>)] = VECTOR_STRING;
1✔
529
    type_map[&typeid(std::list<int>)] = LIST_INT;
1✔
530
    type_map[&typeid(std::list<std::string>)] = LIST_STRING;
1✔
531
    type_map[&typeid(std::map<int, int>)] = MAP_INT_INT;
1✔
532
    type_map[&typeid(std::map<int, double>)] = MAP_INT_DOUBLE;
1✔
533
    type_map[&typeid(std::map<int, std::string>)] = MAP_INT_STRING;
1✔
534
    type_map[&typeid(std::map<std::string, int>)] = MAP_STRING_INT;
1✔
535
    type_map[&typeid(std::map<std::string, double>)] = MAP_STRING_DOUBLE;
1✔
536
    type_map[&typeid(std::map<std::string, std::string>)] = MAP_STRING_STRING;
1✔
537
    type_map[&typeid(std::map<std::string, std::vector<double>>)] =
1✔
538
        MAP_STRING_VECTOR_DOUBLE;
539
    type_map[&typeid(std::map<std::string, std::map<int, double>>)] =
1✔
540
        MAP_STRING_MAP_INT_DOUBLE;
541
    type_map[&typeid(
2✔
542
        std::map<std::string, std::pair<double, std::map<int, double>>>)] =
1✔
543
        MAP_STRING_PAIR_DOUBLE_MAP_INT_DOUBLE;
544
    type_map[&typeid(std::map<int, std::map<std::string, double>>)] =
1✔
545
        MAP_INT_MAP_STRING_DOUBLE;
546
    type_map[&typeid(
2✔
547
        std::map<std::string,
548
                 std::vector<
549
                     std::pair<int, std::pair<std::string, std::string>>>>)] =
1✔
550
        MAP_STRING_VECTOR_PAIR_INT_PAIR_STRING_STRING;
551

552
    type_map[&typeid(
2✔
553
        std::map<std::string, std::pair<std::string, std::vector<double>>>)] =
1✔
554
        MAP_STRING_PAIR_STRING_VECTOR_DOUBLE;
555

556
    type_map[&typeid(std::map<std::string, std::map<std::string, int>>)] =
1✔
557
        MAP_STRING_MAP_STRING_INT;
558

559
    type_map[&typeid(std::list<std::pair<int, int>>)] = LIST_PAIR_INT_INT;
1✔
560

561
    type_map[&typeid(std::vector<std::pair<std::pair<double, double>,
2✔
562
                                           std::map<std::string, double>>>)] =
1✔
563
        VECTOR_PAIR_PAIR_DOUBLE_DOUBLE_MAP_STRING_DOUBLE;
564

565
    type_map[&typeid(std::map<std::pair<std::string, std::string>, int>)] =
1✔
566
        MAP_PAIR_STRING_STRING_INT;
567

568
    type_map[&typeid(std::map<std::string, std::map<std::string, double>>)] =
1✔
569
        MAP_STRING_MAP_STRING_DOUBLE;
570
  }
571

572
  const std::type_info* ti = &v.type();
56,290✔
573
  if (type_map.count(ti) == 0) {
574
    throw ValueError(std::string("unsupported backend type ") + ti->name());
×
575
  }
576
  return type_map[ti];
56,290✔
577
}
578

579
}  // namespace cyclus
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