bes  Updated for version 3.20.6
BESDefinitionStorageVolatile.cc
1 // BESDefinitionStorageVolatile.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
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 University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "BESDefinitionStorageVolatile.h"
34 #include "BESDefine.h"
35 #include "BESInfo.h"
36 
37 using std::endl;
38 using std::string;
39 using std::ostream;
40 
41 BESDefinitionStorageVolatile::~BESDefinitionStorageVolatile()
42 {
44 }
45 
52 BESDefine *
54 {
55  Define_citer i;
56  i = _def_list.find(def_name);
57  if (i != _def_list.end()) {
58  return (*i).second;
59  }
60  return NULL;
61 }
62 
71 {
72  if (look_for(def_name) == NULL) {
73  _def_list[def_name] = d;
74  return true;
75  }
76  return false;
77 }
78 
88 {
89  bool ret = false;
90  Define_iter i;
91  i = _def_list.find(def_name);
92  if (i != _def_list.end()) {
93  BESDefine *d = (*i).second;
94  _def_list.erase(i);
95  delete d;
96  ret = true;
97  }
98  return ret;
99 }
100 
106 {
107  while (_def_list.size() != 0) {
108  Define_iter di = _def_list.begin();
109  BESDefine *d = (*di).second;
110  _def_list.erase(di);
111  if (d) {
112  delete d;
113  }
114  }
115  return true;
116 }
117 
129 {
130  std::map<string, string> dprops; // for the definition
131  std::map<string, string> cprops; // for the container
132  std::map<string, string> aprops; // for aggregation
133  Define_citer di = _def_list.begin();
134  Define_citer de = _def_list.end();
135  for (; di != de; di++) {
136  string def_name = (*di).first;
137  BESDefine *def = (*di).second;
138 
139  dprops.clear();
140  dprops["name"] = def_name;
141  info.begin_tag("definition", &dprops);
142 
143  BESDefine::containers_citer ci = def->first_container();
144  BESDefine::containers_citer ce = def->end_container();
145  for (; ci != ce; ci++) {
146  cprops.clear();
147 
148  string sym = (*ci)->get_symbolic_name();
149  cprops["name"] = sym;
150 
151  // FIXME: need to get rid of the root directory
152  string real = (*ci)->get_real_name();
153 
154  string type = (*ci)->get_container_type();
155  cprops["type"] = type;
156 
157  string con = (*ci)->get_constraint();
158  if (!con.empty()) {
159  cprops["constraint"] = con;
160  }
161 
162  string attrs = (*ci)->get_attributes();
163  if (!attrs.empty()) {
164  cprops["attributes"] = attrs;
165  }
166 
167  info.add_tag("container", real, &cprops);
168  }
169 
170  if (!def->get_agg_handler().empty()) {
171  aprops.clear();
172  aprops["handler"] = def->get_agg_handler();
173  info.add_tag("aggregation", def->get_agg_cmd(), &aprops);
174  }
175 
176  info.end_tag("definition");
177  }
178 }
179 
187 void BESDefinitionStorageVolatile::dump(ostream &strm) const
188 {
189  strm << BESIndent::LMarg << "BESDefinitionStorageVolatile::dump - (" << (void *) this << ")" << endl;
190  BESIndent::Indent();
191  strm << BESIndent::LMarg << "name: " << get_name() << endl;
192  if (_def_list.size()) {
193  strm << BESIndent::LMarg << "definitions:" << endl;
194  BESIndent::Indent();
195  Define_citer di = _def_list.begin();
196  Define_citer de = _def_list.end();
197  for (; di != de; di++) {
198  (*di).second->dump(strm);
199  }
200  BESIndent::UnIndent();
201  }
202  else {
203  strm << BESIndent::LMarg << "definitions: none" << endl;
204  }
205  BESIndent::UnIndent();
206 }
207 
BESDefinitionStorageVolatile::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESDefinitionStorageVolatile.cc:187
BESDefinitionStorage::get_name
virtual const std::string & get_name() const
retrieve the name of this persistent store
Definition: BESDefinitionStorage.h:82
BESDefinitionStorageVolatile::look_for
virtual BESDefine * look_for(const std::string &def_name)
looks for a definition in this volatile store with the given name
Definition: BESDefinitionStorageVolatile.cc:53
BESInfo
informational response object
Definition: BESInfo.h:63
BESDefinitionStorageVolatile::show_definitions
virtual void show_definitions(BESInfo &info)
show the definitions stored in this store
Definition: BESDefinitionStorageVolatile.cc:128
BESDefinitionStorageVolatile::del_definition
virtual bool del_definition(const std::string &def_name)
deletes a defintion with the given name from this volatile store
Definition: BESDefinitionStorageVolatile.cc:87
BESDefinitionStorageVolatile::add_definition
virtual bool add_definition(const std::string &def_name, BESDefine *d)
adds a given definition to this volatile storage
Definition: BESDefinitionStorageVolatile.cc:70
BESDefine
Definition: BESDefine.h:42
BESDefinitionStorageVolatile::del_definitions
virtual bool del_definitions()
deletes all defintions from the definition store
Definition: BESDefinitionStorageVolatile.cc:105