16
16
#include " FuncGen.h"
17
17
18
18
#include < glog/logging.h>
19
- #include < toml++/toml.h>
20
19
21
20
#include < boost/format.hpp>
22
21
#include < map>
@@ -322,27 +321,14 @@ void FuncGen::DefineTopLevelGetSizeSmartPtr(std::string& testCode,
322
321
}
323
322
324
323
bool FuncGen::DeclareGetSizeFuncs (std::string& testCode,
325
- const std::set<ContainerInfo> & containerInfo,
324
+ const ContainerInfoRefSet & containerInfo,
326
325
bool chaseRawPointers) {
327
- for (auto & cInfo : containerInfo) {
326
+ for (const ContainerInfo & cInfo : containerInfo) {
328
327
std::string ctype = cInfo.typeName ;
329
328
ctype = ctype.substr (0 , ctype.find (" <" , 0 ));
330
329
331
- if (!typeToFuncMap.contains (cInfo.ctype )) {
332
- LOG (ERROR) << " attempted to use container `"
333
- << containerTypeEnumToStr (cInfo.ctype )
334
- << " ` for which a declaration was not provided" ;
335
- return false ;
336
- }
337
-
338
- auto & func = typeToDeclMap[cInfo.ctype ];
339
- boost::format fmt;
340
- fmt = boost::format (func) % ctype;
341
- /* if (cInfo.ctype == STRING_TYPE) {
342
- fmt = boost::format(func);
343
- } else {
344
- fmt = boost::format(func) % ctype;
345
- }*/
330
+ auto & decl = cInfo.codegen .decl ;
331
+ boost::format fmt = boost::format (decl) % ctype;
346
332
testCode.append (fmt.str ());
347
333
}
348
334
@@ -359,28 +345,14 @@ bool FuncGen::DeclareGetSizeFuncs(std::string& testCode,
359
345
}
360
346
361
347
bool FuncGen::DefineGetSizeFuncs (std::string& testCode,
362
- const std::set<ContainerInfo> & containerInfo,
348
+ const ContainerInfoRefSet & containerInfo,
363
349
bool chaseRawPointers) {
364
- for (auto & cInfo : containerInfo) {
350
+ for (const ContainerInfo & cInfo : containerInfo) {
365
351
std::string ctype = cInfo.typeName ;
366
352
ctype = ctype.substr (0 , ctype.find (" <" , 0 ));
367
353
368
- if (!typeToFuncMap.contains (cInfo.ctype )) {
369
- LOG (ERROR) << " attempted to use container `"
370
- << containerTypeEnumToStr (cInfo.ctype )
371
- << " ` for which a definition was not provided" ;
372
- return false ;
373
- }
374
- auto & func = typeToFuncMap[cInfo.ctype ];
375
-
376
- boost::format fmt;
377
- fmt = boost::format (func) % ctype;
378
- /* if (cInfo.ctype == STRING_TYPE) {
379
- fmt = boost::format(func);
380
- } else {
381
- fmt = boost::format(func) % ctype;
382
- }*/
383
-
354
+ auto & func = cInfo.codegen .func ;
355
+ boost::format fmt = boost::format (func) % ctype;
384
356
testCode.append (fmt.str ());
385
357
}
386
358
@@ -422,38 +394,3 @@ void FuncGen::DeclareGetContainer(std::string& testCode) {
422
394
)" ;
423
395
testCode.append (func);
424
396
}
425
-
426
- bool FuncGen::RegisterContainer (ContainerTypeEnum ctype, const fs::path& path) {
427
- toml::table container;
428
- try {
429
- container = toml::parse_file (std::string (path));
430
- } catch (const toml::parse_error& ex) {
431
- LOG (ERROR) << " FuncGen::RegisterContainer: " << path << " : "
432
- << ex.description ();
433
- return false ;
434
- }
435
-
436
- toml::table* codegen = container[" codegen" ].as_table ();
437
- if (!codegen) {
438
- LOG (ERROR) << " a container info file requires an `codegen` table" ;
439
- return false ;
440
- }
441
-
442
- if (std::optional<std::string> str =
443
- (*codegen)[" decl" ].value <std::string>()) {
444
- typeToDeclMap.emplace (ctype, std::move (*str));
445
- } else {
446
- LOG (ERROR) << " `codegen.decl` is a required field" ;
447
- return false ;
448
- }
449
-
450
- if (std::optional<std::string> str =
451
- (*codegen)[" func" ].value <std::string>()) {
452
- typeToFuncMap.emplace (ctype, std::move (*str));
453
- } else {
454
- LOG (ERROR) << " `codegen.func` is a required field" ;
455
- return false ;
456
- }
457
-
458
- return true ;
459
- }
0 commit comments