@@ -4,8 +4,8 @@ Lawrence Livermore National Security, LLC;
44See the top-level NOTICE for additional details. All rights reserved.
55SPDX-License-Identifier: BSD-3-Clause
66*/
7+ #include " commodity_conversion_maps.hpp"
78#include " units.hpp"
8-
99#include < algorithm>
1010#include < array>
1111#include < atomic>
@@ -97,6 +97,19 @@ enum commodity : std::uint32_t
9797namespace UNITS_NAMESPACE {
9898namespace commodities {
9999 using commodityMap = std::unordered_map<std::uint32_t , const char *>;
100+ using commodityNameMap = std::unordered_map<std::string, std::uint32_t >;
101+
102+ static commodityNameMap loadDefinedCommodities ()
103+ {
104+ commodityNameMap knownCommodities{};
105+ for (const auto & ccode : defined_commodity_codes) {
106+ if (ccode.first != nullptr ) {
107+ knownCommodities.emplace (ccode.first , ccode.second );
108+ }
109+ }
110+ return knownCommodities;
111+ }
112+ static const commodityNameMap commodity_codes = loadDefinedCommodities();
100113 static const commodityMap commodity_names{
101114 {water, " water" },
102115 // metals
@@ -173,99 +186,6 @@ namespace commodities {
173186 // that might somehow get generated
174187 };
175188
176- using commodityNameMap = std::unordered_map<std::string, std::uint32_t >;
177- static const commodityNameMap commodity_codes{
178- {" _" , 0 }, // null commodity code, would cause some screwy things with
179- // the strings
180- {" __" , 0 }, // null commodity code, would cause some screwy things with
181- // the strings
182- {" ___" , 0 }, // null commodity code, would cause some screwy things with
183- // the strings
184- {" ____" , 0 }, // null commodity code, would cause some screwy things
185- // with the strings
186- {" _____" , 0 }, // null commodity code, would cause some screwy things
187- // with the strings
188- {" water" , water},
189- // metals
190- {" gold" , gold},
191- {" copper" , copper},
192- {" silver" , silver},
193- {" platinum" , platinum},
194- {" palladium" , palladium},
195- {" zinc" , zinc},
196- {" tin" , tin},
197- {" lead" , lead},
198- {" aluminum" , aluminum},
199- {" alluminum_alloy" , alluminum_alloy},
200- {" nickel" , nickel},
201- {" cobalt" , cobalt},
202- {" molybdenum" , molybdenum},
203- {" carbon" , carbon},
204-
205- // energy
206- {" oil" , oil},
207- {" heat_oil" , heat_oil},
208- {" nat_gas" , nat_gas},
209- {" brent_crude" , brent_crude},
210- {" ethanol" , ethanol},
211- {" propane" , propane},
212- // grains
213- {" wheat" , wheat},
214- {" corn" , corn},
215- {" soybeans" , soybeans},
216- {" soybean_meal" , soybean_meal},
217- {" soybean_oil" , soybean_oil},
218- {" oats" , oats},
219- {" rice" , rice},
220- {" durum_wheat" , durum_wheat},
221- {" canola" , canola},
222- {" rough_rice" , rough_rice},
223- {" rapeseed" , rapeseed},
224- {" adzuci" , adzuki},
225- {" adzuki" , adzuki},
226- {" barley" , barley},
227- // meats
228- {" live_cattle" , live_cattle},
229- {" feeder_cattle" , feeder_cattle},
230- {" lean_hogs" , lean_hogs},
231- {" milk" , milk},
232-
233- // soft
234- {" cotton" , cotton},
235- {" orange_juice" , orange_juice},
236- {" sugar" , sugar},
237- {" sugar_11" , sugar_11},
238- {" coffee" , coffee},
239- {" cocoa" , cocoa},
240- {" palm_oil" , palm_oil},
241- {" rubber" , rubber},
242- {" wool" , wool},
243- {" lumber" , lumber},
244-
245- // other common unit blocks
246- {" people" , people},
247- {" cars" , vehicle},
248- {" vehicle" , vehicle},
249- // clinical
250- {" tissue" , tissue},
251- {" cell" , cell},
252- {" cells" , cell},
253- {" embryo" , embryo},
254- {" hahnemann" , Hahnemann},
255- {" korsakov" , Korsakov},
256- {" protein" , protein},
257- {" creatinine" , creatinine},
258- {" prot" , protein},
259- {" creat" , creatinine},
260- // computer
261- {" voxel" , voxel},
262- {" pixel" , pixel},
263- {" vox" , voxel},
264- {" pix" , pixel},
265- {" dot" , pixel},
266- {" error" , errors},
267- {" errors" , errors},
268- };
269189} // namespace commodities
270190
271191namespace hashcodes {
0 commit comments