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