bes  Updated for version 3.20.6
XDGrid.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of asciival, software which can return an XML data
4 // representation of the data read from a DAP server.
5 
6 // Copyright (c) 2010 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 // Authors:
26 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
27 
28 // implementation for XDGrid. See XDByte.
29 //
30 // 3/12/98 jhrg
31 
32 #include "config.h"
33 
34 #include <iostream>
35 #include <string>
36 
37 using namespace std;
38 
39 #include <InternalErr.h>
40 
41 #include <BESDebug.h>
42 
43 // #define DODS_DEBUG
44 
45 #include "XDGrid.h"
46 #include "XDArray.h"
47 #include "debug.h"
48 #include "get_xml_data.h"
49 
50 using namespace xml_data;
51 
52 BaseType *
53 XDGrid::ptr_duplicate()
54 {
55  return new XDGrid(*this);
56 }
57 
58 XDGrid::XDGrid(const string &n) :
59  Grid(n)
60 {
61 }
62 
63 XDGrid::XDGrid(Grid *grid) :
64  Grid(grid->name()), XDOutput(grid)
65 {
66  BaseType *bt = basetype_to_xd(grid->array_var());
67  add_var(bt, libdap::array);
68  // add_var makes a copy of the base type passed to it, so delete it here
69  delete bt;
70  bt = 0;
71 
72  Grid::Map_iter i = grid->map_begin();
73  Grid::Map_iter e = grid->map_end();
74  while (i != e) {
75  bt = basetype_to_xd(*i);
76  add_var(bt, maps);
77  // add_var makes a copy of the base type passed to it, so delete it here
78  delete bt;
79  ++i;
80  }
81 
82  BaseType::set_send_p(grid->send_p());
83 }
84 
85 XDGrid::~XDGrid()
86 {
87 }
88 
89 void XDGrid::print_xml_data(XMLWriter *writer, bool show_type)
90 {
91  // General rule: If everything in the Grid (all maps plus the array)
92  // is projected, then print as a Grid, else print as if the Gird is a
93  // Structure.
94  if (projection_yields_grid())
95  start_xml_declaration(writer, "Grid"); // Start grid element
96  else
97  start_xml_declaration(writer, "Structure"); // Start structure element
98 
99  // Print the array and the maps, but use <Array> and not <Map>
100  if (array_var()->send_p()) {
101  dynamic_cast<XDArray&> (*array_var()).print_xml_data(writer, show_type);
102  }
103 
104  Map_iter m = map_begin();
105  while (m != map_end()) {
106  if ((*m)->send_p()) {
107  if (projection_yields_grid())
108  dynamic_cast<XDArray&> (**m).print_xml_map_data(writer, show_type);
109  else
110  dynamic_cast<XDArray&> (**m).print_xml_data(writer, show_type);
111  }
112  ++m;
113  }
114 
115  // End the structure element
116  end_xml_declaration(writer);
117 }
XDArray::print_xml_map_data
void print_xml_map_data(XMLWriter *writer, bool show_type)
Definition: XDArray.cc:100
XDArray
Definition: XDArray.h:42
XDGrid
Definition: XDGrid.h:39
XDOutput
Definition: XDOutput.h:42