LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
preset_env_accessor.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_UTILS_STUBS_PRESET_ENV_ACCESSOR_HPP_INCLUDED
28 #define LBANN_UTILS_STUBS_PRESET_ENV_ACCESSOR_HPP_INCLUDED
29 
30 #include <string>
31 #include <unordered_map>
32 
33 namespace lbann {
34 namespace utils {
35 namespace stubs {
36 
38 {
39 public:
40  std::string get(std::string const&) const;
41 
42 private:
43  static void populate_vars();
44 
45 private:
46  static std::unordered_map<std::string, std::string> vars_;
47 };
48 
49 inline std::string PresetEnvAccessor::get(std::string const& var_name) const
50 {
51  if (vars_.size() == 0UL)
52  populate_vars();
53 
54  auto it = vars_.find(var_name);
55  if (it == vars_.end())
56  return "";
57 
58  return it->second;
59 }
60 
62 {
63  vars_ = {
64  {"APPLE", "3.14"}, // float
65  {"ICE_CREAM_SCOOPS", "3"}, // int
66  {"PIZZA", "pepperoni"}, // string
67  {"VALUE_IS_TRUE", "true"}, // true as string
68  {"VALUE_IS_ONE", "1"}, // true as int
69  {"VALUE_IS_FALSE", "false"}, // false as string
70  {"VALUE_IS_ZERO", "0"}, // false as int
71  };
72 }
73 
74 } // namespace stubs
75 } // namespace utils
76 } // namespace lbann
77 
78 #endif /* LBANN_UTILS_STUBS_PRESET_ENV_ACCESSOR_HPP_INCLUDED */
std::string get(std::string const &) const
static std::unordered_map< std::string, std::string > vars_