bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
CatalogNode.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the OPeNDAP Back-End Server (BES)
4
5// Copyright (c) 2018 OPeNDAP, Inc.
6// Author: James Gallagher <jgallagher@opendap.org>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23
24#include "config.h"
25
26#include <cassert>
27
28#include <string>
29#include <ostream>
30#include <sstream>
31
32#include "BESIndent.h"
33#include "BESUtil.h"
34
35#include "BESCatalogList.h"
36#include "BESInfo.h"
37#include "CatalogNode.h"
38#include "CatalogItem.h"
39
40using namespace bes;
41using namespace std;
42
43CatalogNode::~CatalogNode()
44{
45#if ITEMS
46 for (std::vector<CatalogItem*>::iterator i = d_items.begin(), e = d_items.end(); i != e; ++i)
47 delete *i;
48 d_items.clear();
49#endif
50
51#if NODES_AND_LEAVES
52 for (std::vector<CatalogItem*>::iterator i = d_nodes.begin(), e = d_nodes.end(); i != e; ++i)
53 delete *i;
54 d_nodes.clear();
55
56 for (std::vector<CatalogItem*>::iterator i = d_leaves.begin(), e = d_leaves.end(); i != e; ++i)
57 delete *i;
58 d_leaves.clear();
59#endif
60 delete d_no_really_im_a_leaf;
61 d_no_really_im_a_leaf = 0;;
62}
63
78void
80{
81 map<string, string, std::less<>> props;
82
83 // The node may actually be a leaf. Check and act accordingly.
84 CatalogItem *im_a_leaf = get_leaf();
85 if(im_a_leaf){
86 im_a_leaf->encode_item(info);
87 }
88 else { // It's a node. Do the node dance...
89 if(get_catalog_name() != BESCatalogList::TheCatalogList()->default_catalog_name())
90 props["name"] = BESUtil::assemblePath(get_catalog_name(), get_name(), true);
91 else
92 props["name"] = get_name();
93
94 // props["catalog"] = get_catalog_name();
95 props["lastModified"] = get_lmt();
96 ostringstream oss;
97 oss << get_item_count();
98 props["count"] = oss.str();
99
100 info->begin_tag("node", &props);
101
102 // Depth-first node traversal. Assume the nodes and leaves are sorted.
103 // Write the nodes first.
104 for (CatalogNode::item_citer i = nodes_begin(), e = nodes_end(); i != e; ++i) {
105 assert((*i)->get_type() == CatalogItem::node);
106 (*i)->encode_item(info);
107 }
108
109 // then leaves
110 for (CatalogNode::item_citer i = leaves_begin(), e = leaves_end(); i != e; ++i) {
111 assert((*i)->get_type() == CatalogItem::leaf);
112 (*i)->encode_item(info);
113 }
114 info->end_tag("node");
115 }
116}
117
118
123void CatalogNode::dump(ostream &strm) const
124{
125 strm << BESIndent::LMarg << "CatalogNode::dump - (" << (void *) this << ")" << endl;
126 BESIndent::Indent();
127
128 strm << BESIndent::LMarg << "name: " << d_name << endl;
129 strm << BESIndent::LMarg << "catalog_name: " << d_catalog_name << endl;
130 strm << BESIndent::LMarg << "last modified time: " << d_lmt<< endl;
131
132
133 if(d_no_really_im_a_leaf){
134 d_no_really_im_a_leaf->dump(strm);
135 }
136 else {
137
138 #if ITEMS
139 strm << BESIndent::LMarg << "item count: " << d_items.size() << endl;
140 #endif
141
142#if NODES_AND_LEAVES
143 strm << BESIndent::LMarg << "item count: " << d_nodes.size() + d_leaves.size() << endl;
144#endif
145
146 strm << BESIndent::LMarg << "items: ";
147 if (d_nodes.size() + d_leaves.size()) {
148 strm << endl;
149 BESIndent::Indent();
150#if ITEMS
151 vector<CatalogItem*>::const_iterator i = d_items.begin();
152 vector<CatalogItem*>::const_iterator e = d_items.end();
153 for (; i != e; ++i) {
154 strm << BESIndent::LMarg << (*i) << endl;
155 }
156#endif
157#if NODES_AND_LEAVES
158 vector<CatalogItem*>::const_iterator i = d_nodes.begin();
159 vector<CatalogItem*>::const_iterator e = d_nodes.end();
160 for (; i != e; ++i) {
161 strm << BESIndent::LMarg << (*i) << endl;
162 }
163
164 i = d_leaves.begin();
165 e = d_leaves.end();
166 for (; i != e; ++i) {
167 strm << BESIndent::LMarg << (*i) << endl;
168 }
169#endif
170 BESIndent::UnIndent();
171 }
172 }
173 BESIndent::UnIndent();
174}
informational response object
Definition BESInfo.h:63
static std::string assemblePath(const std::string &firstPart, const std::string &secondPart, bool leadingSlash=false, bool trailingSlash=false)
Assemble path fragments making sure that they are separated by a single '/' character.
Definition BESUtil.cc:804
void encode_item(BESInfo *info) const
Encode this CatalogItem in an info object.
std::string get_lmt() const
Get the last modified time for this node.
Definition CatalogNode.h:90
void encode_node(BESInfo *info)
Encode this CatalogNode in an info object.
std::string get_catalog_name() const
The name of the catalog.
Definition CatalogNode.h:85
virtual void dump(std::ostream &strm) const
std::string get_name() const
The name of this node in the catalog.
Definition CatalogNode.h:80
STL iterator class.