00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "config.h"
00038
00039 static char rcsid[] not_used =
00040 {"$Id: Int16.cc 16088 2007-03-28 21:42:19Z jimg $"
00041 };
00042
00043 #include <stdlib.h>
00044
00045 #include "Int16.h"
00046 #include "DDS.h"
00047 #include "util.h"
00048 #include "parser.h"
00049
00050 #include "Operators.h"
00051 #include "dods-limits.h"
00052 #include "debug.h"
00053 #include "InternalErr.h"
00054
00055
00056 using std::cerr;
00057 using std::endl;
00058
00059 Int16::Int16(const string &n) : BaseType(n, dods_int16_c, (xdrproc_t)XDR_INT16)
00060 {}
00061
00062 Int16::Int16(const Int16 ©_from) : BaseType(copy_from)
00063 {
00064 _buf = copy_from._buf;
00065 }
00066
00067 BaseType *
00068 Int16::ptr_duplicate()
00069 {
00070 return new Int16(*this);
00071 }
00072
00073 Int16 &
00074 Int16::operator=(const Int16 &rhs)
00075 {
00076 if (this == &rhs)
00077 return *this;
00078
00079 dynamic_cast<BaseType &>(*this) = rhs;
00080
00081 _buf = rhs._buf;
00082
00083 return *this;
00084 }
00085
00086 unsigned int
00087 Int16::width()
00088 {
00089 return sizeof(dods_int16);
00090 }
00091
00092 bool
00093 Int16::serialize(const string &dataset, ConstraintEvaluator &eval, DDS &dds,
00094 XDR *sink, bool ce_eval)
00095 {
00096 dds.timeout_on();
00097
00098 if (!read_p())
00099 read(dataset);
00100
00101 #if EVAL
00102 if (ce_eval && !eval.eval_selection(dds, dataset))
00103 return true;
00104 #endif
00105
00106 dds.timeout_off();
00107
00108 if (!XDR_INT16(sink, &_buf))
00109 throw Error("Network I/O Error. Could not send int 16 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00110
00111 return true;
00112 }
00113
00114 bool
00115 Int16::deserialize(XDR *source, DDS *, bool)
00116 {
00117 if (!XDR_INT16(source, &_buf))
00118 throw Error("Network I/O Error. Could not read int 16 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00119
00120 return false;
00121 }
00122
00123 unsigned int
00124 Int16::val2buf(void *val, bool)
00125 {
00126
00127
00128
00129
00130 if (!val)
00131 throw InternalErr(__FILE__, __LINE__,
00132 "The incoming pointer does not contain any data.");
00133
00134 _buf = *(dods_int16 *)val;
00135
00136 return width();
00137 }
00138
00139 unsigned int
00140 Int16::buf2val(void **val)
00141 {
00142
00143
00144 if (!val)
00145 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00146
00147 if (!*val)
00148 *val = new dods_int16;
00149
00150 *(dods_int16 *)*val = _buf;
00151
00152 return width();
00153 }
00154
00155 dods_int16
00156 Int16::value() const
00157 {
00158 return _buf;
00159 }
00160
00161 bool
00162 Int16::set_value(dods_int16 i)
00163 {
00164 _buf = i;
00165 set_read_p(true);
00166
00167 return true;
00168 }
00169
00170 void
00171 Int16::print_val(FILE *out, string space, bool print_decl_p)
00172 {
00173 if (print_decl_p) {
00174 print_decl(out, space, false);
00175 fprintf(out, " = %d;\n", _buf) ;
00176 }
00177 else
00178 fprintf(out, "%d", _buf) ;
00179 }
00180
00181 bool
00182 Int16::ops(BaseType *b, int op, const string &dataset)
00183 {
00184
00185
00186 if (!read_p() && !read(dataset)) {
00187
00188
00189
00190
00191
00192 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00193 }
00194
00195
00196 if (!b->read_p() && !b->read(dataset)) {
00197
00198
00199
00200
00201
00202 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00203 }
00204
00205 switch (b->type()) {
00206 case dods_byte_c:
00207 return rops<dods_int16, dods_byte, SUCmp<dods_int16, dods_byte> >
00208 (_buf, dynamic_cast<Byte *>(b)->_buf, op);
00209 case dods_int16_c:
00210 return rops<dods_int16, dods_int16, Cmp<dods_int16, dods_int16> >
00211 (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
00212 case dods_uint16_c:
00213 return rops<dods_int16, dods_uint16, SUCmp<dods_int16, dods_uint16> >
00214 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
00215 case dods_int32_c:
00216 return rops<dods_int16, dods_int32, Cmp<dods_int16, dods_int32> >
00217 (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
00218 case dods_uint32_c:
00219 return rops<dods_int16, dods_uint32, SUCmp<dods_int16, dods_uint32> >
00220 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
00221 case dods_float32_c:
00222 return rops<dods_int16, dods_float32, Cmp<dods_int16, dods_float32> >
00223 (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
00224 case dods_float64_c:
00225 return rops<dods_int16, dods_float64, Cmp<dods_int16, dods_float64> >
00226 (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
00227 default:
00228 return false;
00229 }
00230 }
00231
00240 void
00241 Int16::dump(ostream &strm) const
00242 {
00243 strm << DapIndent::LMarg << "Int16::dump - ("
00244 << (void *)this << ")" << endl ;
00245 DapIndent::Indent() ;
00246 BaseType::dump(strm) ;
00247 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00248 DapIndent::UnIndent() ;
00249 }
00250