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 TestByte. See the comments in TestByte.h
33 // For each of the `variable classes' (e.g., Byte, ... Array, ... Grid) you
34 // *must* define a ctor, dtor, ptr_duplicate and read mfunc. In addition, you
35 // must edit the definition of New<class name> so that it creates the correct
36 // type of object. for example, edit NewByte() so that it creates and returns
37 // a TestByte pointer (see util.cc).
38 //
39 // jhrg 1/12/95
40 //
41 // NB: It is no longer true that you must subclass the Byte, ..., Grid
42 // classes in order to use the DAP. Those classes are no longer abstract. For
43 // many client-side uses, the classes will work just fine as they are. To
44 // build a server, it is still necessary to subclass and define a read()
45 // method for each of the data type classes. 01/22/03 jhrg
46 
47 #include "config.h"
48 
49 #ifdef HAVE_UNISTD_H
50 #include <unistd.h>
51 #endif
52 
53 #ifdef WIN32
54 #include <io.h>
55 #include <fcntl.h>
56 #include <process.h>
57 #endif
58 
59 #include "TestByte.h"
60 #include "debug.h"
61 
62 // The NewByte `helper function' creates a pointer to the a TestByte and
63 // returns that pointer. It takes the same arguments as the class's ctor. If
64 // any of the variable classes are subclassed (e.g., to make a new Byte like
65 // HDFByte) then the corresponding function here, and in the other class
66 // definition files, needs to be changed so that it creates an instance of
67 // the new (sub)class. Continuing the earlier example, that would mean that
68 // NewByte() would return a HDFByte, not a Byte.
69 //
70 // It is important that these function's names and return types do not change
71 // - they are called by the parser code (for the dds, at least) so if their
72 // names changes, that will break.
73 //
74 // The declarations for these functions (in util.h) should *not* need
75 // changing.
76 
77 extern int test_variable_sleep_interval;
78 
79 void
_duplicate(const TestByte & ts)80 TestByte::_duplicate(const TestByte &ts)
81 {
82     d_series_values = ts.d_series_values;
83 }
84 
TestByte(const string & n)85 TestByte::TestByte(const string &n) : Byte(n), d_series_values(false)
86 {
87 	// For some reason, d_buf was set to '23' in the version checked in on
88 	// 9/12/13, but that seems to break the EXPR regression tests and '255'
89 	// seems to be the correct value. Since '23' is an odd choice, I'm leaving
90 	// this comment as a reminder should this information be useful in the future.
91 	// jhrg 10/1/13
92     // d_buf = 23;
93 	d_buf = 255;
94 }
95 
TestByte(const string & n,const string & d)96 TestByte::TestByte(const string &n, const string &d)
97     : Byte(n, d), d_series_values(false)
98 {
99     // d_buf = 23;
100 	d_buf = 255;
101 }
102 
103 BaseType *
ptr_duplicate()104 TestByte::ptr_duplicate()
105 {
106     return new TestByte(*this);
107 }
108 
TestByte(const TestByte & rhs)109 TestByte::TestByte(const TestByte &rhs) : Byte(rhs), TestCommon(rhs)
110 {
111     _duplicate(rhs);
112 }
113 
114 TestByte &
operator =(const TestByte & rhs)115 TestByte::operator=(const TestByte &rhs)
116 {
117     if (this == &rhs)
118 	return *this;
119 
120     dynamic_cast<Byte &>(*this) = rhs; // run Constructor=
121 
122     _duplicate(rhs);
123 
124     return *this;
125 }
126 #if 1
127 void
output_values(std::ostream & out)128 TestByte::output_values(std::ostream &out)
129 {
130     // value is a method where each return value is a different type so we have
131     // to make calls to it from objects/methods where the type is statically
132     // known.
133     print_val(out, "", false);
134 }
135 #endif
136 
137 bool
read()138 TestByte::read()
139 {
140     DBG(cerr << "Entering TestByte::read for " << name() << endl);
141     if (read_p())
142 	return true;
143 
144     if (test_variable_sleep_interval > 0)
145 	sleep(test_variable_sleep_interval);
146 
147     if (get_series_values()) {
148          d_buf++;
149     }
150     else {
151         d_buf = 255;
152     }
153 
154     set_read_p(true);
155 
156     DBG(cerr << "In TestByte::read, _buf = " << (int)d_buf << endl);
157 
158     return true;
159 }
160