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 20518 2009-03-05 23:39:46Z 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
00056 namespace libdap {
00057
00067 Byte::Byte(const string & n): BaseType(n, dods_byte_c)
00068 {}
00069
00080 Byte::Byte(const string &n, const string &d): BaseType(n, d, dods_byte_c)
00081 {}
00082
00083 Byte::Byte(const Byte & copy_from): BaseType(copy_from)
00084 {
00085 _buf = copy_from._buf;
00086 }
00087
00088 BaseType *Byte::ptr_duplicate()
00089 {
00090 return new Byte(*this);
00091 }
00092
00093 Byte & Byte::operator=(const Byte & rhs)
00094 {
00095 if (this == &rhs)
00096 return *this;
00097
00098 dynamic_cast < BaseType & >(*this) = rhs;
00099
00100 _buf = rhs._buf;
00101
00102 return *this;
00103 }
00104
00105 unsigned int Byte::width()
00106 {
00107 return sizeof(dods_byte);
00108 }
00109
00120 bool Byte::serialize(ConstraintEvaluator & eval, DDS & dds,
00121 Marshaller &m, bool ce_eval)
00122 {
00123 dds.timeout_on();
00124
00125 if (!read_p())
00126 read();
00127
00128 #if EVAL
00129 if (ce_eval && !eval.eval_selection(dds, dataset()))
00130 return true;
00131 #endif
00132
00133 dds.timeout_off();
00134
00135 m.put_byte( _buf ) ;
00136
00137 return true;
00138 }
00139
00143 bool Byte::deserialize(UnMarshaller &um, DDS *, bool)
00144 {
00145 um.get_byte( _buf ) ;
00146
00147 return false;
00148 }
00149
00155 unsigned int Byte::val2buf(void *val, bool)
00156 {
00157
00158
00159
00160
00161 if (!val)
00162 throw InternalErr("the incoming pointer does not contain any data.");
00163
00164 _buf = *(dods_byte *) val;
00165
00166 return width();
00167 }
00168
00169 unsigned int Byte::buf2val(void **val)
00170 {
00171
00172
00173 if (!val)
00174 throw InternalErr("NULL pointer");
00175
00176 if (!*val)
00177 *val = new dods_byte;
00178
00179 *(dods_byte *) * val = _buf;
00180
00181 return width();
00182 }
00183
00188 bool Byte::set_value(dods_byte value)
00189 {
00190 _buf = value;
00191 set_read_p(true);
00192
00193 return true;
00194 }
00195
00198 dods_byte Byte::value() const
00199 {
00200 return _buf;
00201 }
00202
00203 void Byte::print_val(FILE * out, string space, bool print_decl_p)
00204 {
00205 if (print_decl_p) {
00206 print_decl(out, space, false);
00207 fprintf(out, " = %d;\n", (int) _buf);
00208 }
00209 else
00210 fprintf(out, "%d", (int) _buf);
00211 }
00212
00213 void Byte::print_val(ostream &out, string space, bool print_decl_p)
00214 {
00215 if (print_decl_p) {
00216 print_decl(out, space, false);
00217 out << " = " << (int)_buf << ";\n" ;
00218 }
00219 else
00220 out << (int)_buf ;
00221 }
00222
00223 bool Byte::ops(BaseType * b, int op)
00224 {
00225
00226
00227 if (!read_p() && !read()) {
00228 cerr << "This value not read!" << endl;
00229
00230
00231
00232
00233
00234 throw InternalErr("This value not read!");
00235 }
00236
00237 if (!b || !b->read_p() && !b->read()) {
00238 cerr << "This value not read!" << endl;
00239
00240
00241
00242
00243
00244 throw InternalErr("This value not read!");
00245 }
00246
00247 switch (b->type()) {
00248 case dods_byte_c:
00249 return rops < dods_byte, dods_byte, Cmp < dods_byte, dods_byte > >
00250 (_buf, dynamic_cast < Byte * >(b)->_buf, op);
00251 case dods_int16_c:
00252 return rops < dods_byte, dods_int16, USCmp < dods_byte,
00253 dods_int16 > > (_buf, dynamic_cast < Int16 * >(b)->_buf, op);
00254 case dods_uint16_c:
00255 return rops < dods_byte, dods_uint16, Cmp < dods_byte,
00256 dods_uint16 > > (_buf, dynamic_cast < UInt16 * >(b)->_buf, op);
00257 case dods_int32_c:
00258 return rops < dods_byte, dods_int32, USCmp < dods_byte,
00259 dods_int32 > > (_buf, dynamic_cast < Int32 * >(b)->_buf, op);
00260 case dods_uint32_c:
00261 return rops < dods_byte, dods_uint32, Cmp < dods_byte,
00262 dods_uint32 > > (_buf, dynamic_cast < UInt32 * >(b)->_buf, op);
00263 case dods_float32_c:
00264 return rops < dods_byte, dods_float32, Cmp < dods_byte,
00265 dods_float32 > > (_buf, dynamic_cast < Float32 * >(b)->_buf,
00266 op);
00267 case dods_float64_c:
00268 return rops < dods_byte, dods_float64, Cmp < dods_byte,
00269 dods_float64 > > (_buf, dynamic_cast < Float64 * >(b)->_buf,
00270 op);
00271 default:
00272 return false;
00273 }
00274 }
00275
00284 void Byte::dump(ostream & strm) const
00285 {
00286 strm << DapIndent::LMarg << "Byte::dump - ("
00287 << (void *) this << ")" << endl;
00288 DapIndent::Indent();
00289 BaseType::dump(strm);
00290 strm << DapIndent::LMarg << "value: " << _buf << endl;
00291 DapIndent::UnIndent();
00292 }
00293
00294 }