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: Int32.cc 16088 2007-03-28 21:42:19Z jimg $"
00041 };
00042
00043 #include <stdlib.h>
00044
00045 #include "Int32.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
00066 Int32::Int32(const string &n)
00067 : BaseType(n, dods_int32_c, (xdrproc_t)XDR_INT32)
00068 {}
00069
00070 Int32::Int32(const Int32 ©_from) : BaseType(copy_from)
00071 {
00072 _buf = copy_from._buf;
00073 }
00074
00075 BaseType *
00076 Int32::ptr_duplicate()
00077 {
00078 return new Int32(*this);
00079 }
00080
00081 Int32::~Int32()
00082 {
00083 DBG(cerr << "~Int32" << endl);
00084 }
00085
00086 Int32 &
00087 Int32::operator=(const Int32 &rhs)
00088 {
00089 if (this == &rhs)
00090 return *this;
00091
00092 dynamic_cast<BaseType &>(*this) = rhs;
00093
00094 _buf = rhs._buf;
00095
00096 return *this;
00097 }
00098
00099 unsigned int
00100 Int32::width()
00101 {
00102 return sizeof(dods_int32);
00103 }
00104
00105 bool
00106 Int32::serialize(const string &dataset, ConstraintEvaluator &eval, DDS &dds,
00107 XDR *sink, bool ce_eval)
00108 {
00109 dds.timeout_on();
00110
00111 if (!read_p())
00112 read(dataset);
00113
00114 #if EVAL
00115 if (ce_eval && !eval.eval_selection(dds, dataset))
00116 return true;
00117 #endif
00118
00119 dds.timeout_off();
00120
00121 if (!XDR_INT32(sink, &_buf))
00122 throw Error("Network I/O Error. Culd not read int 32 data.\nThis may be due to a bug in libdap, on the server or a\nproblem with the network connection.");
00123
00124 return true;
00125 }
00126
00127 bool
00128 Int32::deserialize(XDR *source, DDS *, bool)
00129 {
00130 if (!XDR_INT32(source, &_buf))
00131 throw Error("Network I/O Error. Could not send int 32 data. This may be due to a\nbug in libdap or a problem with the network connection.");
00132
00133 return false;
00134 }
00135
00136 unsigned int
00137 Int32::val2buf(void *val, bool)
00138 {
00139
00140
00141
00142
00143 if (!val)
00144 throw InternalErr(__FILE__, __LINE__,
00145 "The incoming pointer does not contain any data.");
00146
00147 _buf = *(dods_int32 *)val;
00148
00149 return width();
00150 }
00151
00152 unsigned int
00153 Int32::buf2val(void **val)
00154 {
00155
00156
00157 if (!val)
00158 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00159
00160 if (!*val)
00161 *val = new dods_int32;
00162
00163 *(dods_int32 *)*val = _buf;
00164
00165 return width();
00166 }
00167
00168 dods_int32
00169 Int32::value() const
00170 {
00171 return _buf;
00172 }
00173
00174 bool
00175 Int32::set_value(dods_int32 i)
00176 {
00177 _buf = i;
00178 set_read_p(true);
00179
00180 return true;
00181 }
00182
00183 void
00184 Int32::print_val(FILE *out, string space, bool print_decl_p)
00185 {
00186 if (print_decl_p) {
00187 print_decl(out, space, false);
00188 fprintf(out, " = %d;\n", (int)_buf) ;
00189 }
00190 else
00191 fprintf(out, "%d", (int)_buf) ;
00192 }
00193
00194 bool
00195 Int32::ops(BaseType *b, int op, const string &dataset)
00196 {
00197
00198
00199 if (!read_p() && !read(dataset)) {
00200
00201
00202
00203
00204
00205 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00206 }
00207
00208
00209 if (!b->read_p() && !b->read(dataset)) {
00210
00211
00212
00213
00214
00215 throw InternalErr(__FILE__, __LINE__, "This value not read!");
00216 }
00217
00218 switch (b->type()) {
00219 case dods_byte_c:
00220 return rops<dods_int32, dods_byte, SUCmp<dods_int32, dods_byte> >
00221 (_buf, dynamic_cast<Byte *>(b)->_buf, op);
00222 case dods_int16_c:
00223 return rops<dods_int32, dods_int16, Cmp<dods_int32, dods_int16> >
00224 (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
00225 case dods_uint16_c:
00226 return rops<dods_int32, dods_uint16, SUCmp<dods_int32, dods_uint16> >
00227 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
00228 case dods_int32_c:
00229 return rops<dods_int32, dods_int32, Cmp<dods_int32, dods_int32> >
00230 (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
00231 case dods_uint32_c:
00232 return rops<dods_int32, dods_uint32, SUCmp<dods_int32, dods_uint32> >
00233 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
00234 case dods_float32_c:
00235 return rops<dods_int32, dods_float32, Cmp<dods_int32, dods_float32> >
00236 (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
00237 case dods_float64_c:
00238 return rops<dods_int32, dods_float64, Cmp<dods_int32, dods_float64> >
00239 (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
00240 default:
00241 return false;
00242 }
00243 }
00244
00253 void
00254 Int32::dump(ostream &strm) const
00255 {
00256 strm << DapIndent::LMarg << "Int32::dump - ("
00257 << (void *)this << ")" << endl ;
00258 DapIndent::Indent() ;
00259 BaseType::dump(strm) ;
00260 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00261 DapIndent::UnIndent() ;
00262 }
00263