OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
AggMemberDatasetUsingLocationRef.cc
Go to the documentation of this file.
1 // This file is part of the "NcML Module" project, a BES module designed
3 // to allow NcML files to be used to be used as a wrapper to add
4 // AIS to existing datasets of any format.
5 //
6 // Copyright (c) 2010 OPeNDAP, Inc.
7 // Author: Michael Johnson <m.johnson@opendap.org>
8 //
9 // For more information, please also see the main website: http://opendap.org/
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26 //
27 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
30 
31 #include "BESDataDDSResponse.h" // bes
32 #include "DataDDS.h"
33 #include "DDS.h" // libdap
34 #include "NCMLDebug.h" // ncml_module
35 #include "NCMLUtil.h" // ncml_module
36 
37 namespace agg_util
38 {
39 
41  const std::string& locationToLoad,
42  const agg_util::DDSLoader& loaderToUse)
44  , _loader(loaderToUse)
45  , _pDataResponse(0)
46  {
47  }
48 
50  {
51  cleanup();
52  }
53 
57  , _loader(proto._loader)
58  , _pDataResponse(0) // force a reload as needed for a copy
59  {
60  }
61 
64  {
65  if (this != &that)
66  {
67  // clear out any old loaded stuff
68  cleanup();
69  // assign
71  copyRepFrom(that);
72  }
73  return *this;
74  }
75 
76 
77  const libdap::DataDDS*
79  {
80  if (!_pDataResponse)
81  {
82  loadDataDDS();
83  }
84  DataDDS* pDDSRet = 0;
85  if (_pDataResponse)
86  {
87  pDDSRet = _pDataResponse->get_dds();
88  }
89  return pDDSRet;
90  }
91 
93  void
94  AggMemberDatasetUsingLocationRef::loadDataDDS()
95  {
96  // We cannot load an empty location, so avoid the exception later.
97  if (getLocation().empty())
98  {
99  THROW_NCML_INTERNAL_ERROR("AggMemberDatasetUsingLocationRef():"
100  " got empty location! Cannot load!");
101  }
102 
103  // Make a new response and store the raw ptr, noting that we need to delete it in dtor.
104  std::auto_ptr<BESDapResponse> newResponse = _loader.makeResponseForType(DDSLoader::eRT_RequestDataDDS);
105  VALID_PTR(newResponse.get());
106  // static_cast should work here, but I want to be sure since DataDDX is in the works...
107  _pDataResponse = dynamic_cast<BESDataDDSResponse*>(newResponse.get());
108  NCML_ASSERT_MSG(_pDataResponse,
109  "AggMemberDatasetUsingLocationRef::loadDDS(): "
110  " failed to get a BESDataDDSResponse back"
111  " while loading location=" + getLocation());
112  // release after potential for exception to avoid leak
113  newResponse.release();
114 
115  BESDEBUG("ncml", "Loading DataDDS for aggregation member location = " << getLocation() << endl);
116  _loader.loadInto(getLocation(), DDSLoader::eRT_RequestDataDDS, _pDataResponse);
117  }
118 
119  void
120  AggMemberDatasetUsingLocationRef::cleanup() throw()
121  {
122  SAFE_DELETE(_pDataResponse);
123  }
124 
125  void
126  AggMemberDatasetUsingLocationRef::copyRepFrom(const AggMemberDatasetUsingLocationRef& rhs)
127  {
128  _loader = rhs._loader;
129  _pDataResponse = 0; // force this to be NULL... we want to reload if we get an assignment
130  }
131 
132 }
static std::auto_ptr< BESDapResponse > makeResponseForType(ResponseType type)
Make a new response object for the requested type.
Definition: DDSLoader.cc:333
virtual const libdap::DataDDS * getDataDDS()
If not loaded yet, loads the DataDDS response, then returns it.
#define SAFE_DELETE(a)
Definition: NCMLUtil.h:64
class AggMemberDatasetUsingLocationRef: Concrete subclass of AggMemberDataset for lazy-loading a loca...
Helper class for temporarily hijacking an existing dhi to load a DDX response for one particular file...
#define NCML_ASSERT_MSG(cond, msg)
Definition: NCMLDebug.h:83
AggMemberDatasetWithDimensionCacheBase & operator=(const AggMemberDatasetWithDimensionCacheBase &rhs)
const std::string & getLocation() const
The location to which the AggMemberDataset refers Note: this could be "" for some subclasses if they ...
void loadInto(const std::string &location, ResponseType type, BESDapResponse *pResponse)
Load a DDX or DataDDS response into the given pResponse object, which must be non-null.
Definition: DDSLoader.cc:141
AggMemberDatasetUsingLocationRef(const std::string &locationToLoad, const agg_util::DDSLoader &loaderToUse)
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
#define THROW_NCML_INTERNAL_ERROR(msg)
Definition: NCMLDebug.h:61
AggMemberDatasetUsingLocationRef & operator=(const AggMemberDatasetUsingLocationRef &rhs)
#define VALID_PTR(ptr)
Definition: NCMLDebug.h:88
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
Interface class for a reference counted object.