https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MapConversionUtils.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
12namespace Moose
13{
21template <typename T, typename C>
22std::map<T, C> createMapFromVectors(const std::vector<T> & keys, const std::vector<C> & values);
23
30template <typename T>
31std::map<T, MooseEnum> createMapFromVectorAndMultiMooseEnum(const std::vector<T> & keys,
32 const MultiMooseEnum & values);
33
34template <typename T, typename C>
35std::map<T, C>
36createMapFromVectors(const std::vector<T> & keys, const std::vector<C> & values)
37{
38 std::map<T, C> map;
39 mooseAssert(keys.size() == values.size(),
40 "Map should be made from keys (" + std::to_string(keys.size()) + ") and values (" +
41 std::to_string(values.size()) + ") of the same size");
42
43 // No values have been specified.
44 if (!values.size())
45 {
46 return map;
47 }
48 std::transform(keys.begin(),
49 keys.end(),
50 values.begin(),
51 std::inserter(map, map.end()),
52 [](const T & a, const C & b) { return std::make_pair(a, b); });
53 return map;
54}
55
56template <typename T>
57std::map<T, MooseEnum>
58createMapFromVectorAndMultiMooseEnum(const std::vector<T> & keys, const MultiMooseEnum & values)
59{
60 std::map<T, MooseEnum> map;
61 mooseAssert(keys.size() == values.size(),
62 "Map should be made from keys and values of the same size");
63 // No values have been specified. We cant form a map of empty MooseEnum
64 if (!values.size())
65 return map;
66 std::transform(keys.begin(),
67 keys.end(),
68 values.begin(),
69 std::inserter(map, map.end()),
70 [values](const T & a, const MooseEnumItem & b)
71 {
72 // Create a MooseEnum from the available values in the MultiMooseEnum and an
73 // actual current active item from that same MultiMooseEnum
74 MooseEnum single_value(values.getRawNames(), b.name());
75 return std::make_pair(a, single_value);
76 });
77 return map;
78}
79}
std::array< Real, 2 > values
Definition MortarUtils.C:52
Class for containing MooseEnum item information.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
std::map< T, MooseEnum > createMapFromVectorAndMultiMooseEnum(const std::vector< T > &keys, const MultiMooseEnum &values)
Create a map from a vector of keys and MultiMooseEnum acting as a vector.
std::map< T, C > createMapFromVectors(const std::vector< T > &keys, const std::vector< C > &values)
Create a map from two vectors.