IODA Bundle
BufrMnemonicSet.cpp
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 NOAA/NWS/NCEP/EMC
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #include <ostream>
9 #include <vector>
10 
11 #include "eckit/exception/Exceptions.h"
12 
13 #include "BufrMnemonicSet.h"
14 #include "BufrTypes.h"
15 
16 namespace Ingester
17 {
18  BufrMnemonicSet::BufrMnemonicSet(const std::vector<std::string>& mnemonics,
19  const Channels& channels) :
20  mnemonics_(mnemonics),
21  mnemonicsStr_(makeMnemonicsStr(mnemonics)),
22  channels_(channels),
23  maxColumn_(*std::max_element(channels.begin(), channels.end()))
24  {
25  if (std::find_if(channels.begin(), channels.end(), [](const auto x){ return x < 1; }) \
26  != channels.end())
27  {
28  throw eckit::BadParameter("All channel numbers must be >= 1.");
29  }
30  }
31 
32  std::string BufrMnemonicSet::makeMnemonicsStr(std::vector<std::string> mnemonics)
33  {
34  std::ostringstream mnemonicsStrStream;
35  for (auto mnemonicsIt = mnemonics.begin();
36  mnemonicsIt < mnemonics.end();
37  mnemonicsIt++)
38  {
39  mnemonicsStrStream << *mnemonicsIt;
40 
41  if (mnemonicsIt != mnemonics.end() - 1)
42  {
43  mnemonicsStrStream << " ";
44  }
45  }
46 
47  return mnemonicsStrStream.str();
48  }
49 } // namespace Ingester
static std::string makeMnemonicsStr(std::vector< std::string > mnemonics)
Concatinates mnemonics into a space seperated string.
BufrMnemonicSet(const std::vector< std::string > &mnemonics, const Channels &channels={1})
std::set< size_t > Channels
Definition: BufrTypes.h:18
Definition: encode.cc:30