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 21699 2009-11-05 00:06:01Z jimg $"
00041 };
00042
00043 #include "Byte.h"
00044 #include "Int16.h"
00045 #include "UInt16.h"
00046 #include "Int32.h"
00047 #include "UInt32.h"
00048 #include "Float32.h"
00049 #include "Float64.h"
00050 #include "Str.h"
00051 #include "Url.h"
00052 #include "Array.h"
00053 #include "Structure.h"
00054 #include "Sequence.h"
00055 #include "Grid.h"
00056
00057 #include "DDS.h"
00058 #include "Operators.h"
00059
00060 #include "util.h"
00061 #include "parser.h"
00062 #include "dods-limits.h"
00063 #include "InternalErr.h"
00064
00065 using std::cerr;
00066 using std::endl;
00067
00068 namespace libdap {
00069
00079 Byte::Byte(const string & n): BaseType(n, dods_byte_c)
00080 {}
00081
00092 Byte::Byte(const string &n, const string &d): BaseType(n, d, dods_byte_c)
00093 {}
00094
00095 Byte::Byte(const Byte & copy_from): BaseType(copy_from)
00096 {
00097 _buf = copy_from._buf;
00098 }
00099
00100 BaseType *Byte::ptr_duplicate()
00101 {
00102 return new Byte(*this);
00103 }
00104
00105 Byte & Byte::operator=(const Byte & rhs)
00106 {
00107 if (this == &rhs)
00108 return *this;
00109
00110 dynamic_cast < BaseType & >(*this) = rhs;
00111
00112 _buf = rhs._buf;
00113
00114 return *this;
00115 }
00116
00117 unsigned int Byte::width()
00118 {
00119 return sizeof(dods_byte);
00120 }
00121
00132 bool Byte::serialize(ConstraintEvaluator & eval, DDS & dds,
00133 Marshaller &m, bool ce_eval)
00134 {
00135 dds.timeout_on();
00136
00137 if (!read_p())
00138 read();
00139
00140 #if EVAL
00141 if (ce_eval && !eval.eval_selection(dds, dataset()))
00142 return true;
00143 #endif
00144
00145 dds.timeout_off();
00146
00147 m.put_byte( _buf ) ;
00148
00149 return true;
00150 }
00151
00155 bool Byte::deserialize(UnMarshaller &um, DDS *, bool)
00156 {
00157 um.get_byte( _buf ) ;
00158
00159 return false;
00160 }
00161
00167 unsigned int Byte::val2buf(void *val, bool)
00168 {
00169
00170
00171
00172
00173 if (!val)
00174 throw InternalErr("the incoming pointer does not contain any data.");
00175
00176 _buf = *(dods_byte *) val;
00177
00178 return width();
00179 }
00180
00181 unsigned int Byte::buf2val(void **val)
00182 {
00183
00184
00185 if (!val)
00186 throw InternalErr("NULL pointer");
00187
00188 if (!*val)
00189 *val = new dods_byte;
00190
00191 *(dods_byte *) * val = _buf;
00192
00193 return width();
00194 }
00195
00200 bool Byte::set_value(dods_byte value)
00201 {
00202 _buf = value;
00203 set_read_p(true);
00204
00205 return true;
00206 }
00207
00210 dods_byte Byte::value() const
00211 {
00212 return _buf;
00213 }
00214
00215 #if FILE_METHODS
00216 void Byte::print_val(FILE * out, string space, bool print_decl_p)
00217 {
00218 if (print_decl_p) {
00219 print_decl(out, space, false);
00220 fprintf(out, " = %d;\n", (int) _buf);
00221 }
00222 else
00223 fprintf(out, "%d", (int) _buf);
00224 }
00225 #endif
00226
00227 void Byte::print_val(ostream &out, string space, bool print_decl_p)
00228 {
00229 if (print_decl_p) {
00230 print_decl(out, space, false);
00231 out << " = " << (int)_buf << ";\n" ;
00232 }
00233 else
00234 out << (int)_buf ;
00235 }
00236
00237 bool Byte::ops(BaseType * b, int op)
00238 {
00239
00240
00241 if (!read_p() && !read()) {
00242
00243
00244
00245
00246
00247 throw InternalErr("This value not read!");
00248 }
00249
00250 if (!b || !(b->read_p() || b->read())) {
00251
00252
00253
00254
00255
00256 throw InternalErr("This value not read!");
00257 }
00258
00259 switch (b->type()) {
00260 case dods_byte_c:
00261 return rops < dods_byte, dods_byte, Cmp < dods_byte, dods_byte > >
00262 (_buf, dynamic_cast < Byte * >(b)->_buf, op);
00263 case dods_int16_c:
00264 return rops < dods_byte, dods_int16, USCmp < dods_byte,
00265 dods_int16 > > (_buf, dynamic_cast < Int16 * >(b)->_buf, op);
00266 case dods_uint16_c:
00267 return rops < dods_byte, dods_uint16, Cmp < dods_byte,
00268 dods_uint16 > > (_buf, dynamic_cast < UInt16 * >(b)->_buf, op);
00269 case dods_int32_c:
00270 return rops < dods_byte, dods_int32, USCmp < dods_byte,
00271 dods_int32 > > (_buf, dynamic_cast < Int32 * >(b)->_buf, op);
00272 case dods_uint32_c:
00273 return rops < dods_byte, dods_uint32, Cmp < dods_byte,
00274 dods_uint32 > > (_buf, dynamic_cast < UInt32 * >(b)->_buf, op);
00275 case dods_float32_c:
00276 return rops < dods_byte, dods_float32, Cmp < dods_byte,
00277 dods_float32 > > (_buf, dynamic_cast < Float32 * >(b)->_buf,
00278 op);
00279 case dods_float64_c:
00280 return rops < dods_byte, dods_float64, Cmp < dods_byte,
00281 dods_float64 > > (_buf, dynamic_cast < Float64 * >(b)->_buf,
00282 op);
00283 default:
00284 return false;
00285 }
00286 }
00287
00296 void Byte::dump(ostream & strm) const
00297 {
00298 strm << DapIndent::LMarg << "Byte::dump - ("
00299 << (void *) this << ")" << endl;
00300 DapIndent::Indent();
00301 BaseType::dump(strm);
00302 strm << DapIndent::LMarg << "value: " << _buf << endl;
00303 DapIndent::UnIndent();
00304 }
00305
00306 }