OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
NCMLUtil.h
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 #ifndef __NCML_MODULE_NCML_UTIL_H__
30 #define __NCML_MODULE_NCML_UTIL_H__
31 
46 namespace libdap
47 {
48  // FDecls
49  class BaseType;
50  class Constructor;
51  class DDS;
52  class DAS;
53  class AttrTable;
54 }
55 
56 class BESDapResponse;
57 
58 #include <string>
59 #include <vector>
60 
61 // If there isn't one defined yet, define a safe delete
62 // to clear ptr after delete to avoid problems.
63 #ifndef SAFE_DELETE
64 #define SAFE_DELETE(a) { delete (a); (a) = 0; }
65 #endif // SAFE_DELETE
66 
67 namespace ncml_module
68 {
72  class NCMLUtil
73  {
74  NCMLUtil() {}
75  public:
76  ~NCMLUtil() {}
77 
79  static const std::string WHITESPACE;
80 
85  static int tokenize(
86  const std::string& str,
87  std::vector<std::string>& tokens,
88  const std::string& delimiters = " \t");
89 
91  static int tokenizeChars(
92  const std::string& str,
93  std::vector<std::string>& tokens);
94 
98  static bool isAscii(const std::string& str);
99 
101  static bool isAllWhitespace(const std::string& str);
102 
105  static void trimLeft(
106  std::string& str,
107  const std::string& trimChars = WHITESPACE);
108 
111  static void trimRight(
112  std::string& str,
113  const std::string& trimChars = WHITESPACE);
114 
117  static void trim(
118  std::string& str,
119  const std::string& trimChars = WHITESPACE)
120  {
121  trimLeft(str, trimChars);
122  trimRight(str, trimChars);
123  }
124 
128  static void trimAll(
129  std::vector<std::string>& tokens,
130  const std::string& trimChars = WHITESPACE);
131 
132 
139  static bool toUnsignedInt(const std::string& stringVal, unsigned int& oVal);
140 
145  static void populateDASFromDDS(libdap::DAS* das, const libdap::DDS& dds_const);
146 
153  static void copyVariablesAndAttributesInto(
154  libdap::DDS* dds_out,
155  const libdap::DDS& dds_in);
156 
163  static libdap::DDS* getDDSFromEitherResponse(BESDapResponse* response);
164 
165  static void hackGlobalAttributesForDAP2(libdap::AttrTable &global_attributes, const std::string &global_container_name);
166 
172  static void setVariableNameProperly(
173  libdap::BaseType* pVar,
174  const std::string& name);
175 
176  }; // class NCMLUtil
177 } // namespace ncml_module
178 
179 #endif /* __NCML_MODULE_NCML_UTIL_H__ */
static void copyVariablesAndAttributesInto(libdap::DDS *dds_out, const libdap::DDS &dds_in)
Make a deep copy of the global attributes and variables within dds_in into *dds_out.
Definition: NCMLUtil.cc:256
static bool isAscii(const std::string &str)
Does the string contain only ASCII 7-bit characters according to isascii()?
Definition: NCMLUtil.cc:96
static void trimLeft(std::string &str, const std::string &trimChars=WHITESPACE)
Trim off any number of any character in trimChars from the left side of str in place.
Definition: NCMLUtil.cc:116
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
static bool isAllWhitespace(const std::string &str)
Is all the string whitespace as defined by chars in WHITESPACE ?
Definition: NCMLUtil.cc:110
static libdap::DDS * getDDSFromEitherResponse(BESDapResponse *response)
Return the DDS* for the given response object.
Definition: NCMLUtil.cc:282
static bool toUnsignedInt(const std::string &stringVal, unsigned int &oVal)
Convert the string to an unsigned int into oVal.
Definition: NCMLUtil.cc:146
static class NCMLUtil overview
static int tokenizeChars(const std::string &str, std::vector< std::string > &tokens)
Split str into a vector with one char in str per token slot.
Definition: NCMLUtil.cc:82
static void trim(std::string &str, const std::string &trimChars=WHITESPACE)
Trim from both left and right.
Definition: NCMLUtil.h:117
Static class of utility functions.
Definition: NCMLUtil.h:72
static void trimRight(std::string &str, const std::string &trimChars=WHITESPACE)
Trim off any number of any character in trimChars from the right side of str in place.
Definition: NCMLUtil.cc:126
static void setVariableNameProperly(libdap::BaseType *pVar, const std::string &name)
Currently BaseType::set_name only sets in BaseType.
Definition: NCMLUtil.cc:398
Represents an OPeNDAP DAP response object within the BES.
static void populateDASFromDDS(libdap::DAS *das, const libdap::DDS &dds_const)
Given we have a valid attribute tree inside of the DDS, recreate it in the DAS.
Definition: NCMLUtil.cc:200
static void hackGlobalAttributesForDAP2(libdap::AttrTable &global_attributes, const std::string &global_container_name)
Definition: NCMLUtil.cc:318
static void trimAll(std::vector< std::string > &tokens, const std::string &trimChars=WHITESPACE)
Call trim on each string in tokens.
Definition: NCMLUtil.cc:136
static const std::string WHITESPACE
Delimiter set for tokenizing whitespace separated data.
Definition: NCMLUtil.h:79
static int tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" \t")
Split str into tokens using the characters in delimiters as split boundaries.
Definition: NCMLUtil.cc:54