bes Updated for version 3.20.10
DMZ.h
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of the BES
5
6// Copyright (c) 2021 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#ifndef h_dmz_h
26#define h_dmz_h 1
27
28//#include "config.h"
29
30#include <string>
31#include <vector>
32#include <set>
33#include <stack>
34#include <memory>
35
36#define PUGIXML_NO_XPATH
37#define PUGIXML_HEADER_ONLY
38#include <pugixml.hpp>
39
40#include <libdap/Type.h>
41
42namespace libdap {
43class DMR;
44class BaseType;
45class Array;
46class D4Group;
47class D4Attributes;
48class Constructor;
49}
50
51namespace http {
52class url;
53}
54
55namespace dmrpp {
56
57class DmrppCommon;
58
71class DMZ {
72
73private:
74 pugi::xml_document d_xml_doc;
75 std::shared_ptr<http::url> d_dataset_elem_href;
76
77 void process_dataset(libdap::DMR *dmr, const pugi::xml_node &xml_root);
78 pugi::xml_node get_variable_xml_node(libdap::BaseType *btp) const;
79 void process_chunk(dmrpp::DmrppCommon *dc, const pugi::xml_node &chunk) const;
80 void process_chunks(dmrpp::DmrppCommon *dc, const pugi::xml_node &chunks);
81
82 static void process_compact(libdap::BaseType *btp, const pugi::xml_node &compact);
83
84 static pugi::xml_node get_variable_xml_node_helper(const pugi::xml_node &var_node, std::stack<libdap::BaseType*> &bt);
85 static void build_basetype_chain(libdap::BaseType *btp, std::stack<libdap::BaseType*> &bt);
86
87 static void process_group(libdap::DMR *dmr, libdap::D4Group *parent, const pugi::xml_node &var_node);
88 static void process_dimension(libdap::D4Group *grp, const pugi::xml_node &dimension_node);
89 static void process_variable(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Constructor *parent, const pugi::xml_node &var_node);
90 static void process_dim(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Array *array, const pugi::xml_node &dim_node);
91 static void process_map(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Array *array, const pugi::xml_node &map_node);
92 static libdap::BaseType *build_variable(libdap::DMR *dmr, libdap::D4Group *group, libdap::Type t, const pugi::xml_node &var_node);
93 static libdap::BaseType *add_scalar_variable(libdap::DMR *dmr, libdap::D4Group *group, libdap::Constructor *parent, libdap::Type t, const pugi::xml_node &var_node);
94 static libdap::BaseType *add_array_variable(libdap::DMR *dmr, libdap::D4Group *grp, libdap::Constructor *parent, libdap::Type t, const pugi::xml_node &var_node);
95 static void process_attribute(libdap::D4Attributes *attributes, const pugi::xml_node &dap_attr_node);
96
97 static void process_cds_node(dmrpp::DmrppCommon *dc, const pugi::xml_node &chunks);
98
99 void load_attributes(libdap::BaseType *btp, pugi::xml_node var_node) const;
100
101 friend class DMZTest;
102
103public:
104
106 DMZ() = default;
107
108 explicit DMZ(const std::string &file_name);
109
110 virtual ~DMZ() = default;
111
112 // This is not virtual because we call it from a ctor
113 void parse_xml_doc(const std::string &filename);
114
115 virtual void build_thin_dmr(libdap::DMR *dmr);
116
117 virtual void load_attributes(libdap::BaseType *btp);
118 virtual void load_attributes(libdap::Constructor *constructor);
119 virtual void load_attributes(libdap::D4Group *group);
120
121 virtual void load_chunks(libdap::BaseType *btp);
122
123#if 0
124 // These were originally part of the design and intended to speed the delivery
125 // of the metadata responses, but the pugixml parser is so fast I don't think
126 // they are needed. Add them later if we really need them. jhrg 11/22/21
127 std::string get_attribute_xml(std::string path);
128 std::string get_variable_xml(std::string path);
129#endif
130
131 virtual void load_all_attributes(libdap::DMR *dmr);
132
133#if 0
134 // This was here because with lazy loading of attributes, the glabal values did
135 // not show up. But I've dropped the lazy attr load feature since it provides
136 // no measureable benefit for the test data we have. If we need lazy-attrs, the
137 // software is still in the handler, just mostly disabled. jhrg 11/22/21
138 virtual void load_global_attributes(libdap::DMR *dmr);
139#endif
140};
141
142} // namespace dmrpp
143
144#endif // h_dmz_h
145
Interface to hide the DMR++ information storage format.
Definition: DMZ.h:71
DMZ()=default
Build a DMZ without simultaneously parsing an XML document.
virtual void load_chunks(libdap::BaseType *btp)
Load the chunk information into a variable.
Definition: DMZ.cc:1050
void parse_xml_doc(const std::string &filename)
Build the DOM tree for a DMR++ XML document.
Definition: DMZ.cc:142
virtual void build_thin_dmr(libdap::DMR *dmr)
populate the DMR instance as a 'thin DMR'
Definition: DMZ.cc:574
Size and offset information of data included in DMR++ files.
Definition: DmrppCommon.h:76
utility class for the HTTP catalog module
Definition: AllowedHosts.cc:55
Type
Type of JSON value.
Definition: rapidjson.h:664