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