bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
name_map.cc
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of asciival, software which can return an ASCII
5// representation of the data read from a DAP server.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26// (c) COPYRIGHT URI/MIT 1996,2000
27// Please read the full copyright statement in the file COPYRIGHT_URI.
28//
29// Authors:
30// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31
32#ifdef __GNUG__
33//#pragma implementation
34#endif
35
36#include "config.h"
37
38static char rcsid[] not_used = {"$Id$"};
39
40#include "BESRegex.h"
41
42#include <libdap/escaping.h>
43
44#include "name_map.h"
45
46name_map::name_map(char *raw_equiv)
47{
48 _names.push_back(name_equiv(raw_equiv));
49}
50
54
55void
56name_map::add(char *raw_equiv)
57{
58 name_equiv equiv(raw_equiv);
59 _names.push_back(equiv);
60}
61
62static string
63munge(string name)
64{
65 return esc2underscore(name);
66}
67
68string
69name_map::lookup(string name, const bool canonical_names)
70{
71 // NEItor is the name_eqiv interator. 7/23/99 jhrg
72 // Could use find_if here. 9/12/2001 jhrg
73 for (NEItor p = _names.begin(); p != _names.end(); ++p)
74 if (name == p->from) {
75 if (!canonical_names) {
76 return p->to;
77 }
78 else {
79 static BESRegex ident("[A-Za-z_][A-Za-z0-9_]*", 1);
80 string tmp_n = p->to;
81 if (ident.match(tmp_n.c_str(), tmp_n.size()))
82 return munge(tmp_n);
83 else
84 return tmp_n;
85 }
86 }
87
88 if (!canonical_names)
89 return name;
90 else
91 return munge(name);
92}
93
94void
96{
97 _names.erase(_names.begin(), _names.end());
98}
99
100// $Log: name_map.cc,v $
101// Revision 1.10 2004/07/08 22:18:25 jimg
102// Merged with release-3-4-3FCS
103//
104// Revision 1.9.4.2 2004/07/05 03:12:10 rmorris
105// Use "using std::*" in the standard way.
106//
107// Revision 1.9.4.1 2003/07/11 04:28:18 jimg
108// Boldly (ahem) removed the GNUG interface/implementation //#pragma.
109// compared object sizes; there's a little difference, but it looks like a
110// draw as to which is bigger.
111//
112// Revision 1.9 2003/01/27 19:38:23 jimg
113// Updated the copyright information.
114// Merged with release-3-2-6.
115//
116// Revision 1.7.4.2 2002/12/18 23:41:25 pwest
117// gcc3.2 compile corrections, mainly regarding using statements
118//
119// Revision 1.8 2001/09/28 23:46:06 jimg
120// merged with 3.2.3.
121//
122// Revision 1.7.4.1 2001/09/18 23:29:26 jimg
123// Massive changes to use the new AsciiOutput class. Output more or less
124// conforms to the DAP Spec. draft.
125//
126// Revision 1.7 2000/10/02 20:09:52 jimg
127// Moved Log entries to the end of the files
128//
129// Revision 1.6 1999/07/24 00:10:07 jimg
130// Repaired the munge function and removed SLList.
131//
132// Revision 1.5 1999/03/24 06:23:43 brent
133// convert String.h to std lib <string>, convert to packages regex -- B^2
134//
135// Revision 1.4 1997/02/06 20:44:51 jimg
136// Fixed log messages
137//
138// Revision 1.3 1997/01/10 06:50:30 jimg
139// Added to lookup mfunc the ability to map non-alphanmerics to underscore.
140//
141// Revision 1.2 1996/11/23 05:17:39 jimg
142// Added name_map() because g++ wants it.
143//
144// Revision 1.1 1996/11/22 23:52:01 jimg
145// Created.
Regular expression matching.
Definition BESRegex.h:89
int match(const char *s, int len, int pos=0) const
Does the pattern match.
Definition BESRegex.cc:70
string lookup(string name, const bool canonical_names=false)
Definition name_map.cc:69
void delete_all()
Definition name_map.cc:95
void add(char *raw_equiv)
Definition name_map.cc:56