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