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