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