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