1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
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 1995-1996,1999
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 TestGrid. See TestByte.
33 //
34 // jhrg 1/13/95
35 
36 #include "TestGrid.h"
37 #include "TestCommon.h"
38 
39 extern int test_variable_sleep_interval;
40 
41 void
_duplicate(const TestGrid & ts)42 TestGrid::_duplicate(const TestGrid &ts)
43 {
44     d_series_values = ts.d_series_values;
45 }
46 
47 BaseType *
ptr_duplicate()48 TestGrid::ptr_duplicate()
49 {
50     return new TestGrid(*this);
51 }
52 
TestGrid(const TestGrid & rhs)53 TestGrid::TestGrid(const TestGrid &rhs) : Grid(rhs), TestCommon(rhs)
54 {
55     _duplicate(rhs);
56 }
57 
58 void
output_values(std::ostream & out)59 TestGrid::output_values(std::ostream &out)
60 {
61     // value_written controls comma printing
62     bool value_written = false;
63     bool pyg = projection_yields_grid();
64     if (pyg)
65         out << "{  Array: " ;
66     else //if (components(true) > 1)
67         out << "{ " ;
68 
69     if (array_var()->send_p()) {
70         array_var()->print_val(out, "", false);
71         value_written = true;
72     }
73 
74     if (pyg) {
75         out << "  Maps: " ;
76         // No comma needed if the 'Maps:' separator is written out
77         value_written = false;
78     }
79 
80     Map_citer i = map_begin();
81     // Write the first (and maybe only) value.
82     while(i != map_end() && !value_written) {
83         if ((*i)->send_p()) {
84             (*i++)->print_val(out, "", false);
85             value_written = true;
86         }
87         else {
88             ++i;
89         }
90     }
91     // Each subsequent value will be preceded by a comma
92     while(i != map_end()) {
93         if ((*i)->send_p()) {
94             out << ", ";
95             (*i++)->print_val(out, "", false);
96         }
97         else {
98             ++i;
99         }
100     }
101 
102     //if (pyg || components(true) > 1)
103         out << " }" ;
104 }
105 
106 TestGrid &
operator =(const TestGrid & rhs)107 TestGrid::operator=(const TestGrid &rhs)
108 {
109     if (this == &rhs)
110 	return *this;
111 
112     dynamic_cast<Grid &>(*this) = rhs; // run Constructor=
113 
114     _duplicate(rhs);
115 
116     return *this;
117 }
118 
119 
TestGrid(const string & n)120 TestGrid::TestGrid(const string &n) : Grid(n), d_series_values(false)
121 {
122 }
123 
TestGrid(const string & n,const string & d)124 TestGrid::TestGrid(const string &n, const string &d)
125     : Grid(n, d), d_series_values(false)
126 {
127 }
128 
~TestGrid()129 TestGrid::~TestGrid()
130 {
131 }
132 
read()133 bool TestGrid::read()
134 {
135     if (read_p())
136         return true;
137 
138     get_array()->read();
139 
140     for (Map_iter i = map_begin(); i != map_end(); i++) {
141         if (!(*i)->read()) {
142             return false;
143         }
144     }
145 
146     set_read_p(true);
147 
148     return true;
149 }
150 
151 void
set_series_values(bool sv)152 TestGrid::set_series_values(bool sv)
153 {
154     Map_iter i = map_begin();
155     while (i != map_end()) {
156         dynamic_cast<TestCommon&>(*(*i)).set_series_values(sv);
157         ++i;
158     }
159 
160     dynamic_cast<TestCommon&>(*array_var()).set_series_values(sv);
161 
162     d_series_values = sv;
163 }
164