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