OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESDefinitionStorageVolatile.cc
Go to the documentation of this file.
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 
34 #include "BESDefine.h"
35 #include "BESInfo.h"
36 
38 {
39  del_definitions() ;
40 }
41 
48 BESDefine *
49 BESDefinitionStorageVolatile::look_for( const string &def_name )
50 {
51  Define_citer i ;
52  i = _def_list.find( def_name ) ;
53  if( i != _def_list.end() )
54  {
55  return (*i).second;
56  }
57  return NULL ;
58 }
59 
67 bool
69  BESDefine *d )
70 {
71  if( look_for( def_name ) == NULL )
72  {
73  _def_list[def_name] = d ;
74  return true ;
75  }
76  return false ;
77 }
78 
87 bool
89 {
90  bool ret = false ;
91  Define_iter i ;
92  i = _def_list.find( def_name ) ;
93  if( i != _def_list.end() )
94  {
95  BESDefine *d = (*i).second;
96  _def_list.erase( i ) ;
97  delete d ;
98  ret = true ;
99  }
100  return ret ;
101 }
102 
107 bool
109 {
110  while( _def_list.size() != 0 )
111  {
112  Define_iter di = _def_list.begin() ;
113  BESDefine *d = (*di).second ;
114  _def_list.erase( di ) ;
115  if( d )
116  {
117  delete d ;
118  }
119  }
120  return true ;
121 }
122 
133 void
135 {
136  map<string,string> dprops ; // for the definition
137  map<string,string> cprops ; // for the container
138  map<string,string> aprops ; // for aggregation
139  Define_citer di = _def_list.begin() ;
140  Define_citer de = _def_list.end() ;
141  for( ; di != de; di++ )
142  {
143  string def_name = (*di).first ;
144  BESDefine *def = (*di).second ;
145 
146  dprops.clear() ;
147  dprops["name"] = def_name ;
148  info.begin_tag( "definition", &dprops ) ;
149 
152  for( ; ci != ce; ci++ )
153  {
154  cprops.clear() ;
155  string sym = (*ci)->get_symbolic_name() ;
156  cprops["name"] = sym ;
157  // FIXME: need to get rid of the root directory
158  string real = (*ci)->get_real_name() ;
159  string type = (*ci)->get_container_type() ;
160  cprops["type"] = type ;
161  string con = (*ci)->get_constraint() ;
162  if( !con.empty() )
163  {
164  cprops["constraint"] = con ;
165  }
166  string attrs = (*ci)->get_attributes() ;
167  if( !attrs.empty() )
168  {
169  cprops["attributes"] = attrs ;
170  }
171  info.add_tag( "container", real, &cprops ) ;
172  }
173 
174  if( !def->get_agg_handler().empty() )
175  {
176  aprops.clear() ;
177  aprops["handler"] = def->get_agg_handler() ;
178  info.add_tag( "aggregation", def->get_agg_cmd(), &aprops ) ;
179  }
180 
181  info.end_tag( "definition" ) ;
182  }
183 }
184 
192 void
194 {
195  strm << BESIndent::LMarg << "BESDefinitionStorageVolatile::dump - ("
196  << (void *)this << ")" << endl ;
198  strm << BESIndent::LMarg << "name: " << get_name() << endl ;
199  if( _def_list.size() )
200  {
201  strm << BESIndent::LMarg << "definitions:" << endl ;
203  Define_citer di = _def_list.begin() ;
204  Define_citer de = _def_list.end() ;
205  for( ; di != de; di++ )
206  {
207  (*di).second->dump( strm ) ;
208  }
210  }
211  else
212  {
213  strm << BESIndent::LMarg << "definitions: none" << endl ;
214  }
216 }
217 
virtual bool add_definition(const string &def_name, BESDefine *d)
adds a given definition to this volatile storage
virtual BESDefine * look_for(const string &def_name)
looks for a definition in this volatile store with the given name
virtual bool del_definition(const string &def_name)
deletes a defintion with the given name from this volatile store
virtual void add_tag(const string &tag_name, const string &tag_data, map< string, string > *attrs=0)=0
const string & get_agg_cmd()
Definition: BESDefine.h:66
static void Indent()
Definition: BESIndent.cc:38
BESDefine::containers_citer end_container()
Definition: BESDefine.h:60
informational response object
Definition: BESInfo.h:68
virtual void show_definitions(BESInfo &info)
show the defintions stored in this store
virtual const string & get_name() const
retrieve the name of this persistent store
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
Definition: BESInfo.cc:142
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual void dump(ostream &strm) const
dumps information about this object
BESDefine::containers_citer first_container()
Definition: BESDefine.h:59
virtual bool del_definitions()
deletes all defintions from the definition store
list< BESContainer * >::const_iterator containers_citer
Definition: BESDefine.h:56
const string & get_agg_handler()
Definition: BESDefine.h:74
static void UnIndent()
Definition: BESIndent.cc:44
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:149