OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
ScopeStack.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 
30 #include "ScopeStack.h"
31 #include "BESDebug.h"
32 #include "BESInternalError.h"
33 
34 namespace ncml_module
35 {
36  /* static */
37  /* enum ScopeType { GLOBAL=0, VARIABLE_ATOMIC, VARIABLE_CONSTRUCTOR, ATTRIBUTE_ATOMIC, ATTRIBUTE_CONTAINER, NUM_SCOPE_TYPES}; */
38  // Make sure these match!
39  const string ScopeStack::Entry::sTypeStrings[NUM_SCOPE_TYPES] =
40  {
41  "<GLOBAL>",
42  "<Variable_Atomic>",
43  "<Variable_Constructor>",
44  "<Attribute_Atomic>",
45  "<Attribute_Container>",
46  };
47 
48  ScopeStack::Entry::Entry(ScopeType theType, const string& theName)
49  : type(theType)
50  , name(theName)
51  {
52  if (theType < 0 || theType >= NUM_SCOPE_TYPES)
53  {
54  BESDEBUG("ncml", "ScopeStack::Entry(): Invalid scope type = " << theType << " for scope name=" << theName << endl);
55  throw BESInternalError("Invalid Scope Type!", __FILE__, __LINE__);
56  }
57  }
58 
60 
62  : _scope(0)
63  {
64  }
65 
67  {
68  _scope.clear();
69  _scope.resize(0);
70  }
71 
72  void
74  {
75  _scope.clear();
76  }
77 
78  void
80  {
81  _scope.pop_back();
82  }
83 
84  const ScopeStack::Entry&
86  {
87  return _scope.back();
88  }
89 
90  bool
92  {
93  return _scope.empty();
94  }
95 
96  int
98  {
99  return _scope.size();
100  }
101 
102  string
104  {
105  string scope("");
106  vector<Entry>::const_iterator iter;
107  for(iter = _scope.begin(); iter != _scope.end(); iter++ )
108  {
109  if (iter != _scope.begin())
110  {
111  scope.append("."); // append scoping operator if not first entry
112  }
113  scope.append((*iter).name);
114  }
115  return scope;
116  }
117 
118  string
120  {
121  string scope("");
122  vector<Entry>::const_iterator iter;
123  for(iter = _scope.begin(); iter != _scope.end(); iter++ )
124  {
125  if (iter != _scope.begin())
126  {
127  scope.append("."); // append scoping operator if not first entry
128  }
129  scope.append((*iter).getTypedName());
130  }
131  return scope;
132  }
133 
134  bool
136  {
137  if (_scope.empty() && type == GLOBAL)
138  {
139  return true;
140  }
141  else if (_scope.empty())
142  {
143  return false;
144  }
145  else
146  {
147  return (_scope.back().type == type);
148  }
149  }
150 
152 
153  void
154  ScopeStack::push(const Entry& entry)
155  {
156  if (entry.type == GLOBAL)
157  {
158  BESDEBUG("ncml", "Logic error: can't push a GLOBAL scope type, ignoring." << endl);
159  }
160  else
161  {
162  _scope.push_back(entry);
163  }
164  }
165 }
string getScopeString() const
Return a fully qualifed name for the scope, such as "" for global scope or "MetaData.Info.Name" for an attribute container, etc.
Definition: ScopeStack.cc:103
exception thrown if inernal error encountered
bool isCurrentScope(ScopeType type) const
Is the current scope of the given type? Note that isCurrentScope(GLOBAL) == empty().
Definition: ScopeStack.cc:135
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
ScopeType
The current scope is either global attribute table, within a variable's attribute table...
Definition: ScopeStack.h:63
Entry used in Scope class to maintain where we are within the DDS AttrTable hierarchy.
Definition: ScopeStack.h:71
string getTypedScopeString() const
Similar to getScopeString(), but appends the type of the scope to the name in the form "Name" f...
Definition: ScopeStack.cc:119
static const string sTypeStrings[NUM_SCOPE_TYPES]
Definition: ScopeStack.h:88
const Entry & top() const
Definition: ScopeStack.cc:85
bool empty() const
If there are no entries pushed.
Definition: ScopeStack.cc:91
int size() const
How many things are on the stack.
Definition: ScopeStack.cc:97
void push(const string &name, ScopeType type)
Definition: ScopeStack.h:98
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64