bes  Updated for version 3.20.5
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 BESDefinitionStorageVolatile::~BESDefinitionStorageVolatile()
38 {
40 }
41 
48 BESDefine *
50 {
51  Define_citer i;
52  i = _def_list.find(def_name);
53  if (i != _def_list.end()) {
54  return (*i).second;
55  }
56  return NULL;
57 }
58 
67 {
68  if (look_for(def_name) == NULL) {
69  _def_list[def_name] = d;
70  return true;
71  }
72  return false;
73 }
74 
84 {
85  bool ret = false;
86  Define_iter i;
87  i = _def_list.find(def_name);
88  if (i != _def_list.end()) {
89  BESDefine *d = (*i).second;
90  _def_list.erase(i);
91  delete d;
92  ret = true;
93  }
94  return ret;
95 }
96 
102 {
103  while (_def_list.size() != 0) {
104  Define_iter di = _def_list.begin();
105  BESDefine *d = (*di).second;
106  _def_list.erase(di);
107  if (d) {
108  delete d;
109  }
110  }
111  return true;
112 }
113 
125 {
126  map<string, string> dprops; // for the definition
127  map<string, string> cprops; // for the container
128  map<string, string> aprops; // for aggregation
129  Define_citer di = _def_list.begin();
130  Define_citer de = _def_list.end();
131  for (; di != de; di++) {
132  string def_name = (*di).first;
133  BESDefine *def = (*di).second;
134 
135  dprops.clear();
136  dprops["name"] = def_name;
137  info.begin_tag("definition", &dprops);
138 
139  BESDefine::containers_citer ci = def->first_container();
140  BESDefine::containers_citer ce = def->end_container();
141  for (; ci != ce; ci++) {
142  cprops.clear();
143 
144  string sym = (*ci)->get_symbolic_name();
145  cprops["name"] = sym;
146 
147  // FIXME: need to get rid of the root directory
148  string real = (*ci)->get_real_name();
149 
150  string type = (*ci)->get_container_type();
151  cprops["type"] = type;
152 
153  string con = (*ci)->get_constraint();
154  if (!con.empty()) {
155  cprops["constraint"] = con;
156  }
157 
158  string attrs = (*ci)->get_attributes();
159  if (!attrs.empty()) {
160  cprops["attributes"] = attrs;
161  }
162 
163  info.add_tag("container", real, &cprops);
164  }
165 
166  if (!def->get_agg_handler().empty()) {
167  aprops.clear();
168  aprops["handler"] = def->get_agg_handler();
169  info.add_tag("aggregation", def->get_agg_cmd(), &aprops);
170  }
171 
172  info.end_tag("definition");
173  }
174 }
175 
183 void BESDefinitionStorageVolatile::dump(ostream &strm) const
184 {
185  strm << BESIndent::LMarg << "BESDefinitionStorageVolatile::dump - (" << (void *) this << ")" << endl;
186  BESIndent::Indent();
187  strm << BESIndent::LMarg << "name: " << get_name() << endl;
188  if (_def_list.size()) {
189  strm << BESIndent::LMarg << "definitions:" << endl;
190  BESIndent::Indent();
191  Define_citer di = _def_list.begin();
192  Define_citer de = _def_list.end();
193  for (; di != de; di++) {
194  (*di).second->dump(strm);
195  }
196  BESIndent::UnIndent();
197  }
198  else {
199  strm << BESIndent::LMarg << "definitions: none" << endl;
200  }
201  BESIndent::UnIndent();
202 }
203 
BESDefinitionStorageVolatile::dump
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESDefinitionStorageVolatile.cc:183
BESDefinitionStorageVolatile::add_definition
virtual bool add_definition(const string &def_name, BESDefine *d)
adds a given definition to this volatile storage
Definition: BESDefinitionStorageVolatile.cc:66
BESDefinitionStorageVolatile::look_for
virtual BESDefine * look_for(const string &def_name)
looks for a definition in this volatile store with the given name
Definition: BESDefinitionStorageVolatile.cc:49
BESInfo
informational response object
Definition: BESInfo.h:68
BESDefinitionStorageVolatile::show_definitions
virtual void show_definitions(BESInfo &info)
show the definitions stored in this store
Definition: BESDefinitionStorageVolatile.cc:124
BESDefine
Definition: BESDefine.h:45
BESDefinitionStorage::get_name
virtual const string & get_name() const
retrieve the name of this persistent store
Definition: BESDefinitionStorage.h:84
BESDefinitionStorageVolatile::del_definition
virtual bool del_definition(const string &def_name)
deletes a defintion with the given name from this volatile store
Definition: BESDefinitionStorageVolatile.cc:83
BESDefinitionStorageVolatile::del_definitions
virtual bool del_definitions()
deletes all defintions from the definition store
Definition: BESDefinitionStorageVolatile.cc:101