@@ -1365,6 +1365,69 @@ public:
1365
1365
}
1366
1366
}
1367
1367
1368
+ /* *
1369
+ * \brief. Query enum value using given name.
1370
+ *
1371
+ * Here T is an enum class defined by AMREX_ENUM. The return value
1372
+ * indicates if `name` is found. An exception is thrown, if the found
1373
+ * string associated with the name cannot be case-insensitively
1374
+ * converted to an enumerator (i.e., the found string, not `name`, does
1375
+ * not case-insensitively match any names in the definition of T). If
1376
+ * there are multiple matches, the first one is used. Characters in
1377
+ * `ignores` will be ignored as if they don't exist in the value part of
1378
+ * ParamParse entries (e.g., `name = value`).
1379
+ */
1380
+ template <typename T, typename ET = amrex_enum_traits<T>,
1381
+ std::enable_if_t <ET::value,int > = 0 >
1382
+ int query_enum_sloppy (const char * name, T& ref, std::string_view const & ignores,
1383
+ int ival = FIRST) const
1384
+ {
1385
+ std::string s;
1386
+ int exist = this ->query (name, s, ival);
1387
+ if (exist) {
1388
+ try {
1389
+ s.erase (std::remove_if (s.begin (), s.end (),
1390
+ [&] (auto const & c) {
1391
+ return ignores.find (c) != std::string_view::npos; }),
1392
+ s.end ());
1393
+ ref = amrex::getEnumCaseInsensitive<T>(s);
1394
+ } catch (...) {
1395
+ if (amrex::Verbose () > 0 ) {
1396
+ amrex::Print () << " amrex::ParmParse::query_enum_sloppy (input name: "
1397
+ << this ->prefixedName (name) << " ):\n " ;
1398
+ }
1399
+ throw ;
1400
+ }
1401
+ }
1402
+ return exist;
1403
+ }
1404
+
1405
+ /* *
1406
+ * \brief. Get enum value using given name.
1407
+ *
1408
+ * Here T is an enum class defined by AMREX_ENUM. It's a runtime error,
1409
+ * if `name` is not found. An exception is thrown, if the found string
1410
+ * associated with the name cannot be case-insensitively converted to an
1411
+ * enumerator (i.e., the found string, not `name`, does not
1412
+ * case-insensitively match any names in the definition of T). If there
1413
+ * are multiple matches, the first one is used. Characters in `ignores`
1414
+ * will be ignored as if they don't exist in the value part of
1415
+ * ParamParse entries (e.g., `name = value`).
1416
+ */
1417
+ template <typename T, typename ET = amrex_enum_traits<T>,
1418
+ std::enable_if_t <ET::value,int > = 0 >
1419
+ void get_enum_sloppy (const char * name, T& ref, std::string_view const & ignores,
1420
+ int ival = FIRST) const
1421
+ {
1422
+ int exist = this ->query_enum_sloppy (name, ref, ignores, ival);
1423
+ if (!exist) {
1424
+ std::string msg (" get_enum_sloppy(\" " );
1425
+ msg.append (name).append (" \" ," ).append (amrex::getEnumClassName<T>())
1426
+ .append (" &) failed." );
1427
+ amrex::Abort (msg);
1428
+ }
1429
+ }
1430
+
1368
1431
// ! Remove given name from the table.
1369
1432
int remove (const char * name);
1370
1433
0 commit comments