bes  Updated for version 3.20.5
ScopeStack.h
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 #ifndef __NCML_MODULE__SCOPE_STACK_H__
31 #define __NCML_MODULE__SCOPE_STACK_H__
32 
33 #include <string>
34 #include <vector>
35 
36 using namespace std;
37 
38 
54 namespace ncml_module
55 {
56  class ScopeStack
57  {
58  public: // Inner classes
63  enum ScopeType { GLOBAL=0, VARIABLE_ATOMIC, VARIABLE_CONSTRUCTOR, ATTRIBUTE_ATOMIC, ATTRIBUTE_CONTAINER, NUM_SCOPE_TYPES};
64 
71  struct Entry
72  {
73  Entry(ScopeType theType, const string& theName);
74  Entry() : type(GLOBAL) , name("") {}
75 
76  string getTypedName() const
77  {
78  return name + toString(type);
79  }
80 
81  static const string& toString(ScopeType theType)
82  {
83  return sTypeStrings[theType];
84  }
85 
86  ScopeType type;
87  string name;
88  static const string sTypeStrings[NUM_SCOPE_TYPES];
89  };
90 
92  public:
93 
94  ScopeStack();
95  virtual ~ScopeStack();
96 
97  void clear();
98  void push(const string& name, ScopeType type) { push(Entry(type, name)); }
99  void pop();
100  const Entry& top() const;
101 
102  ScopeType topType() const { return top().type; }
103  const string& topName() const { return top().name; }
104 
108  bool empty() const;
109 
115  int size() const;
116 
117  string getFullyQualifiedName() const { return getScopeString(); }
118 
123  string getScopeString() const;
124 
132  string getTypedScopeString() const;
133 
138  bool isCurrentScope(ScopeType type) const;
139 
140  private: // Method
141 
142  void push(const Entry& entry);
143 
145  private:
146  vector<Entry> _scope;
147  };
148 }
149 
150 #endif /* __NCML_MODULE__SCOPE_STACK_H__ */
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...