38 #include "Constructor.h"
41 #include <AttrTable.h>
54 NCMLUtil::tokenize(
const string& str,
55 vector<string>& tokens,
56 const string& delimiters)
58 BESDEBUG(
"ncml",
"NCMLUtil::tokenize value of str:" << str << endl);
63 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
65 string::size_type pos = str.find_first_of(delimiters, lastPos);
68 while (string::npos != pos || string::npos != lastPos)
71 tokens.push_back(str.substr(lastPos, pos - lastPos));
74 lastPos = str.find_first_not_of(delimiters, pos);
76 pos = str.find_first_of(delimiters, lastPos);
82 NCMLUtil::tokenizeChars(
const string& str, vector<string>& tokens)
86 for (
unsigned int i=0; i<str.size(); ++i)
90 tokens.push_back(val);
96 NCMLUtil::isAscii(
const string& str)
98 string::const_iterator endIt = str.end();
99 for (string::const_iterator it = str.begin(); it != endIt; ++it)
110 NCMLUtil::isAllWhitespace(
const string& str)
112 return (str.find_first_not_of(
" \t\n") == string::npos);
116 NCMLUtil::trimLeft(std::string& input,
const std::string& trimChars )
118 size_t firstValid = input.find_first_not_of(trimChars);
119 input.erase(0, firstValid);
126 NCMLUtil::trimRight(std::string& input,
const std::string& trimChars )
128 size_t lastValid = input.find_last_not_of(trimChars);
129 if (lastValid != string::npos)
131 input.erase(lastValid+1, string::npos);
136 NCMLUtil::trimAll(std::vector<std::string>& tokens,
const std::string& trimChars )
138 unsigned int num = tokens.size();
139 for (
unsigned int i=0; i<num; ++i)
141 trim(tokens[i], trimChars);
146 NCMLUtil::toUnsignedInt(
const std::string& stringVal,
unsigned int& oVal)
150 istringstream iss(stringVal);
153 (stringVal[0] ==
'-')
165 static void populateAttrTableForContainerVariableRecursive(AttrTable* dasTable, Constructor* consVar)
170 BESDEBUG(
"ncml",
"Recursively adding attribute tables for children of composite variable " << consVar->name() <<
"..." << endl);
171 Constructor::Vars_iter endIt = consVar->var_end();
172 for (Constructor::Vars_iter it = consVar->var_begin(); it != endIt; ++it)
176 BESDEBUG(
"ncml",
"Adding attribute table for var: " << var->name() << endl);
178 AttrTable* newTable =
new AttrTable(var->get_attr_table());
180 dasTable->append_container(newTable, var->name());
183 if (var->is_constructor_type())
185 Constructor* child =
dynamic_cast<Constructor*
>(var);
191 BESDEBUG(
"ncml",
"Var " << child->name() <<
" is composite, so recursively adding attribute tables" << endl);
192 populateAttrTableForContainerVariableRecursive(newTable, child);
200 NCMLUtil::populateDASFromDDS(DAS* das,
const DDS& dds_const)
202 BESDEBUG(
"ncml",
"Populating a DAS from a DDS...." << endl);
210 DDS& dds =
const_cast<DDS&
>(dds_const);
216 BESDEBUG(
"ncml",
"populateDASFromDDS got unexpected container " << dds.container_name() <<
" and is failing." << endl);
217 throw BESInternalError(
"Unexpected Container Error creating DAS from DDS in NCMLHandler", __FILE__, __LINE__);
222 *(das->get_top_level_attributes()) = dds.get_attr_table();
227 DDS::Vars_iter endIt = dds.var_end();
228 for (DDS::Vars_iter it = dds.var_begin(); it != endIt; ++it)
235 AttrTable* clonedVarTable =
new AttrTable(var->get_attr_table());
237 das->add_table(var->name(), clonedVarTable);
240 if (var->is_constructor_type())
242 Constructor* consVar =
dynamic_cast<Constructor*
>(var);
248 populateAttrTableForContainerVariableRecursive(clonedVarTable, consVar);
256 NCMLUtil::copyVariablesAndAttributesInto(DDS* dds_out,
const DDS& dds_in)
261 if (dds_out == &dds_in)
267 DDS& dds =
const_cast<DDS&
>(dds_in);
270 dds_out->get_attr_table() = dds.get_attr_table();
275 for (DDS::Vars_iter i = dds.var_begin(); i != dds.var_end(); ++i)
277 dds_out->add_var(*i);
290 pDDS = pDDXResponse->
get_dds();
292 else if (pDataDDSResponse)
294 pDDS = pDataDDSResponse->
get_dds();
301 BESDEBUG(
"ncml_attr",
"DDS' global table contains " << pDDS->get_attr_table().get_size() <<
" attributes." << endl);
318 NCMLUtil::hackGlobalAttributesForDAP2(libdap::AttrTable &global_attributes,
const std::string &global_container_name)
320 if (global_container_name.empty())
330 bool simple_attribute_found =
false;
331 AttrTable::Attr_iter i = global_attributes.attr_begin();
332 while (!simple_attribute_found && i != global_attributes.attr_end()) {
333 if (!global_attributes.is_container(i))
334 simple_attribute_found =
true;
339 if (!simple_attribute_found)
343 bool only_simple_attributes =
true;
344 i = global_attributes.attr_begin();
345 while (only_simple_attributes && i != global_attributes.attr_end()) {
346 if (global_attributes.is_container(i))
347 only_simple_attributes =
false;
355 if (only_simple_attributes)
357 AttrTable *new_global_attr_container =
new AttrTable();
358 AttrTable *new_attr_container = new_global_attr_container->append_container(global_container_name);
359 *new_attr_container = global_attributes;
360 global_attributes = *new_global_attr_container;
366 AttrTable *new_attr_container = global_attributes.find_container(global_container_name);
367 if (!new_attr_container)
368 new_attr_container = global_attributes.append_container(global_container_name);
371 i = global_attributes.attr_begin();
372 while (i != global_attributes.attr_end()) {
373 if (!global_attributes.is_container(i)) {
374 new_attr_container->append_attr(global_attributes.get_name(i),
375 global_attributes.get_type(i), global_attributes.get_attr_vector(i));
382 i = global_attributes.attr_begin();
383 while (i != global_attributes.attr_end()) {
384 if (!global_attributes.is_container(i)) {
385 global_attributes.del_attr(global_attributes.get_name(i));
387 i = global_attributes.attr_begin();
398 NCMLUtil::setVariableNameProperly(libdap::BaseType* pVar,
const std::string& name)
401 pVar->set_name(name);
403 BaseType* pTemplate = pVar->var();
406 pTemplate->set_name(name);
exception thrown if inernal error encountered
Represents an OPeNDAP DDS DAP2 data object within the BES.
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
static class NCMLUtil overview
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Represents an OPeNDAP DAP response object within the BES.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream