BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_to_enum.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12
13#ifndef BELFEM_FN_TO_ENUM_HPP
14#define BELFEM_FN_TO_ENUM_HPP
15
16#include "typedefs.hpp"
17#include "assert.hpp"
18#include "stringtools.hpp"
19
20namespace belfem
21{
22
23//------------------------------------------------------------------------------
24
25 template < typename T >
26 void
27 to_enum( const string & aString, T & aEnum )
28 {
29 int tNumEntries = ( int ) T::UNDEFINED ;
30
31 aEnum = T::UNDEFINED ;
32
33 string tString = string_to_lower( aString );
34
35 for( int k=0; k<tNumEntries; ++k )
36 {
37 aEnum = ( T ) k ;
38 string tEnum = string_to_lower( to_string( aEnum ) );
39
40 if( tString == tEnum )
41 {
42 return ;
43 }
44 }
45
46 // overwrite enum with false value if no value was detected
47 aEnum = T::UNDEFINED ;
48 }
49
50//------------------------------------------------------------------------------
51}
52#endif //BELFEM_FN_TO_ENUM_HPP
USER GUIDES:
Definition cl_Capacitor.cpp:16
void to_enum(const string &aString, T &aEnum)
Definition fn_to_enum.hpp:27
std::string string_to_lower(const std::string &aString)
convert the string to lower case
Definition stringtools.cpp:267
string to_string(const DomainType aDomainType)
Definition en_DomainType.cpp:21