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