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 //#define DODS_DEBUG
36
37 #include "config.h"
38 #include "D4Group.h"
39 #include "Constructor.h"
40 #include "debug.h"
41
42 #include "TestStructure.h"
43
44 using namespace libdap;
45
m_duplicate(const TestStructure & ts)46 void TestStructure::m_duplicate(const TestStructure &ts)
47 {
48 d_series_values = ts.d_series_values;
49 }
50
51 BaseType *
ptr_duplicate()52 TestStructure::ptr_duplicate()
53 {
54 return new TestStructure(*this);
55 }
56
TestStructure(const TestStructure & rhs)57 TestStructure::TestStructure(const TestStructure &rhs) :
58 Structure(rhs), TestCommon(rhs)
59 {
60 m_duplicate(rhs);
61 }
62
63 TestStructure &
operator =(const TestStructure & rhs)64 TestStructure::operator=(const TestStructure &rhs)
65 {
66 if (this == &rhs) return *this;
67
68 dynamic_cast<Structure &>(*this) = rhs; // run Constructor=
69
70 m_duplicate(rhs);
71
72 return *this;
73 }
74
TestStructure(const string & n)75 TestStructure::TestStructure(const string &n) :
76 Structure(n), d_series_values(false)
77 {
78 }
79
TestStructure(const string & n,const string & d)80 TestStructure::TestStructure(const string &n, const string &d) :
81 Structure(n, d), d_series_values(false)
82 {
83 }
84
~TestStructure()85 TestStructure::~TestStructure()
86 {
87 }
88
output_values(std::ostream & out)89 void TestStructure::output_values(std::ostream &out)
90 {
91 out << "{ ";
92
93 bool value_written = false;
94 Vars_citer i = var_begin();
95
96 // Write the first (and maybe only) value.
97 while (i != var_end() && !value_written) {
98 if ((*i)->send_p()) {
99 (*i++)->print_val(out, "", false);
100 value_written = true;
101 }
102 else {
103 ++i;
104 }
105 }
106 // Each subsequent value will be preceded by a comma
107 while (i != var_end()) {
108 if ((*i)->send_p()) {
109 out << ", ";
110 (*i++)->print_val(out, "", false);
111 }
112 else {
113 ++i;
114 }
115 }
116
117 out << " }";
118 }
119
120 void
transform_to_dap4(D4Group * root,Constructor * container)121 TestStructure::transform_to_dap4(D4Group *root, Constructor *container)
122 {
123 TestStructure *dest = new TestStructure(name(), dataset());
124 Constructor::transform_to_dap4(root, dest);
125 container->add_var_nocopy(dest);
126 }
127
128 // For this `Test' class, run the read mfunc for each of variables which
129 // comprise the structure.
130
read()131 bool TestStructure::read()
132 {
133 if (read_p()) return true;
134
135 for (Vars_iter i = var_begin(); i != var_end(); i++) {
136 if (!(*i)->read()) {
137 return false;
138 }
139 }
140
141 set_read_p(true);
142
143 return true;
144 }
145
set_series_values(bool sv)146 void TestStructure::set_series_values(bool sv)
147 {
148 Vars_iter i = var_begin();
149 while (i != var_end()) {
150 dynamic_cast<TestCommon&>(*(*i)).set_series_values(sv);
151 ++i;
152 }
153
154 d_series_values = sv;
155 }
156