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