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 20518 2009-03-05 23:39:46Z jimg $"
00041 };
00042
00043 #include "UInt32.h"
00044 #include "DDS.h"
00045 #include "util.h"
00046 #include "parser.h"
00047 #include "Operators.h"
00048 #include "dods-limits.h"
00049 #include "debug.h"
00050 #include "InternalErr.h"
00051
00052 using std::cerr;
00053 using std::endl;
00054
00055 namespace libdap {
00056
00062 UInt32::UInt32(const string &n)
00063 : BaseType(n, dods_uint32_c)
00064 {}
00065
00073 UInt32::UInt32(const string &n, const string &d)
00074 : BaseType(n, d, dods_uint32_c)
00075 {}
00076
00077 UInt32::UInt32(const UInt32 ©_from) : BaseType(copy_from)
00078 {
00079 _buf = copy_from._buf;
00080 }
00081
00082 BaseType *
00083 UInt32::ptr_duplicate()
00084 {
00085 return new UInt32(*this);
00086 }
00087
00088 UInt32 &
00089 UInt32::operator=(const UInt32 &rhs)
00090 {
00091 if (this == &rhs)
00092 return *this;
00093
00094 dynamic_cast<BaseType &>(*this) = rhs;
00095
00096 _buf = rhs._buf;
00097
00098 return *this;
00099 }
00100
00101 unsigned int
00102 UInt32::width()
00103 {
00104 return sizeof(dods_uint32);
00105 }
00106
00107 bool
00108 UInt32::serialize(ConstraintEvaluator &eval, DDS &dds,
00109 Marshaller &m, bool ce_eval)
00110 {
00111 dds.timeout_on();
00112
00113 if (!read_p())
00114 read();
00115
00116 #if EVAL
00117 if (ce_eval && !eval.eval_selection(dds, dataset()))
00118 return true;
00119 #endif
00120
00121 dds.timeout_off();
00122
00123 m.put_uint32( _buf ) ;
00124
00125 return true;
00126 }
00127
00128 bool
00129 UInt32::deserialize(UnMarshaller &um, DDS *, bool)
00130 {
00131 um.get_uint32( _buf ) ;
00132
00133 return false;
00134 }
00135
00136 unsigned int
00137 UInt32::val2buf(void *val, bool)
00138 {
00139
00140
00141
00142
00143
00144 if (!val)
00145 throw InternalErr(__FILE__, __LINE__,
00146 "The incoming pointer does not contain any data.");
00147
00148 _buf = *(dods_uint32 *)val;
00149
00150 return width();
00151 }
00152
00153 unsigned int
00154 UInt32::buf2val(void **val)
00155 {
00156
00157
00158 if (!val)
00159 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00160
00161 if (!*val)
00162 *val = new dods_uint32;
00163
00164 *(dods_uint32 *)*val = _buf;
00165
00166 return width();
00167 }
00168
00169 dods_uint32
00170 UInt32::value() const
00171 {
00172 return _buf;
00173 }
00174
00175 bool
00176 UInt32::set_value(dods_uint32 i)
00177 {
00178 _buf = i;
00179 set_read_p(true);
00180
00181 return true;
00182 }
00183
00184 void
00185 UInt32::print_val(FILE *out, string space, bool print_decl_p)
00186 {
00187 if (print_decl_p) {
00188 print_decl(out, space, false);
00189 fprintf(out, " = %u;\n", (unsigned int)_buf) ;
00190 }
00191 else
00192 fprintf(out, "%u", (unsigned int)_buf) ;
00193 }
00194
00195 void
00196 UInt32::print_val(ostream &out, string space, bool print_decl_p)
00197 {
00198 if (print_decl_p) {
00199 print_decl(out, space, false);
00200 out << " = " << (unsigned int)_buf << ";\n" ;
00201 }
00202 else
00203 out << (unsigned int)_buf ;
00204 }
00205
00206 bool
00207 UInt32::ops(BaseType *b, int op)
00208 {
00209
00210 if (!read_p() && !read()) {
00211
00212
00213
00214
00215
00216 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
00217 }
00218
00219
00220 if (!b || !b->read_p() && !b->read()) {
00221
00222
00223
00224
00225
00226 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
00227 }
00228
00229 switch (b->type()) {
00230 case dods_byte_c:
00231 return rops<dods_uint32, dods_byte, Cmp<dods_uint32, dods_byte> >
00232 (_buf, dynamic_cast<Byte *>(b)->_buf, op);
00233 case dods_int16_c:
00234 return rops<dods_uint32, dods_int16, USCmp<dods_uint32, dods_int16> >
00235 (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
00236 case dods_uint16_c:
00237 return rops<dods_uint32, dods_uint16, Cmp<dods_uint32, dods_uint16> >
00238 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
00239 case dods_int32_c:
00240 return rops<dods_uint32, dods_int32, USCmp<dods_uint32, dods_int32> >
00241 (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
00242 case dods_uint32_c:
00243 return rops<dods_uint32, dods_uint32, Cmp<dods_uint32, dods_uint32> >
00244 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
00245 case dods_float32_c:
00246 return rops<dods_uint32, dods_float32, Cmp<dods_uint32, dods_float32> >
00247 (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
00248 case dods_float64_c:
00249 return rops<dods_uint32, dods_float64, Cmp<dods_uint32, dods_float64> >
00250 (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
00251 default:
00252 return false;
00253 }
00254 }
00255
00264 void
00265 UInt32::dump(ostream &strm) const
00266 {
00267 strm << DapIndent::LMarg << "UInt32::dump - ("
00268 << (void *)this << ")" << endl ;
00269 DapIndent::Indent() ;
00270 BaseType::dump(strm) ;
00271 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00272 DapIndent::UnIndent() ;
00273 }
00274
00275 }
00276