libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
D4Maps.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of libdap, A C++ implementation of the OPeNDAP Data
4// Access Protocol.
5
6// Copyright (c) 2013 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 "XMLWriter.h"
28#include "InternalErr.h"
29#include "D4Group.h"
30#include "Array.h"
31#include "D4Dimensions.h"
32#include "D4Maps.h"
33
34using namespace libdap;
35
36Array* D4Map::array(D4Group *root)
37{
38 if (d_array)
39 return d_array;
40 else {
41 d_array = dynamic_cast<Array*>(root->find_var(d_array_path));
42 if (!d_array)
43 throw InternalErr(__FILE__, __LINE__,
44 std::string("Failed to find an array at: ").append(d_array_path));
45 return d_array;
46 }
47}
48
49void
50D4Map::print_dap4(XMLWriter &xml)
51{
52 if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar*) "Map") < 0)
53 throw InternalErr(__FILE__, __LINE__, "Could not write Map element");
54
55 if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "name",
56 (const xmlChar*)(d_array ? d_array->FQN().c_str(): d_name.c_str())) < 0)
57 throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");
58
59 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
60 throw InternalErr(__FILE__, __LINE__, "Could not end Map element");
61
62}
A multidimensional array of identical data types.
Definition: Array.h:123
virtual std::string FQN() const
Definition: BaseType.cc:329
BaseType * find_var(const string &name)
Definition: D4Group.cc:401
A class for software fault reporting.
Definition: InternalErr.h:65
top level DAP object to house generic methods
Definition: AlarmHandler.h:36