OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
AsciiStructure.cc
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of asciival, software which can return an ASCII
5 // representation of the data read from a DAP server.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1998,2000
27 // Please read the full copyright statement in the file COPYRIGHT_URI.
28 //
29 // Authors:
30 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31 
32 // Implementation for the class AsciiStructure. See AsciiByte.cc
33 //
34 // 3/12/98 jhrg
35 
36 #include "config.h"
37 
38 #include <string>
39 
40 #include <BESDebug.h>
41 
42 #include "InternalErr.h"
43 #include "AsciiStructure.h"
44 #include "AsciiSequence.h"
45 //#include "name_map.h"
46 #include "get_ascii.h"
47 
48 using namespace dap_asciival;
49 
50 BaseType *
52 {
53  return new AsciiStructure(*this);
54 }
55 
56 AsciiStructure::AsciiStructure(const string &n) : Structure(n)
57 {
58 }
59 
61  : Structure( bt->name() ), AsciiOutput( bt )
62 {
63  // Let's make the alternative structure of Ascii types now so that we
64  // don't have to do it on the fly. This will also set the parents of
65  // each of the underlying vars of the structure.
66  Vars_iter p = bt->var_begin();
67  while (p != bt->var_end()) {
68  BaseType *new_bt = basetype_to_asciitype(*p);
69  add_var(new_bt);
70  // add_var makes a copy of the base type passed to it, so delete
71  // it here
72  delete new_bt;
73  p++;
74  }
75 
76  BaseType::set_send_p(bt->send_p());
77 }
78 
80 {
81 }
82 
83 void
85 {
86  Vars_iter p = var_begin();
87  while (p != var_end()) {
88  if ((*p)->is_simple_type())
89  strm << dynamic_cast<AsciiOutput*>(*p)->get_full_name() ;
90  else if ((*p)->type() == dods_structure_c)
91  dynamic_cast<AsciiStructure*>((*p))->print_header(strm);
92  // May need a case here for Sequence 2/18/2002 jhrg
93  // Yes, we do, and for Grid as well. 04/04/03 jhrg
94  else
95  throw InternalErr(__FILE__, __LINE__,
96  "Support for ASCII output of datasets with structures which contain Sequences or Grids has not been completed.");
97  if (++p != var_end())
98  strm << ", " ;
99  }
100 }
101 
102 void
103 AsciiStructure::print_ascii(ostream &strm, bool print_name) throw(InternalErr)
104 {
105  BESDEBUG("ascii", "In 'AsciiStructure::print_ascii'" << endl);
106 
107  if (is_linear()) {
108  if (print_name) {
109  print_header(strm);
110  strm << "\n" ;
111  }
112 
113  Vars_iter p = var_begin();
114  while (p != var_end()) {
115  if ((*p)->send_p())
116  dynamic_cast<AsciiOutput*> ((*p))->print_ascii(strm, false);
117 
118  if (++p != var_end())
119  strm << ", ";
120  }
121  }
122  else {
123  for (Vars_iter p = var_begin(); p != var_end(); ++p) {
124  if ((*p)->send_p()) {
125  dynamic_cast<AsciiOutput*> ((*p))->print_ascii(strm, true);
126  // This line outputs an extra endl when print_ascii is called for
127  // nested structures because an endl is written for each member
128  // and then once for the structure itself. 9/14/2001 jhrg
129  strm << "\n";
130  }
131  }
132  }
133 }
134 
virtual BaseType * ptr_duplicate()
BaseType * basetype_to_asciitype(BaseType *bt)
Definition: get_ascii.cc:116
AsciiStructure(const string &n)
virtual ~AsciiStructure()
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
virtual void print_header(ostream &strm)
virtual void print_ascii(ostream &strm, bool print_name=true)
Print an ASCII representation for an instance of BaseType's children.