libdap++  Updated for version 3.8.2
Int32.cc
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1994-1999
27 // Please read the full copyright statement in the file COPYRIGHT_URI.
28 //
29 // Authors:
30 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31 
32 // Implementation for Int32.
33 //
34 // jhrg 9/7/94
35 
36 
37 #include "config.h"
38 
39 static char rcsid[] not_used =
40  {"$Id: Int32.cc 21699 2009-11-05 00:06:01Z jimg $"
41  };
42 
43 #include "Byte.h"
44 #include "Int16.h"
45 #include "UInt16.h"
46 #include "Int32.h"
47 #include "UInt32.h"
48 #include "Float32.h"
49 #include "Float64.h"
50 #include "Str.h"
51 #include "Url.h"
52 #include "Array.h"
53 #include "Structure.h"
54 #include "Sequence.h"
55 #include "Grid.h"
56 
57 #include "DDS.h"
58 #include "util.h"
59 #include "parser.h"
60 #include "Operators.h"
61 #include "dods-limits.h"
62 #include "debug.h"
63 #include "InternalErr.h"
64 
65 
66 using std::cerr;
67 using std::endl;
68 
69 namespace libdap {
70 
78 Int32::Int32(const string &n)
80 {}
81 
89 Int32::Int32(const string &n, const string &d)
90  : BaseType(n, d, dods_int32_c)
91 {}
92 
93 Int32::Int32(const Int32 &copy_from) : BaseType(copy_from)
94 {
95  _buf = copy_from._buf;
96 }
97 
98 BaseType *
100 {
101  return new Int32(*this);
102 }
103 
105 {
106  DBG(cerr << "~Int32" << endl);
107 }
108 
109 Int32 &
111 {
112  if (this == &rhs)
113  return *this;
114 
115  dynamic_cast<BaseType &>(*this) = rhs;
116 
117  _buf = rhs._buf;
118 
119  return *this;
120 }
121 
122 unsigned int
124 {
125  return sizeof(dods_int32);
126 }
127 
128 bool
130  Marshaller &m, bool ce_eval)
131 {
132  dds.timeout_on();
133 
134  if (!read_p())
135  read(); // read() throws Error and InternalErr
136 
137 #if EVAL
138  if (ce_eval && !eval.eval_selection(dds, dataset()))
139  return true;
140 #endif
141 
142  dds.timeout_off();
143 
144  m.put_int32( _buf ) ;
145 
146  return true;
147 }
148 
149 bool
151 {
152  um.get_int32( _buf ) ;
153 
154  return false;
155 }
156 
157 unsigned int
158 Int32::val2buf(void *val, bool)
159 {
160  // Jose Garcia
161  // This method is public therefore and I believe it has being designed
162  // to be use by read which must be implemented on the surrogated library,
163  // thus if the pointer val is NULL, is an Internal Error.
164  if (!val)
165  throw InternalErr(__FILE__, __LINE__,
166  "The incoming pointer does not contain any data.");
167 
168  _buf = *(dods_int32 *)val;
169 
170  return width();
171 }
172 
173 unsigned int
174 Int32::buf2val(void **val)
175 {
176  // Jose Garcia
177  // The same comment justifying throwing an Error in val2buf applies here.
178  if (!val)
179  throw InternalErr(__FILE__, __LINE__, "NULL pointer.");
180 
181  if (!*val)
182  *val = new dods_int32;
183 
184  *(dods_int32 *)*val = _buf;
185 
186  return width();
187 }
188 
191 {
192  return _buf;
193 }
194 
195 bool
197 {
198  _buf = i;
199  set_read_p(true);
200 
201  return true;
202 }
203 
204 #if FILE_METHODS
205 void
206 Int32::print_val(FILE *out, string space, bool print_decl_p)
207 {
208  if (print_decl_p) {
209  print_decl(out, space, false);
210  fprintf(out, " = %d;\n", (int)_buf) ;
211  }
212  else
213  fprintf(out, "%d", (int)_buf) ;
214 }
215 #endif
216 
217 void
218 Int32::print_val(ostream &out, string space, bool print_decl_p)
219 {
220  if (print_decl_p) {
221  print_decl(out, space, false);
222  out << " = " << (int)_buf << ";\n" ;
223  }
224  else
225  out << (int)_buf ;
226 }
227 
228 bool
229 Int32::ops(BaseType *b, int op)
230 {
231 
232  // Extract the Byte arg's value.
233  if (!read_p() && !read()) {
234  // Jose Garcia
235  // Since the read method is virtual and implemented outside
236  // libdap++ if we cannot read the data that is the problem
237  // of the user or of whoever wrote the surrogate library
238  // implemeting read therefore it is an internal error.
239  throw InternalErr(__FILE__, __LINE__, "This value not read!");
240  }
241 
242  // Extract the second arg's value.
243  if (!b->read_p() && !b->read()) {
244  // Jose Garcia
245  // Since the read method is virtual and implemented outside
246  // libdap++ if we cannot read the data that is the problem
247  // of the user or of whoever wrote the surrogate library
248  // implemeting read therefore it is an internal error.
249  throw InternalErr(__FILE__, __LINE__, "This value not read!");
250  }
251 
252  switch (b->type()) {
253  case dods_byte_c:
254  return rops<dods_int32, dods_byte, SUCmp<dods_int32, dods_byte> >
255  (_buf, dynamic_cast<Byte *>(b)->_buf, op);
256  case dods_int16_c:
257  return rops<dods_int32, dods_int16, Cmp<dods_int32, dods_int16> >
258  (_buf, dynamic_cast<Int16 *>(b)->_buf, op);
259  case dods_uint16_c:
260  return rops<dods_int32, dods_uint16, SUCmp<dods_int32, dods_uint16> >
261  (_buf, dynamic_cast<UInt16 *>(b)->_buf, op);
262  case dods_int32_c:
263  return rops<dods_int32, dods_int32, Cmp<dods_int32, dods_int32> >
264  (_buf, dynamic_cast<Int32 *>(b)->_buf, op);
265  case dods_uint32_c:
266  return rops<dods_int32, dods_uint32, SUCmp<dods_int32, dods_uint32> >
267  (_buf, dynamic_cast<UInt32 *>(b)->_buf, op);
268  case dods_float32_c:
269  return rops<dods_int32, dods_float32, Cmp<dods_int32, dods_float32> >
270  (_buf, dynamic_cast<Float32 *>(b)->_buf, op);
271  case dods_float64_c:
272  return rops<dods_int32, dods_float64, Cmp<dods_int32, dods_float64> >
273  (_buf, dynamic_cast<Float64 *>(b)->_buf, op);
274  default:
275  return false;
276  }
277 }
278 
287 void
288 Int32::dump(ostream &strm) const
289 {
290  strm << DapIndent::LMarg << "Int32::dump - ("
291  << (void *)this << ")" << endl ;
293  BaseType::dump(strm) ;
294  strm << DapIndent::LMarg << "value: " << _buf << endl ;
296 }
297 
298 } // namespace libdap
299 
virtual bool read()
Read data into a local buffer.
Definition: BaseType.cc:790
virtual bool read_p()
Has this variable been read?
Definition: BaseType.cc:444
virtual ~Int32()
Definition: Int32.cc:104
static void UnIndent()
Definition: DapIndent.cc:49
abstract base class used to unmarshall/deserialize dap data objects
Definition: UnMarshaller.h:54
virtual void print_decl(FILE *out, string space=" ", bool print_semi=true, bool constraint_info=false, bool constrained=false)
Print an ASCII representation of the variable structure.
Definition: BaseType.cc:853
virtual bool ops(BaseType *b, int op)
Evaluate relational operators.
Definition: Int32.cc:229
#define not_used
Definition: config.h:850
Int32(const string &n)
Definition: Int32.cc:78
Holds an unsigned 16-bit integer.
Definition: UInt16.h:59
virtual dods_int32 value() const
Definition: Int32.cc:190
void timeout_off()
Definition: DDS.cc:687
virtual unsigned int width()
Returns the size of the class instance data.
Definition: Int32.cc:123
Type type() const
Returns the type of the class instance.
Definition: BaseType.cc:238
Holds a 32-bit floating point value.
Definition: Float32.h:61
A class for software fault reporting.
Definition: InternalErr.h:64
virtual bool deserialize(UnMarshaller &um, DDS *dds, bool reuse=false)
Receive data from the net.
Definition: Int32.cc:150
string dataset() const
Returns the name of the dataset used to create this instance.
Definition: BaseType.cc:231
bool eval_selection(DDS &dds, const string &dataset)
Evaluate a boolean-valued constraint expression. This is main method for the evaluator ans is called ...
#define DBG(x)
Definition: debug.h:58
virtual void get_int32(dods_int32 &val)=0
Holds a 16-bit signed integer value.
Definition: Int16.h:59
static void Indent()
Definition: DapIndent.cc:43
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BaseType.cc:186
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Definition: BaseType.cc:483
Int32 & operator=(const Int32 &rhs)
Definition: Int32.cc:110
virtual BaseType * ptr_duplicate()
Definition: Int32.cc:99
virtual void dump(ostream &strm) const
dumps information about this object
Definition: Int32.cc:288
void timeout_on()
Definition: DDS.cc:679
Evaluate a constraint expression.
static ostream & LMarg(ostream &strm)
Definition: DapIndent.cc:78
virtual bool set_value(dods_int32 i)
Definition: Int32.cc:196
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
Definition: Int32.cc:206
The basic data type for the DODS DAP types.
Definition: BaseType.h:190
abstract base class used to marshal/serialize dap data objects
Definition: Marshaller.h:53
Holds a 64-bit (double precision) floating point value.
Definition: Float64.h:62
Holds a single byte.
Definition: Byte.h:63
dods_int32 _buf
Definition: Int32.h:77
virtual unsigned int buf2val(void **val)
Reads the class data.
Definition: Int32.cc:174
Holds a 32-bit unsigned integer.
Definition: UInt32.h:61
virtual void put_int32(dods_int32 val)=0
virtual bool serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval=true)
Move data to the net.
Definition: Int32.cc:129
Holds a 32-bit signed integer.
Definition: Int32.h:62
virtual unsigned int val2buf(void *val, bool reuse=false)
Loads class data.
Definition: Int32.cc:158
int32_t dods_int32