bes Updated for version 3.20.10
DmrppStructure.cc
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of the BES
5
6// Copyright (c) 2016 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include "config.h"
26
27#include <string>
28
29#include <libdap/XMLWriter.h>
30
31#include <BESError.h>
32#include <BESDebug.h>
33
34#include "DmrppStructure.h"
35
36using namespace libdap;
37using namespace std;
38
39namespace dmrpp {
40
41DmrppStructure &
42DmrppStructure::operator=(const DmrppStructure &rhs)
43{
44 if (this == &rhs)
45 return *this;
46
47 dynamic_cast<Structure &>(*this) = rhs; // run Constructor=
48
49 dynamic_cast<DmrppCommon &>(*this) = rhs;
50 //DmrppCommon::m_duplicate_common(rhs);
51
52 return *this;
53}
54
55#if 0
56class PrintDAP4FieldXMLWriter : public unary_function<BaseType *, void>
57{
58 XMLWriter &d_xml;
59 bool d_constrained;
60public:
61 PrintDAP4FieldXMLWriter(XMLWriter &x, bool c) : d_xml(x), d_constrained(c) {}
62
63 void operator()(BaseType *btp)
64 {
65 btp->print_dap4(d_xml, d_constrained);
66 }
67};
68
69void
70DmrppStructure::print_dap4(XMLWriter &xml, bool constrained)
71{
72 if (constrained && !send_p())
73 return;
74
75 if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar*)type_name().c_str()) < 0)
76 throw InternalErr(__FILE__, __LINE__, "Could not write " + type_name() + " element");
77
78 if (!name().empty())
79 if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "name", (const xmlChar*)name().c_str()) < 0)
80 throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
81
82 bool has_variables = (var_begin() != var_end());
83 if (has_variables)
84 for_each(var_begin(), var_end(), PrintDAP4FieldXMLWriter(xml, constrained));
85
86 attributes()->print_dap4(xml);
87
88 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
89 throw InternalErr(__FILE__, __LINE__, "Could not end " + type_name() + " element");
90}
91#endif
92
93void DmrppStructure::dump(ostream & strm) const
94{
95 strm << BESIndent::LMarg << "DmrppStructure::dump - (" << (void *) this << ")" << endl;
96 BESIndent::Indent();
97 DmrppCommon::dump(strm);
98 Structure::dump(strm);
99 strm << BESIndent::LMarg << "value: " << "----" << /*d_buf <<*/ endl;
100 BESIndent::UnIndent();
101}
102
103} // namespace dmrpp
104