OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
Dimension.cc
Go to the documentation of this file.
1 // This file is part of the "NcML Module" project, a BES module designed
3 // to allow NcML files to be used to be used as a wrapper to add
4 // AIS to existing datasets of any format.
5 //
6 // Copyright (c) 2009 OPeNDAP, Inc.
7 // Author: Michael Johnson <m.johnson@opendap.org>
8 //
9 // For more information, please also see the main website: http://opendap.org/
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26 //
27 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29 #include "Dimension.h"
30 #include "NCMLDebug.h"// the only NCML dep we allow...
31 
32 #include <iostream>
33 #include <sstream>
34 
35 using std::string;
36 using std::ostringstream;
37 using std::vector;
38 using std::ws;
39 
40 namespace agg_util
41 {
43  : name("")
44  , size(0)
45  , isShared(false)
46  , isSizeConstant(false)
47  {
48  }
49 
50  Dimension::Dimension(const string& nameArg, unsigned int sizeArg, bool isSharedArg, bool isSizeConstantArg)
51  : name(nameArg)
52  , size(sizeArg)
53  , isShared(isSharedArg)
54  , isSizeConstant(isSizeConstantArg)
55  {
56  }
57 
59  {
60  }
61 
62  std::string
64  {
65  ostringstream oss;
66  oss << *this;
67  return oss.str();
68  }
69 
70  std::ostream& operator<<(std::ostream& os, const Dimension& dim)
71  {
72  os << dim.name << '\n';
73  os << dim.size << '\n';
74  return os;
75  }
76 
77  std::istream& operator>>(std::istream& is, Dimension& dim)
78  {
79  dim.isShared = false;
80  dim.isSizeConstant = true;
81 
82  getline(is, dim.name);
83  is >> ws >> dim.size >> ws;
84  return is;
85  }
86 
87  bool
88  DimensionTable::findDimension(const std::string& name, Dimension* pOut) const
89  {
90  bool foundIt = false;
91  vector<Dimension>::const_iterator endIt = _dimensions.end();
92  vector<Dimension>::const_iterator it;
93  for (it = _dimensions.begin(); it != endIt; ++it)
94  {
95  if (it->name == name)
96  {
97  if (pOut)
98  {
99  *pOut = *it;
100  }
101  foundIt = true;
102  break;
103  }
104  }
105  return foundIt;
106  }
107 
108  void
110  {
111  if (!findDimension(dim.name))
112  {
113  _dimensions.push_back(dim);
114  }
115  else
116  {
117  BESDEBUG("ncml", "A dimension with name=" << dim.name << " already exists. Not adding." << endl);
118  }
119  }
120 
121  const std::vector<Dimension>&
123  {
124  return _dimensions;
125  }
126 
127 }
std::istream & operator>>(std::istream &is, Dimension &dim)
Definition: Dimension.cc:77
unsigned int size
Definition: Dimension.h:64
std::string name
Definition: Dimension.h:61
bool findDimension(const std::string &name, Dimension *pOut=0) const
Find the dimension with the given name.
Definition: Dimension.cc:88
const std::vector< Dimension > & getDimensions() const
Definition: Dimension.cc:122
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
std::ostream & operator<<(std::ostream &os, const Dimension &dim)
Dump to stream.
Definition: Dimension.cc:70
std::string toString() const
Dump to string and return (using operator<<)
Definition: Dimension.cc:63
Struct for holding information about a dimension of data, minimally a name and a cardinality (size)...
Definition: Dimension.h:50
void addDimensionUnique(const Dimension &dim)
Add the dimension to the table if one with the same name doesn't already exist.
Definition: Dimension.cc:109
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64