Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warnings 1 #255

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 141 additions & 27 deletions Array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@

#include "config.h"

// #define DODS_DEBUG

#include <algorithm>
#include <functional>
#include <sstream>

#include "Array.h"
#include "Grid.h"

#include "D4Attributes.h"
#include "D4Dimensions.h"
#include "D4Enum.h"
#include "D4EnumDefs.h"
Expand All @@ -56,21 +52,14 @@
#include "InternalErr.h"
#include "debug.h"
#include "escaping.h"
#include "util.h"

using namespace std;

namespace libdap {

Array::dimension::dimension(D4Dimension *d) : dim(d), use_sdim_for_slice(true) {
size = d->size();
name = d->name();

start = 0;
stop = size - 1;
stride = 1;
c_size = size;
}
// This constructor is defined here so that D4Dimensions.h does not need to be included in Array.h
Array::dimension::dimension(D4Dimension *d)
: size(d->size()), name(d->name()), dim(d), use_sdim_for_slice(true), stop(size - 1), c_size(size) {}

void Array::_duplicate(const Array &a) {
_shape = a._shape;
Expand Down Expand Up @@ -196,7 +185,6 @@ void Array::transform_to_dap4(D4Group *root, Constructor *container) {
} else {
DBG(cerr << __func__ << "() -" << " Using Existing D4Dimension '" << d4_dim->name() << "' ("
<< (void *)d4_dim << ")" << endl);
;

if (d4_dim->size() != (unsigned long)(*dap2_dim).size) {
// TODO Revisit this decision. jhrg 3/18/14
Expand Down Expand Up @@ -281,7 +269,6 @@ bool Array::is_dap2_grid() {
*/
std::vector<BaseType *> *Array::transform_to_dap2(AttrTable *) {
DBG(cerr << __func__ << "() - BEGIN Array '" << name() << "'" << endl);
;

BaseType *dest;
if (!is_dap4()) { // Don't convert a DAP2 thing
Expand Down Expand Up @@ -913,7 +900,12 @@ unsigned int Array::width(bool constrained) const
}
#endif

#if 0

class PrintD4ArrayDimXMLWriter: public unary_function<Array::dimension&, void> {
=======
class PrintD4ArrayDimXMLWriter : public unary_function<Array::dimension &, void> {
>>>>>>> master
XMLWriter &xml;
// Was this variable constrained using local/direct slicing? i.e., is d_local_constraint set?
// If so, don't use shared dimensions; instead emit Dim elements that are anonymous.
Expand Down Expand Up @@ -955,7 +947,12 @@ class PrintD4ArrayDimXMLWriter : public unary_function<Array::dimension &, void>
}
};

<<<<<<< HEAD

class PrintD4ConstructorVarXMLWriter : public unary_function<BaseType *, void> {
=======
class PrintD4ConstructorVarXMLWriter : public unary_function<BaseType *, void> {
>>>>>>> master
XMLWriter &xml;
bool d_constrained;

Expand All @@ -973,6 +970,7 @@ class PrintD4MapXMLWriter : public unary_function<D4Map *, void> {

void operator()(D4Map *m) { m->print_dap4(xml); }
};
#endif

/**
* @brief Print the DAP4 representation of an array.
Expand Down Expand Up @@ -1003,17 +1001,86 @@ void Array::print_dap4(XMLWriter &xml, bool constrained /* default: false*/) {
}

if (prototype()->is_constructor_type()) {
Constructor &c = static_cast<Constructor &>(*prototype());
for_each(c.var_begin(), c.var_end(), PrintD4ConstructorVarXMLWriter(xml, constrained));
// bind2nd(mem_fun_ref(&BaseType::print_dap4), xml));
auto const &c = static_cast<Constructor &>(*prototype());
#if 0
auto print_d4_constructor = [&xml, constrained](BaseType *btp) { btp->print_dap4(xml, constrained); };
for_each(c.var_begin(), c.var_end(), print_d4_constructor);
#endif
for (auto var : c.variables()) {
var->print_dap4(xml, constrained);
}
}

#if 0
// Drop the local_constraint which is per-array and use a per-dimension on instead
for_each(dim_begin(), dim_end(), PrintD4ArrayDimXMLWriter(xml, constrained));
auto print_d4_array_dim_xml_writer = [&xml, constrained](Array::dimension &d) {
// This duplicates code in D4Dimensions (where D4Dimension::print_dap4() is defined
// because of the need to print the constrained size of a dimension. I think that
// the constraint information has to be kept here and not in the dimension (since they
// are shared dims). Could hack print_dap4() to take the constrained size, however.
if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar *)"Dim") < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write Dim element");

string name = (d.dim) ? d.dim->fully_qualified_name() : d.name;
// If there is a name, there must be a Dimension (named dimension) in scope
// so write its name but not its size.
if (!constrained && !name.empty()) {
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name", (const xmlChar *)name.c_str()) <
0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
} else if (d.use_sdim_for_slice) {
assert(!name.empty());
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name", (const xmlChar *)name.c_str()) <
0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
} else {
ostringstream size;
size << (constrained ? d.c_size : d.size);
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"size",
(const xmlChar *)size.str().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
}

if (xmlTextWriterEndElement(xml.get_writer()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not end Dim element");
};

for_each(dim_begin(), dim_end(), print_d4_array_dim_xml_writer);
#endif

for (auto const &d : shape()) {
if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar *)"Dim") < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write Dim element");

string name = (d.dim) ? d.dim->fully_qualified_name() : d.name;
// If there is a name, there must be a Dimension (named dimension) in scope
// so write its name but not its size.
if (!constrained && !name.empty()) {
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name", (const xmlChar *)name.c_str()) <
0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
} else if (d.use_sdim_for_slice) {
assert(!name.empty());
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name", (const xmlChar *)name.c_str()) <
0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
} else {
ostringstream size;
size << (constrained ? d.c_size : d.size);
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"size",
(const xmlChar *)size.str().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
}

if (xmlTextWriterEndElement(xml.get_writer()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not end Dim element");
}

attributes()->print_dap4(xml);

for_each(maps()->map_begin(), maps()->map_end(), PrintD4MapXMLWriter(xml));
auto print_d4_map = [&xml](D4Map *m) { m->print_dap4(xml); };

for_each(maps()->map_begin(), maps()->map_end(), print_d4_map);

if (xmlTextWriterEndElement(xml.get_writer()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not end " + type_name() + " element");
Expand Down Expand Up @@ -1143,7 +1210,12 @@ void Array::print_as_map_xml_writer(XMLWriter &xml, bool constrained) {
print_xml_writer_core(xml, constrained, "Map");
}

#if 0

class PrintArrayDimXMLWriter: public unary_function<Array::dimension&, void> {
=======
class PrintArrayDimXMLWriter : public unary_function<Array::dimension &, void> {
>>>>>>> master
XMLWriter &xml;
bool d_constrained;

Expand All @@ -1170,16 +1242,18 @@ class PrintArrayDimXMLWriter : public unary_function<Array::dimension &, void> {
}
};

#endif

void Array::print_xml_writer_core(XMLWriter &xml, bool constrained, string tag) {
if (constrained && !send_p())
return;

if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar *)tag.c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write " + tag + " element");

if (!name().empty())
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name", (const xmlChar *)name().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
if (!name().empty() &&
xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name", (const xmlChar *)name().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");

get_attr_table().print_xml_writer(xml);

Expand All @@ -1189,7 +1263,47 @@ void Array::print_xml_writer_core(XMLWriter &xml, bool constrained, string tag)
btp->print_xml_writer(xml, constrained);
btp->set_name(tmp_name);

for_each(dim_begin(), dim_end(), PrintArrayDimXMLWriter(xml, constrained));
#if 0
auto print_array_dim_xml_writer = [&xml, constrained](Array::dimension &d) {
if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar *)"dimension") < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write dimension element");

if (!d.name.empty())
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name",
(const xmlChar *)d.name.c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");

ostringstream size;
size << (constrained ? d.c_size : d.size);
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"size",
(const xmlChar *)size.str().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");

if (xmlTextWriterEndElement(xml.get_writer()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not end dimension element");
};

for_each(dim_begin(), dim_end(), print_array_dim_xml_writer);
#endif

for (auto const &d : shape()) {
if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar *)"dimension") < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write dimension element");

if (!d.name.empty())
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"name",
(const xmlChar *)d.name.c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");

ostringstream size;
size << (constrained ? d.c_size : d.size);
if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar *)"size",
(const xmlChar *)size.str().c_str()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");

if (xmlTextWriterEndElement(xml.get_writer()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not end dimension element");
}

if (xmlTextWriterEndElement(xml.get_writer()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not end " + tag + " element");
Expand Down Expand Up @@ -1289,13 +1403,13 @@ void Array::print_val(ostream &out, string space, bool print_decl_p) {

auto shape = new uint64_t[dimensions(true)];
unsigned int index = 0;
for (Dim_iter i = _shape.begin(); i != _shape.end() && index < dimensions(true); ++i)
for (auto i = _shape.begin(); i != _shape.end() && index < dimensions(true); ++i)
shape[index++] = dimension_size_ll(i, true);

print_array(out, 0, dimensions(true), shape);

delete[] shape;
shape = 0;
shape = nullptr;

if (print_decl_p) {
out << ";\n";
Expand Down
37 changes: 13 additions & 24 deletions Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,38 +139,27 @@ class Array : public Vector {
// pointer; it is shared between the array and the Group where the
// Dimension is defined. To keep Array manageable to implement, size
// will be set here using the value from 'dim' if it is not null.
int64_t size; ///< The unconstrained dimension size.
string name; ///< The name of this dimension.
int64_t size = 0; ///< The unconstrained dimension size.
string name; ///< The name of this dimension.

D4Dimension *dim; ///< If not null, a weak pointer to the D4Dimension
D4Dimension *dim = nullptr; ///< If not null, a weak pointer to the D4Dimension

// when a DMR is printed for a data response, if an array uses shared
// dimensions and those sdims have been sliced, make sure to use those
// and get the syntax correct. That's what this field does - in every
// case the array records the sizes of its dimensions and their slices
// regardless of whether they were provided explicitly in a CE or inherited
// from a sliced sdim.
bool use_sdim_for_slice; ///< Used to control printing the DMR in data responses

int64_t start; ///< The constraint start index
int64_t stop; ///< The constraint end index
int64_t stride; ///< The constraint stride
int64_t c_size; ///< Size of dimension once constrained

dimension() : size(0), name(""), dim(0), use_sdim_for_slice(false) {
// this information changes with each constraint expression
start = 0;
stop = 0;
stride = 1;
c_size = size;
}

dimension(int64_t s, string n) : size(s), name(n), dim(0), use_sdim_for_slice(false) {
start = 0;
stop = size - 1;
stride = 1;
c_size = size;
}
bool use_sdim_for_slice = false; ///< Used to control printing the DMR in data responses

int64_t start = 0; ///< The constraint start index
int64_t stop = 0; ///< The constraint end index
int64_t stride = 1; ///< The constraint stride
int64_t c_size = 0; ///< Size of dimension once constrained

dimension() = default;

dimension(int64_t s, string n) : size(s), name(std::move(n)), stop(s - 1), c_size(s) {}

explicit dimension(D4Dimension *d);
};
Expand Down
4 changes: 2 additions & 2 deletions D4Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class D4Enum : public BaseType {

void dump(ostream &strm) const override;

unsigned int val2buf(void *, bool);
unsigned int buf2val(void **);
unsigned int val2buf(void *, bool) override;
unsigned int buf2val(void **) override;

std::vector<BaseType *> *transform_to_dap2(AttrTable *parent_attr_table) override;
};
Expand Down
15 changes: 13 additions & 2 deletions DDS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,8 @@ void DDS::print_xml(FILE *out, bool constrained, const string &blob) {
@deprecated */
void DDS::print_xml(ostream &out, bool constrained, const string &blob) { print_xml_writer(out, constrained, blob); }

#if 0

class VariablePrintXMLWriter : public unary_function<BaseType *, void> {
XMLWriter &d_xml;
bool d_constrained;
Expand All @@ -1138,6 +1140,8 @@ class VariablePrintXMLWriter : public unary_function<BaseType *, void> {
void operator()(BaseType *bt) { bt->print_xml_writer(d_xml, d_constrained); }
};

#endif

/**
* Print the DDX. This code uses the libxml2 'TextWriter' interface; something
* that seems to be a good compromise between doing it by hand (although more
Expand Down Expand Up @@ -1202,8 +1206,13 @@ void DDS::print_xml_writer(ostream &out, bool constrained, const string &blob) {
// Print the global attributes
d_attr.print_xml_writer(xml);

// Print each variable
#if 0
for_each(var_begin(), var_end(), VariablePrintXMLWriter(xml, constrained));
#endif
// Print each variable
for (auto const &var : variables()) {
var->print_xml_writer(xml, constrained);
}

if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar *)"blob") < 0)
throw InternalErr(__FILE__, __LINE__, "Could not write blob element");
Expand Down Expand Up @@ -1279,7 +1288,9 @@ void DDS::print_dmr(ostream &out, bool constrained) {
d_attr.print_xml_writer(xml);

// Print each variable
for_each(var_begin(), var_end(), VariablePrintXMLWriter(xml, constrained));
for (auto const &var : variables()) {
var->print_xml_writer(xml, constrained);
}

if (xmlTextWriterEndElement(xml.get_writer()) < 0)
throw InternalErr(__FILE__, __LINE__, "Could not end the top-level Group element");
Expand Down
Loading
Loading