1 // -*- mode: c++; c-basic-offset:4 -*-
2
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
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 1995-1999
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 TestStructure. See TestByte.cc
32 //
33 // jhrg 1/12/95
34 //
35 // Note that the test code here to read values from a data file works only
36 // for single level sequences - that is, it does *not* work for sequences
37 // that contain other sequences. jhrg 2/2/98
38
39 //#define DODS_DEBUG
40
41 #include "config.h"
42 #include "D4Group.h"
43 #include "Constructor.h"
44 #include "D4Sequence.h"
45 #include "debug.h"
46
47 #include "TestSequence.h"
48 #include "TestD4Sequence.h"
49 #include "TestCommon.h"
50
51 using namespace libdap;
52
_duplicate(const TestSequence & ts)53 void TestSequence::_duplicate(const TestSequence &ts)
54 {
55 d_current = ts.d_current;
56 d_len = ts.d_len;
57 d_series_values = ts.d_series_values;
58 }
59
60 BaseType *
ptr_duplicate()61 TestSequence::ptr_duplicate()
62 {
63 return new TestSequence(*this);
64 }
65
TestSequence(const string & n)66 TestSequence::TestSequence(const string &n) :
67 Sequence(n), d_len(4), d_current(0), d_series_values(false)
68 {
69 }
70
TestSequence(const string & n,const string & d)71 TestSequence::TestSequence(const string &n, const string &d) :
72 Sequence(n, d), d_len(4), d_current(0), d_series_values(false)
73 {
74 }
75
TestSequence(const TestSequence & rhs)76 TestSequence::TestSequence(const TestSequence &rhs) :
77 Sequence(rhs), TestCommon(rhs)
78 {
79 _duplicate(rhs);
80 }
81
~TestSequence()82 TestSequence::~TestSequence()
83 {
84 }
85
86 TestSequence &
operator =(const TestSequence & rhs)87 TestSequence::operator=(const TestSequence &rhs)
88 {
89 if (this == &rhs) return *this;
90
91 dynamic_cast<Sequence &>(*this) = rhs; // run Constructor=
92
93 _duplicate(rhs);
94
95 return *this;
96 }
97
98 void
transform_to_dap4(D4Group * root,Constructor * container)99 TestSequence::transform_to_dap4(D4Group *root, Constructor *container)
100 {
101 TestD4Sequence *dest = new TestD4Sequence(name());
102 Constructor::transform_to_dap4(root, dest);
103 container->add_var_nocopy(dest);
104 }
105
output_values(std::ostream & out)106 void TestSequence::output_values(std::ostream &out)
107 {
108 print_val(out, "", false);
109 }
110
111 // Read values from text files. Sequence instances are stored on separate
112 // lines. Line can be no more than 255 characters long.
113
read()114 bool TestSequence::read()
115 {
116 DBG(cerr << "Entering TestSequence::read for " << name() << endl);
117
118 if (read_p()) return true;
119
120 DBG(cerr << "current: " << d_current << ", length: " << d_len << endl);
121 // When we get to the end of a Sequence, reset the row number counter so
122 // that, in case this is an inner sequence, the next instance will be read
123 // and the "Trying to back up in a Sequence" error won't be generated.
124 if (++d_current > d_len) {
125 DBG(cerr << "Leaving TestSequence::read for " << name()
126 << " because d_current(" << d_current
127 << ") > d_len(" << d_len << ")" << endl);
128 d_current = 0; // reset
129 set_unsent_data(false);
130 reset_row_number();
131 // jhrg original version from 10/9/13: return false; // No more values
132 return true;
133 }
134
135 Vars_iter i = var_begin();
136 while (i != var_end()) {
137 if ((*i)->send_p() || (*i)->is_in_selection()) {
138 DBG(cerr << "Calling " << (*i)->name() << "->read()" << endl);
139 (*i)->read();
140 }
141 ++i;
142 }
143
144 set_unsent_data(true);
145 DBG(cerr << "Leaving TestSequence::read for " << name() << endl);
146 return false;
147 }
148
set_series_values(bool sv)149 void TestSequence::set_series_values(bool sv)
150 {
151 Vars_iter i = var_begin();
152 while (i != var_end()) {
153 dynamic_cast<TestCommon&>(*(*i)).set_series_values(sv);
154 ++i;
155 }
156
157 d_series_values = sv;
158 }
159
length() const160 int TestSequence::length() const
161 {
162 return 5;
163 }
164