IODA Bundle
TemplateParameters.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 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 ///
12 /// \file TemplateParameters.cc
13 ///
14 /// @author Piotr Kuchta, Feb 2009
15 
16 #include "odc/TemplateParameters.h"
17 
18 using namespace eckit;
19 using namespace odc::core;
20 
21 namespace odc {
22 
23 TemplateParameters::TemplateParameters()
24 : std::vector<TemplateParameter*>()
25 {}
26 
28 
30 {
31  for (size_t i = 0; i < size(); ++i)
32  delete at(i);
33  clear();
34 }
35 
37 
38 TemplateParameters::TemplateParameters(const std::string& fileNameTemplate, const MetaData& columns)
39 {
40  parse(fileNameTemplate, *this, columns);
41 }
42 
44 {
45  const std::string &t = fileNameTemplate;
46 
47  int start = 0;
48  for (;;)
49  {
50  size_t l = t.find("{", start);
51  if (l == std::string::npos)
52  break;
53  start = l;
54  size_t r = t.find("}", start);
55  if (r == std::string::npos)
56  throw eckit::UserError(std::string("TemplateParameters::parse: missing '}' while parsing '") + fileNameTemplate + "'");
57  start = r;
58 
59  std::string name = t.substr(l + 1, r - l - 1);
60  size_t index = &columns != &nullMD ? columns.columnIndex(name) : -1;
61 
62  params.push_back(new TemplateParameter(l, r, index, name));
63 
64  Log::debug() << "TemplateParameters::parse: new param: " << l << ", " << r << ", " << index << ", " << name << std::endl;
65  }
66  return params;
67 }
68 
69 } // namespace odc
static TemplateParameters & parse(const std::string &fileNameTemplate, TemplateParameters &, const core::MetaData &=nullMD)
static core::MetaData nullMD
Definition: ColumnInfo.h:23
Definition: encode.cc:30