bes  Updated for version 3.20.6
NCMLUtil.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 #ifndef __NCML_MODULE_NCML_UTIL_H__
30 #define __NCML_MODULE_NCML_UTIL_H__
31 
46 namespace libdap {
47 // FDecls
48 class BaseType;
49 class Constructor;
50 class DDS;
51 class DAS;
52 class AttrTable;
53 }
54 
55 class BESDapResponse;
56 
57 #include <string>
58 #include <vector>
59 
60 // If there isn't one defined yet, define a safe delete
61 // to clear ptr after delete to avoid problems.
62 #ifndef SAFE_DELETE
63 #define SAFE_DELETE(a) { delete (a); (a) = 0; }
64 #endif // SAFE_DELETE
65 
66 namespace ncml_module {
70 class NCMLUtil {
71  NCMLUtil()
72  {
73  }
74 public:
75  ~NCMLUtil()
76  {
77  }
78 
80  static const std::string WHITESPACE;
81 
86  static int tokenize(const std::string& str, std::vector<std::string>& tokens,
87  const std::string& delimiters = " \t");
88 
90  static int tokenizeChars(const std::string& str, std::vector<std::string>& tokens);
91 
95  static bool isAscii(const std::string& str);
96 
98  static bool isAllWhitespace(const std::string& str);
99 
102  static void trimLeft(std::string& str, const std::string& trimChars = WHITESPACE);
103 
106  static void trimRight(std::string& str, const std::string& trimChars = WHITESPACE);
107 
110  static void trim(std::string& str, const std::string& trimChars = WHITESPACE)
111  {
112  trimLeft(str, trimChars);
113  trimRight(str, trimChars);
114  }
115 
119  static void trimAll(std::vector<std::string>& tokens, const std::string& trimChars = WHITESPACE);
120 
127  static bool toUnsignedInt(const std::string& stringVal, unsigned int& oVal);
128 
133  static void populateDASFromDDS(libdap::DAS* das, const libdap::DDS& dds_const);
134 
141  static void copyVariablesAndAttributesInto(libdap::DDS* dds_out, const libdap::DDS& dds_in);
142 
149  static libdap::DDS* getDDSFromEitherResponse(BESDapResponse* response);
150 
151  static void hackGlobalAttributesForDAP2(libdap::AttrTable &global_attributes,
152  const std::string &global_container_name);
153 
159  static void setVariableNameProperly(libdap::BaseType* pVar, const std::string& name);
160 
161 };
162 // class NCMLUtil
163 }// namespace ncml_module
164 
165 #endif /* __NCML_MODULE_NCML_UTIL_H__ */
ncml_module::NCMLUtil::trimRight
static void trimRight(std::string &str, const std::string &trimChars=WHITESPACE)
Definition: NCMLUtil.cc:117
BESDapResponse
Represents an OPeNDAP DAP response object within the BES.
Definition: BESDapResponse.h:41
ncml_module::NCMLUtil::WHITESPACE
static const std::string WHITESPACE
Definition: NCMLUtil.h:80
ncml_module::NCMLUtil::trimLeft
static void trimLeft(std::string &str, const std::string &trimChars=WHITESPACE)
Definition: NCMLUtil.cc:108
libdap
Definition: BESDapFunctionResponseCache.h:35
ncml_module::NCMLUtil
Definition: NCMLUtil.h:70
ncml_module::NCMLUtil::getDDSFromEitherResponse
static libdap::DDS * getDDSFromEitherResponse(BESDapResponse *response)
Definition: NCMLUtil.cc:354
ncml_module::NCMLUtil::toUnsignedInt
static bool toUnsignedInt(const std::string &stringVal, unsigned int &oVal)
Definition: NCMLUtil.cc:133
ncml_module::NCMLUtil::isAscii
static bool isAscii(const std::string &str)
Definition: NCMLUtil.cc:92
ncml_module::NCMLUtil::copyVariablesAndAttributesInto
static void copyVariablesAndAttributesInto(libdap::DDS *dds_out, const libdap::DDS &dds_in)
Definition: NCMLUtil.cc:330
ncml_module::NCMLUtil::trim
static void trim(std::string &str, const std::string &trimChars=WHITESPACE)
Definition: NCMLUtil.h:110
ncml_module::NCMLUtil::trimAll
static void trimAll(std::vector< std::string > &tokens, const std::string &trimChars=WHITESPACE)
Definition: NCMLUtil.cc:125
ncml_module::NCMLUtil::isAllWhitespace
static bool isAllWhitespace(const std::string &str)
Definition: NCMLUtil.cc:103
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
ncml_module::NCMLUtil::tokenize
static int tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" \t")
Definition: NCMLUtil.cc:56
ncml_module::NCMLUtil::tokenizeChars
static int tokenizeChars(const std::string &str, std::vector< std::string > &tokens)
Definition: NCMLUtil.cc:80
ncml_module::NCMLUtil::setVariableNameProperly
static void setVariableNameProperly(libdap::BaseType *pVar, const std::string &name)
Definition: NCMLUtil.cc:460
ncml_module::NCMLUtil::populateDASFromDDS
static void populateDASFromDDS(libdap::DAS *das, const libdap::DDS &dds_const)
Definition: NCMLUtil.cc:274