OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
AsciiOutput.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 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  BaseType *btp = _redirect;
53  if (!btp)
54  btp = this_btp;
55  if (!btp)
56  throw InternalErr(__FILE__, __LINE__,
57  "Instance of AsciiOuput must also be a BaseType.");
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 // This code implements simple modulo arithmetic. The vector shape contains
93 // the maximum count value for each dimension, state contains the current
94 // state. For example, if shape holds 10, 20 then when state holds 0, 20
95 // calling this method will increment state to 1, 0. For this example,
96 // calling the method with state equal to 10, 20 will reset state to 0, 0 and
97 // the return value will be false.
98 bool AsciiOutput::increment_state(vector < int >*state,
99  const vector < int >&shape)
100 {
101 
102  DBG(cerr << "Entering increment_state" << endl);
103 
104  vector < int >::reverse_iterator state_riter;
105  vector < int >::const_reverse_iterator shape_riter;
106  for (state_riter = state->rbegin(), shape_riter = shape.rbegin();
107  state_riter < state->rend(); state_riter++, shape_riter++) {
108  if (*state_riter == *shape_riter - 1) {
109  *state_riter = 0;
110  } else {
111  *state_riter = *state_riter + 1;
112 
113  DBG(cerr << "Returning state:";
114  for_each(state->begin(), state->end(), print < int >);
115  cerr << endl);
116 
117  return true;
118  }
119  }
120 
121  DBG(cerr << "Returning state without change:";
122  for_each(state->begin(), state->end(), print < int >);
123  cerr << endl);
124 
125  return false;
126 }
bool increment_state(vector< int > *state, const vector< int > &shape)
Increment #state# to the next value given #shape#.
Definition: AsciiOutput.cc:98
virtual void print_ascii(ostream &strm, bool print_name=true)
Print an ASCII representation for an instance of BaseType's children.
Definition: AsciiOutput.cc:73
string get_full_name()
Get the fully qualified name of this object.
Definition: AsciiOutput.cc:49