bes  Updated for version 3.20.6
AsciiStructure.cc
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of asciival, software which can return an ASCII
4 // representation of the data read from a DAP server.
5 
6 // Copyright (c) 2002,2003 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
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 OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 // (c) COPYRIGHT URI/MIT 1998,2000
26 // Please read the full copyright statement in the file COPYRIGHT_URI.
27 //
28 // Authors:
29 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
30 
31 // Implementation for the class AsciiStructure. See AsciiByte.cc
32 //
33 // 3/12/98 jhrg
34 
35 #include "config.h"
36 
37 #include <string>
38 
39 #include <BESDebug.h>
40 
41 #include "InternalErr.h"
42 #include "D4Group.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 *
51 AsciiStructure::ptr_duplicate()
52 {
53  return new AsciiStructure(*this);
54 }
55 
56 AsciiStructure::AsciiStructure(const string &n) :
57  Structure(n)
58 {
59 }
60 
61 AsciiStructure::AsciiStructure(Structure *bt) :
62  Structure(bt->name()), AsciiOutput(bt)
63 {
64  // Let's make the alternative structure of Ascii types now so that we
65  // don't have to do it on the fly. This will also set the parents of
66  // each of the underlying vars of the structure.
67  Vars_iter p = bt->var_begin();
68  while (p != bt->var_end()) {
69  BaseType *new_bt = basetype_to_asciitype(*p);
70  add_var(new_bt);
71  // add_var makes a copy of the base type passed to it, so delete
72  // it here
73  delete new_bt;
74  p++;
75  }
76 
77  BaseType::set_send_p(bt->send_p());
78 }
79 
80 AsciiStructure::~AsciiStructure()
81 {
82 }
83 
84 void AsciiStructure::transform_to_dap4(D4Group *root, Constructor *container){
85  cerr << __func__ << "() -BEGIN " <<
86  "('"<< root->name() << "':"<< (void *)root << ")" <<
87  "('"<< container->name() << "':"<< (void *)container << ")" <<
88  endl;
89  AsciiStructure *dest = new AsciiStructure(name());
90  Constructor::transform_to_dap4(root,dest);
91  container->add_var_nocopy(dest);
92  cerr << __func__ << "() - END" << endl;
93 }
94 
95 void AsciiStructure::print_header(ostream &strm)
96 {
97  Vars_iter p = var_begin();
98  while (p != var_end()) {
99  if ((*p)->is_simple_type())
100  strm << dynamic_cast<AsciiOutput&>(**p).get_full_name();
101  else if ((*p)->type() == dods_structure_c)
102  dynamic_cast<AsciiStructure&>(**p).print_header(strm);
103  // May need a case here for Sequence 2/18/2002 jhrg
104  // Yes, we do, and for Grid as well. 04/04/03 jhrg
105  else
106  throw InternalErr(__FILE__, __LINE__,
107  "Support for ASCII output of datasets with structures which contain Sequences or Grids has not been completed.");
108  if (++p != var_end()) strm << ", ";
109  }
110 }
111 
112 void AsciiStructure::print_ascii(ostream &strm, bool print_name) throw (InternalErr)
113 {
114  BESDEBUG("ascii", "In 'AsciiStructure::print_ascii'" << endl);
115 
116  if (is_linear()) {
117  if (print_name) {
118  print_header(strm);
119  strm << "\n";
120  }
121 
122  Vars_iter p = var_begin();
123  while (p != var_end()) {
124  if ((*p)->send_p()) dynamic_cast<AsciiOutput &>(**p).print_ascii(strm, false);
125 
126  if (++p != var_end()) strm << ", ";
127  }
128  }
129  else {
130  for (Vars_iter p = var_begin(); p != var_end(); ++p) {
131  if ((*p)->send_p()) {
132  dynamic_cast<AsciiOutput&>(**p).print_ascii(strm, true);
133  // This line outputs an extra endl when print_ascii is called for
134  // nested structures because an endl is written for each member
135  // and then once for the structure itself. 9/14/2001 jhrg
136  strm << "\n";
137  }
138  }
139  }
140 }
141 
AsciiStructure::print_ascii
virtual void print_ascii(ostream &strm, bool print_name=true)
Print values as ASCII Prints the values of this in ASCII suitable for import into a spreadsheet....
Definition: AsciiStructure.cc:112
AsciiStructure
Definition: AsciiStructure.h:42
AsciiOutput::print_ascii
virtual void print_ascii(ostream &strm, bool print_name=true)
Print values as ASCII Prints the values of this in ASCII suitable for import into a spreadsheet....
Definition: AsciiOutput.cc:73
AsciiOutput
Definition: AsciiOutput.h:46