IODA Bundle
RequestUtils.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2018 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #include <algorithm>
12 #include <iterator>
13 
14 #include "eckit/utils/StringTools.h"
15 #include "eckit/exception/Exceptions.h"
16 #include "eckit/log/Log.h"
17 #include "eckit/types/Types.h"
18 
19 #include "odc/RequestUtils.h"
20 
21 namespace odc {
22 
23 //----------------------------------------------------------------------------------------------------------------------
24 
25 
27 
28  RequestDict r;
29 
30  for (const auto& kv : request) {
31  std::vector<std::string>& values(r[kv.first]);
32  std::transform(kv.second.begin(), kv.second.end(), std::back_inserter(values), eckit::StringTools::unQuote);
33  }
34 
35  return r;
36 }
37 
38 void checkKeywordsHaveValues(const RequestDict& request, const std::vector<std::string>& keywords) {
39 
40  // Convert to lower case for lookup
41 
42  RequestDict lreq;
43  for (const auto& kv : request) {
44  lreq[eckit::StringTools::lower(kv.first)] = kv.second;
45  }
46 
47  for (const std::string& kw : keywords) {
48  if (lreq.find(kw) == lreq.end() || lreq[kw].size() < 1) {
49  throw eckit::UserError("At least one value required for keyword: " + kw, Here());
50  }
51 
52  eckit::Log::info() << ":: - " << kw << " " << lreq[kw] << std::endl;
53  }
54 }
55 
56 //----------------------------------------------------------------------------------------------------------------------
57 
58 } // namespace odc
59 
Definition: ColumnInfo.h:23
RequestDict unquoteRequestValues(const RequestDict &request)
Definition: RequestUtils.cc:26
void checkKeywordsHaveValues(const RequestDict &request, const std::vector< std::string > &keywords)
Definition: RequestUtils.cc:38
std::map< std::string, std::vector< std::string > > RequestDict
Definition: RequestUtils.h:27