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 18315 2008-03-03 20:14:44Z 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
00057 UInt32::UInt32(const string &n)
00058 : BaseType(n, dods_uint32_c)
00059 {}
00060
00061 UInt32::UInt32(const UInt32 ©_from) : BaseType(copy_from)
00062 {
00063 _buf = copy_from._buf;
00064 }
00065
00066 BaseType *
00067 UInt32::ptr_duplicate()
00068 {
00069 return new UInt32(*this);
00070 }
00071
00072 UInt32 &
00073 UInt32::operator=(const UInt32 &rhs)
00074 {
00075 if (this == &rhs)
00076 return *this;
00077
00078 dynamic_cast<BaseType &>(*this) = rhs;
00079
00080 _buf = rhs._buf;
00081
00082 return *this;
00083 }
00084
00085 unsigned int
00086 UInt32::width()
00087 {
00088 return sizeof(dods_uint32);
00089 }
00090
00091 bool
00092 UInt32::serialize(const string &dataset, ConstraintEvaluator &eval, DDS &dds,
00093 Marshaller &m, bool ce_eval)
00094 {
00095 dds.timeout_on();
00096
00097 if (!read_p())
00098 read(dataset);
00099
00100 #if EVAL
00101 if (ce_eval && !eval.eval_selection(dds, dataset))
00102 return true;
00103 #endif
00104
00105 dds.timeout_off();
00106
00107 m.put_uint32( _buf ) ;
00108
00109 return true;
00110 }
00111
00112 bool
00113 UInt32::deserialize(UnMarshaller &um, DDS *, bool)
00114 {
00115 um.get_uint32( _buf ) ;
00116
00117 return false;
00118 }
00119
00120 unsigned int
00121 UInt32::val2buf(void *val, bool)
00122 {
00123
00124
00125
00126
00127
00128 if (!val)
00129 throw InternalErr(__FILE__, __LINE__,
00130 "The incoming pointer does not contain any data.");
00131
00132 _buf = *(dods_uint32 *)val;
00133
00134 return width();
00135 }
00136
00137 unsigned int
00138 UInt32::buf2val(void **val)
00139 {
00140
00141
00142 if (!val)
00143 throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
00144
00145 if (!*val)
00146 *val = new dods_uint32;
00147
00148 *(dods_uint32 *)*val = _buf;
00149
00150 return width();
00151 }
00152
00153 dods_uint32
00154 UInt32::value() const
00155 {
00156 return _buf;
00157 }
00158
00159 bool
00160 UInt32::set_value(dods_uint32 i)
00161 {
00162 _buf = i;
00163 set_read_p(true);
00164
00165 return true;
00166 }
00167
00168 void
00169 UInt32::print_val(FILE *out, string space, bool print_decl_p)
00170 {
00171 if (print_decl_p) {
00172 print_decl(out, space, false);
00173 fprintf(out, " = %u;\n", (unsigned int)_buf) ;
00174 }
00175 else
00176 fprintf(out, "%u", (unsigned int)_buf) ;
00177 }
00178
00179 void
00180 UInt32::print_val(ostream &out, string space, bool print_decl_p)
00181 {
00182 if (print_decl_p) {
00183 print_decl(out, space, false);
00184 out << " = " << (unsigned int)_buf << ";\n" ;
00185 }
00186 else
00187 out << (unsigned int)_buf ;
00188 }
00189
00190 bool
00191 UInt32::ops(BaseType *b, int op, const string &dataset)
00192 {
00193
00194 if (!read_p() && !read(dataset)) {
00195
00196
00197
00198
00199
00200 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
00201 }
00202
00203
00204 if (!b->read_p() && !b->read(dataset)) {
00205
00206
00207
00208
00209
00210 throw InternalErr(__FILE__, __LINE__, "This value was not read!");
00211 }
00212
00213 switch (b->type()) {
00214 case dods_byte_c:
00215 return rops<dods_uint32, dods_byte, Cmp<dods_uint32, dods_byte> >
00216 (_buf, dynamic_cast<Byte *>(b)->_buf, op);
00217 case dods_int16_c:
00218 return rops<dods_uint32, dods_int16, USCmp<dods_uint32, dods_int16> >
00219 (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
00220 case dods_uint16_c:
00221 return rops<dods_uint32, dods_uint16, Cmp<dods_uint32, dods_uint16> >
00222 (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
00223 case dods_int32_c:
00224 return rops<dods_uint32, dods_int32, USCmp<dods_uint32, dods_int32> >
00225 (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
00226 case dods_uint32_c:
00227 return rops<dods_uint32, dods_uint32, Cmp<dods_uint32, dods_uint32> >
00228 (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
00229 case dods_float32_c:
00230 return rops<dods_uint32, dods_float32, Cmp<dods_uint32, dods_float32> >
00231 (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
00232 case dods_float64_c:
00233 return rops<dods_uint32, dods_float64, Cmp<dods_uint32, dods_float64> >
00234 (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
00235 default:
00236 return false;
00237 }
00238 }
00239
00248 void
00249 UInt32::dump(ostream &strm) const
00250 {
00251 strm << DapIndent::LMarg << "UInt32::dump - ("
00252 << (void *)this << ")" << endl ;
00253 DapIndent::Indent() ;
00254 BaseType::dump(strm) ;
00255 strm << DapIndent::LMarg << "value: " << _buf << endl ;
00256 DapIndent::UnIndent() ;
00257 }
00258
00259 }
00260