bes  Updated for version 3.20.6
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 <XMLWriter.h>
30 
31 #include <BESError.h>
32 #include <BESDebug.h>
33 
34 #include "DmrppStructure.h"
35 
36 using namespace libdap;
37 using namespace std;
38 
39 namespace dmrpp {
40 
41 void
42 DmrppStructure::_duplicate(const DmrppStructure &)
43 {
44 }
45 
46 DmrppStructure::DmrppStructure(const string &n) : Structure(n), DmrppCommon()
47 {
48 }
49 
50 DmrppStructure::DmrppStructure(const string &n, const string &d) : Structure(n, d), DmrppCommon()
51 {
52 }
53 
54 BaseType *
55 DmrppStructure::ptr_duplicate()
56 {
57  return new DmrppStructure(*this);
58 }
59 
60 DmrppStructure::DmrppStructure(const DmrppStructure &rhs) : Structure(rhs), DmrppCommon(rhs)
61 {
62  _duplicate(rhs);
63 }
64 
65 DmrppStructure &
66 DmrppStructure::operator=(const DmrppStructure &rhs)
67 {
68  if (this == &rhs)
69  return *this;
70 
71  dynamic_cast<Structure &>(*this) = rhs; // run Constructor=
72 
73  _duplicate(rhs);
74  DmrppCommon::m_duplicate_common(rhs);
75 
76  return *this;
77 }
78 
79 #if 0
80 class PrintDAP4FieldXMLWriter : public unary_function<BaseType *, void>
81 {
82  XMLWriter &d_xml;
83  bool d_constrained;
84 public:
85  PrintDAP4FieldXMLWriter(XMLWriter &x, bool c) : d_xml(x), d_constrained(c) {}
86 
87  void operator()(BaseType *btp)
88  {
89  btp->print_dap4(d_xml, d_constrained);
90  }
91 };
92 
93 void
94 DmrppStructure::print_dap4(XMLWriter &xml, bool constrained)
95 {
96  if (constrained && !send_p())
97  return;
98 
99  if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar*)type_name().c_str()) < 0)
100  throw InternalErr(__FILE__, __LINE__, "Could not write " + type_name() + " element");
101 
102  if (!name().empty())
103  if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "name", (const xmlChar*)name().c_str()) < 0)
104  throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
105 
106  bool has_variables = (var_begin() != var_end());
107  if (has_variables)
108  for_each(var_begin(), var_end(), PrintDAP4FieldXMLWriter(xml, constrained));
109 
110  attributes()->print_dap4(xml);
111 
112  if (xmlTextWriterEndElement(xml.get_writer()) < 0)
113  throw InternalErr(__FILE__, __LINE__, "Could not end " + type_name() + " element");
114 }
115 #endif
116 
117 
118 void DmrppStructure::dump(ostream & strm) const
119 {
120  strm << BESIndent::LMarg << "DmrppStructure::dump - (" << (void *) this << ")" << endl;
121  BESIndent::Indent();
122  DmrppCommon::dump(strm);
123  Structure::dump(strm);
124  strm << BESIndent::LMarg << "value: " << "----" << /*d_buf <<*/ endl;
125  BESIndent::UnIndent();
126 }
127 
128 } // namespace dmrpp
129 
libdap
Definition: BESDapFunctionResponseCache.h:35