bes  Updated for version 3.20.6
AsciiOutput.cc
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 AsciiByte. See the comments in AsciiByte.h
33 //
34 // 3/12/98 jhrg
35 
36 #include "config.h"
37 
38 #include <algorithm>
39 #include <iostream>
40 
41 #include "BaseType.h"
42 #include "debug.h"
43 
44 #include "AsciiOutput.h"
45 #include "get_ascii.h"
46 
47 using namespace dap_asciival;
48 
50 {
51  BaseType *this_btp = dynamic_cast < BaseType * >(this);
52  if (!this_btp)
53  throw InternalErr(__FILE__, __LINE__,
54  "Instance of AsciiOuput must also be a BaseType.");
55  BaseType *btp = _redirect;
56  if (!btp)
57  btp = this_btp;
58 
59  BaseType *btp2 = this_btp->get_parent();
60  if (!btp2)
61  return btp->name(); // Must be top-level node/variable.
62  else
63  return dynamic_cast < AsciiOutput * >(btp2)->get_full_name()
64  + "." + btp->name();
65 }
66 
73 void AsciiOutput::print_ascii(ostream &strm,
74  bool print_name) throw(InternalErr)
75 {
76  BaseType *BTptr = _redirect;
77  if (!BTptr) {
78  BTptr = dynamic_cast < BaseType * >(this);
79  }
80 
81  if (!BTptr)
82  throw InternalErr(__FILE__, __LINE__,
83  "An instance of AsciiOutput failed to cast to BaseType.");
84 
85  if (print_name)
86  strm << get_full_name() << ", " ;
87 
88  BTptr->print_val(strm, "", false);
89 }
90 
91 // This code implements simple modulo arithmetic. The vector shape contains
92 // the maximum count value for each dimension, state contains the current
93 // state. For example, if shape holds 10, 20 then when state holds 0, 20
94 // calling this method will increment state to 1, 0. For this example,
95 // calling the method with state equal to 10, 20 will reset state to 0, 0 and
96 // the return value will be false.
97 bool AsciiOutput::increment_state(vector < int >*state,
98  const vector < int >&shape)
99 {
100  DBG(cerr << "Entering increment_state" << endl);
101 
102  vector < int >::reverse_iterator state_riter;
103  vector < int >::const_reverse_iterator shape_riter;
104  for (state_riter = state->rbegin(), shape_riter = shape.rbegin();
105  state_riter < state->rend(); state_riter++, shape_riter++) {
106  if (*state_riter == *shape_riter - 1) {
107  *state_riter = 0;
108  } else {
109  *state_riter = *state_riter + 1;
110 
111  DBG(cerr << "Returning state:";
112  for_each(state->begin(), state->end(), print < int >);
113  cerr << endl);
114 
115  return true;
116  }
117  }
118 
119  DBG(cerr << "Returning state without change:";
120  for_each(state->begin(), state->end(), print < int >);
121  cerr << endl);
122 
123  return false;
124 }
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::increment_state
bool increment_state(vector< int > *state, const vector< int > &shape)
Definition: AsciiOutput.cc:97
AsciiOutput
Definition: AsciiOutput.h:46
AsciiOutput::get_full_name
string get_full_name()
Definition: AsciiOutput.cc:49