libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
AISMerge.cc
Go to the documentation of this file.
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9// Dan Holloway <dan@hollywood.gso.uri.edu>
10// Reza Nekovei <reza@intcomm.net>
11//
12// This library is free software; you can redistribute it and/or
13// modify it under the terms of the GNU Lesser General Public
14// License as published by the Free Software Foundation; either
15// version 2.1 of the License, or (at your option) any later version.
16//
17// This library is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20// Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public
23// License along with this library; if not, write to the Free Software
24// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25//
26// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
27
28#include "config.h"
29
30#include <cstdio>
31#include <fstream>
32
33#include "AISExceptions.h"
34#include "AISMerge.h"
35#include "Response.h"
36
37namespace libdap {
38
52 if (res.find("http:") == 0 || res.find("file:") == 0 || res.find("https:") == 0) {
53 return d_http.fetch_url(res);
54 } else {
55 FILE *s = fopen(res.c_str(), "r");
56 if (!s)
57 throw Error("I could not open local AIS resource '" + res + "'.");
58 return new Response(s, 0);
59 }
60}
61
75void AISMerge::merge(const string &primary, DAS &das) {
76 if (!d_ais_db.has_resource(primary))
77 return;
78
79 try {
80 ResourceVector rv = d_ais_db.get_resource(primary);
81
82 for (ResourceVectorIter i = rv.begin(); i != rv.end(); ++i) {
83 Response *ais_resource = get_ais_resource(i->get_url());
84 switch (i->get_rule()) {
86 das.parse(ais_resource->get_stream());
87 break;
89 das.erase();
90 das.parse(ais_resource->get_stream());
91 break;
93 if (das.get_size() == 0)
94 das.parse(ais_resource->get_stream());
95 break;
96 }
97 delete ais_resource;
98 ais_resource = 0;
99 }
100 } catch (NoSuchPrimaryResource &e) {
101 throw InternalErr(string("I caught a 'NoSuchPrimaryResource' exception, it said:\n") + e.get_error_message() +
102 string("\n"));
103 }
104}
105
106} // namespace libdap
virtual void merge(const string &primary, DAS &das)
Definition AISMerge.cc:75
virtual Response * get_ais_resource(const string &res)
Definition AISMerge.cc:51
Hold attribute data for a DAP2 dataset.
Definition DAS.h:119
virtual unsigned int get_size() const
Returns the number of attributes in the current attribute table.
Definition DAS.cc:120
virtual void parse(string fname)
Reads a DAS from the named file.
Definition DAS.cc:213
virtual void erase()
erase all attributes in this DAS
Definition DAS.cc:129
A class for error processing.
Definition Error.h:92
std::string get_error_message() const
Definition Error.cc:212
A class for software fault reporting.
Definition InternalErr.h:61
virtual FILE * get_stream() const
Definition Response.h:103
top level DAP object to house generic methods
Definition AISConnect.cc:30
vector< Resource > ResourceVector
ResourceVector::iterator ResourceVectorIter