bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
XDStructure.cc
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of asciival, software which can return an XML data
5// representation of the data read from a DAP server.
6
7// Copyright (c) 2010 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26// Authors:
27// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
28
29// Implementation for the class XDStructure. See XDByte.cc
30//
31// 3/12/98 jhrg
32
33#include "config.h"
34
35#include <string>
36
37#include <BESDebug.h>
38
39#include <libdap/InternalErr.h>
40
41#include "XDStructure.h"
42#include "XDSequence.h"
43#include "get_xml_data.h"
44
45using namespace xml_data;
46using namespace libdap;
47
48BaseType *
49XDStructure::ptr_duplicate()
50{
51 return new XDStructure(*this);
52}
53
54XDStructure::XDStructure(const string &n) : Structure(n)
55{
56}
57
58XDStructure::XDStructure( Structure *bt )
59 : Structure( bt->name() ), XDOutput( bt )
60{
61 // Let's make the alternative structure of XD types now so that we
62 // don't have to do it on the fly. This will also set the parents of
63 // each of the underlying vars of the structure.
64 Vars_iter p = bt->var_begin();
65 while (p != bt->var_end()) {
66 BaseType *new_bt = basetype_to_xd(*p);
67 add_var(new_bt);
68 // add_var makes a copy of the base type passed to it, so delete
69 // it here
70 delete new_bt;
71 p++;
72 }
73
74 BaseType::set_send_p(bt->send_p());
75}
76
77XDStructure::~XDStructure()
78{
79}
80
81void
82XDStructure::start_xml_declaration(XMLWriter *writer, const char *element)
83{
84 XDOutput::start_xml_declaration(writer, element);
85
86 for (Vars_iter p = var_begin(); p != var_end(); ++p) {
87 if ((*p)->send_p()) {
88 dynamic_cast<XDOutput&>(**p).start_xml_declaration(writer, element);
89 dynamic_cast<XDOutput&>(**p).end_xml_declaration(writer);
90 }
91 }
92}
93
94void
95XDStructure::print_xml_data(XMLWriter *writer, bool show_type)
96{
97 // Forcing the use of the generic version prints just the <Structure>
98 // element w/o the type information of the components. That will be printed
99 // by the embedded print_xml_data calls.
100 if (show_type)
101 XDOutput::start_xml_declaration(writer);
102
103 for (Vars_iter p = var_begin(); p != var_end(); ++p) {
104 if ((*p)->send_p()) {
105 dynamic_cast<XDOutput&> (*(*p)).print_xml_data(writer, show_type);
106 }
107 }
108
109 // End the <Structure> element
110 if (show_type)
111 end_xml_declaration(writer);
112}
XDOutput(libdap::BaseType *bt)
Definition XDOutput.h:54