Blame tests/TestByte.cc

Packit a4aae4
Packit a4aae4
// -*- mode: c++; c-basic-offset:4 -*-
Packit a4aae4
Packit a4aae4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
Packit a4aae4
// Access Protocol.
Packit a4aae4
Packit a4aae4
// Copyright (c) 2002,2003 OPeNDAP, Inc.
Packit a4aae4
// Author: James Gallagher <jgallagher@opendap.org>
Packit a4aae4
//
Packit a4aae4
// This library is free software; you can redistribute it and/or
Packit a4aae4
// modify it under the terms of the GNU Lesser General Public
Packit a4aae4
// License as published by the Free Software Foundation; either
Packit a4aae4
// version 2.1 of the License, or (at your option) any later version.
Packit a4aae4
//
Packit a4aae4
// This library is distributed in the hope that it will be useful,
Packit a4aae4
// but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4aae4
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4aae4
// Lesser General Public License for more details.
Packit a4aae4
//
Packit a4aae4
// You should have received a copy of the GNU Lesser General Public
Packit a4aae4
// License along with this library; if not, write to the Free Software
Packit a4aae4
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit a4aae4
//
Packit a4aae4
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
Packit a4aae4
Packit a4aae4
// (c) COPYRIGHT URI/MIT 1995-1996,1999
Packit a4aae4
// Please read the full copyright statement in the file COPYRIGHT_URI.
Packit a4aae4
//
Packit a4aae4
// Authors:
Packit a4aae4
//      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>
Packit a4aae4
Packit a4aae4
// Implementation for TestByte. See the comments in TestByte.h
Packit a4aae4
// For each of the `variable classes' (e.g., Byte, ... Array, ... Grid) you
Packit a4aae4
// *must* define a ctor, dtor, ptr_duplicate and read mfunc. In addition, you
Packit a4aae4
// must edit the definition of New<class name> so that it creates the correct
Packit a4aae4
// type of object. for example, edit NewByte() so that it creates and returns
Packit a4aae4
// a TestByte pointer (see util.cc).
Packit a4aae4
//
Packit a4aae4
// jhrg 1/12/95
Packit a4aae4
//
Packit a4aae4
// NB: It is no longer true that you must subclass the Byte, ..., Grid
Packit a4aae4
// classes in order to use the DAP. Those classes are no longer abstract. For
Packit a4aae4
// many client-side uses, the classes will work just fine as they are. To
Packit a4aae4
// build a server, it is still necessary to subclass and define a read()
Packit a4aae4
// method for each of the data type classes. 01/22/03 jhrg
Packit a4aae4
Packit a4aae4
#include "config.h"
Packit a4aae4
Packit a4aae4
#ifdef HAVE_UNISTD_H
Packit a4aae4
#include <unistd.h>
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#ifdef WIN32
Packit a4aae4
#include <io.h>
Packit a4aae4
#include <fcntl.h>
Packit a4aae4
#include <process.h>
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
#include "TestByte.h"
Packit a4aae4
#include "debug.h"
Packit a4aae4
Packit a4aae4
// The NewByte `helper function' creates a pointer to the a TestByte and
Packit a4aae4
// returns that pointer. It takes the same arguments as the class's ctor. If
Packit a4aae4
// any of the variable classes are subclassed (e.g., to make a new Byte like
Packit a4aae4
// HDFByte) then the corresponding function here, and in the other class
Packit a4aae4
// definition files, needs to be changed so that it creates an instance of
Packit a4aae4
// the new (sub)class. Continuing the earlier example, that would mean that
Packit a4aae4
// NewByte() would return a HDFByte, not a Byte.
Packit a4aae4
//
Packit a4aae4
// It is important that these function's names and return types do not change
Packit a4aae4
// - they are called by the parser code (for the dds, at least) so if their
Packit a4aae4
// names changes, that will break.
Packit a4aae4
//
Packit a4aae4
// The declarations for these functions (in util.h) should *not* need
Packit a4aae4
// changing.
Packit a4aae4
Packit a4aae4
extern int test_variable_sleep_interval;
Packit a4aae4
Packit a4aae4
void
Packit a4aae4
TestByte::_duplicate(const TestByte &ts)
Packit a4aae4
{
Packit a4aae4
    d_series_values = ts.d_series_values;
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
TestByte::TestByte(const string &n) : Byte(n), d_series_values(false)
Packit a4aae4
{
Packit a4aae4
	// For some reason, d_buf was set to '23' in the version checked in on
Packit a4aae4
	// 9/12/13, but that seems to break the EXPR regression tests and '255'
Packit a4aae4
	// seems to be the correct value. Since '23' is an odd choice, I'm leaving
Packit a4aae4
	// this comment as a reminder should this information be useful in the future.
Packit a4aae4
	// jhrg 10/1/13
Packit a4aae4
    // d_buf = 23;
Packit a4aae4
	d_buf = 255;
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
TestByte::TestByte(const string &n, const string &d)
Packit a4aae4
    : Byte(n, d), d_series_values(false)
Packit a4aae4
{
Packit a4aae4
    // d_buf = 23;
Packit a4aae4
	d_buf = 255;
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
BaseType *
Packit a4aae4
TestByte::ptr_duplicate()
Packit a4aae4
{
Packit a4aae4
    return new TestByte(*this);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
TestByte::TestByte(const TestByte &rhs) : Byte(rhs), TestCommon(rhs)
Packit a4aae4
{
Packit a4aae4
    _duplicate(rhs);
Packit a4aae4
}
Packit a4aae4
Packit a4aae4
TestByte &
Packit a4aae4
TestByte::operator=(const TestByte &rhs)
Packit a4aae4
{
Packit a4aae4
    if (this == &rhs)
Packit a4aae4
	return *this;
Packit a4aae4
Packit a4aae4
    dynamic_cast<Byte &>(*this) = rhs; // run Constructor=
Packit a4aae4
Packit a4aae4
    _duplicate(rhs);
Packit a4aae4
Packit a4aae4
    return *this;
Packit a4aae4
}
Packit a4aae4
#if 1
Packit a4aae4
void
Packit a4aae4
TestByte::output_values(std::ostream &out)
Packit a4aae4
{
Packit a4aae4
    // value is a method where each return value is a different type so we have
Packit a4aae4
    // to make calls to it from objects/methods where the type is statically
Packit a4aae4
    // known.
Packit a4aae4
    print_val(out, "", false);
Packit a4aae4
}
Packit a4aae4
#endif
Packit a4aae4
Packit a4aae4
bool
Packit a4aae4
TestByte::read()
Packit a4aae4
{
Packit a4aae4
    DBG(cerr << "Entering TestByte::read for " << name() << endl);
Packit a4aae4
    if (read_p())
Packit a4aae4
	return true;
Packit a4aae4
Packit a4aae4
    if (test_variable_sleep_interval > 0)
Packit a4aae4
	sleep(test_variable_sleep_interval);
Packit a4aae4
Packit a4aae4
    if (get_series_values()) {
Packit a4aae4
         d_buf++;
Packit a4aae4
    }
Packit a4aae4
    else {
Packit a4aae4
        d_buf = 255;
Packit a4aae4
    }
Packit a4aae4
Packit a4aae4
    set_read_p(true);
Packit a4aae4
Packit a4aae4
    DBG(cerr << "In TestByte::read, _buf = " << (int)d_buf << endl);
Packit a4aae4
Packit a4aae4
    return true;
Packit a4aae4
}