https://mooseframework.inl.gov
Loading...
Searching...
No Matches
THMEnums.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include <algorithm>
13#include "MooseEnum.h"
14
15namespace THM
16{
17
27template <typename T>
28T stringToEnum(const std::string & s);
29
37template <typename T>
38T stringToEnum(const std::string & s, const std::map<std::string, T> & enum_map);
39
47template <typename T>
48MooseEnum getMooseEnum(const std::string & default_key, const std::map<std::string, T> & enum_map);
49}
50
51template <typename T>
52T
53THM::stringToEnum(const std::string & s, const std::map<std::string, T> & enum_map)
54{
55 std::string upper(s);
56 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
57
58 if (!enum_map.count(upper))
59 return static_cast<T>(-100);
60 else
61 return enum_map.at(upper);
62}
63
64template <typename T>
66THM::getMooseEnum(const std::string & default_key, const std::map<std::string, T> & enum_map)
67{
68 std::string keys_string;
69 for (typename std::map<std::string, T>::const_iterator it = enum_map.begin();
70 it != enum_map.end();
71 it++)
72 if (it == enum_map.begin())
73 keys_string += it->first;
74 else
75 keys_string += " " + it->first;
76
77 return MooseEnum(keys_string, default_key, true);
78}
const double T
MooseEnum getMooseEnum(const std::string &default_key, const std::map< std::string, T > &enum_map)
Gets MooseEnum corresponding to an enum, using a map of string to enum.
Definition THMEnums.h:66
Component1DConnection::EEndType stringToEnum(const std::string &s)