libdap++  Updated for version 3.12.0
Int8.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) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #include "config.h"
27 
28 #include <cassert>
29 #include <sstream>
30 
31 #include "Byte.h" // synonymous with UInt8 and Char
32 #include "Int8.h"
33 #include "Int16.h"
34 #include "UInt16.h"
35 #include "Int32.h"
36 #include "UInt32.h"
37 #include "Int64.h"
38 #include "UInt64.h"
39 #include "Float32.h"
40 #include "Float64.h"
41 #include "Str.h"
42 #include "Url.h"
43 
44 #include "DAP4StreamMarshaller.h"
45 #include "DAP4StreamUnMarshaller.h"
46 
47 #include "DDS.h"
48 #include "util.h"
49 #include "parser.h"
50 #include "Operators.h"
51 #include "dods-limits.h"
52 #include "debug.h"
53 #include "InternalErr.h"
54 
55 using std::cerr;
56 using std::endl;
57 
58 namespace libdap {
59 
64 Int8::Int8(const string &n) : BaseType(n, dods_int8_c)
65 {}
66 
74 Int8::Int8(const string &n, const string &d) : BaseType(n, d, dods_int8_c)
75 {}
76 
77 Int8::Int8(const Int8 &copy_from) : BaseType(copy_from)
78 {
79  d_buf = copy_from.d_buf;
80 }
81 
82 BaseType *
84 {
85  return new Int8(*this);
86 }
87 
88 Int8 &
89 Int8::operator=(const Int8 &rhs)
90 {
91  if (this == &rhs)
92  return *this;
93 
94  static_cast<BaseType &>(*this) = rhs;
95 
96  d_buf = rhs.d_buf;
97 
98  return *this;
99 }
100 
101 unsigned int
103 {
104  return sizeof(dods_int8);
105 }
106 
107 bool
108 Int8::serialize(ConstraintEvaluator &eval, DDS &dds, Marshaller &m, bool ce_eval)
109 {
110  dds.timeout_on();
111 
112  if (!read_p())
113  read(); // read() throws Error and InternalErr
114 
115 #if EVAL
116  if (ce_eval && !eval.eval_selection(dds, dataset()))
117  return true;
118 #endif
119 
120  dds.timeout_off();
121 
122  assert(typeid(m)==typeid(DAP4StreamMarshaller));
123  static_cast<DAP4StreamMarshaller&>(m).put_int8( d_buf ) ;
124 
125  return true;
126 }
127 
128 bool
130 {
131  assert(typeid(um)==typeid(DAP4StreamUnMarshaller));
132  static_cast<DAP4StreamUnMarshaller&>(um).get_int8( d_buf ) ;
133 
134  return false;
135 }
136 
137 dods_int8
138 Int8::value() const
139 {
140  return d_buf;
141 }
142 
143 bool
145 {
146  d_buf = i;
147  set_read_p(true);
148 
149  return true;
150 }
151 
152 void
153 Int8::print_val(FILE *out, string space, bool print_decl_p)
154 {
155  ostringstream oss;
156  print_val(oss, space, print_decl_p);
157  fwrite(oss.str().data(), sizeof(char), oss.str().length(), out);
158 }
159 
160 void
161 Int8::print_val(ostream &out, string space, bool print_decl_p)
162 {
163  if (print_decl_p) {
164  print_decl(out, space, false);
165  out << " = " << d_buf << ";\n" ;
166  }
167  else
168  out << d_buf ;
169 }
170 
171 bool
172 Int8::ops(BaseType *b, int op)
173 {
174  // Get the arg's value.
175  if (!read_p() && !read())
176  throw InternalErr(__FILE__, __LINE__, "This value not read!");
177 
178  // Get the second arg's value.
179  if (!b->read_p() && !b->read())
180  throw InternalErr(__FILE__, __LINE__, "This value not read!");
181 
182  switch (b->type()) {
183  case dods_int8_c:
184  return Cmp<dods_int8, dods_int8>(op, d_buf, static_cast<Int8*>(b)->value());
185  case dods_byte_c:
186  return SUCmp<dods_int8, dods_byte>(op, d_buf, static_cast<Byte*>(b)->value());
187  case dods_int16_c:
188  return Cmp<dods_int8, dods_int16>(op, d_buf, static_cast<Int16*>(b)->value());
189  case dods_uint16_c:
190  return SUCmp<dods_int8, dods_uint16>(op, d_buf, static_cast<UInt16*>(b)->value());
191  case dods_int32_c:
192  return Cmp<dods_int8, dods_int32>(op, d_buf, static_cast<Int32*>(b)->value());
193  case dods_uint32_c:
194  return SUCmp<dods_int8, dods_uint32>(op, d_buf, static_cast<UInt32*>(b)->value());
195  case dods_int64_c:
196  return Cmp<dods_int8, dods_int64>(op, d_buf, static_cast<Int64*>(b)->value());
197  case dods_uint64_c:
198  return SUCmp<dods_int8, dods_uint64>(op, d_buf, static_cast<UInt64*>(b)->value());
199  case dods_float32_c:
200  return Cmp<dods_int8, dods_float32>(op, d_buf, static_cast<Float32*>(b)->value());
201  case dods_float64_c:
202  return Cmp<dods_int8, dods_float64>(op, d_buf, static_cast<Float64*>(b)->value());
203  default:
204  return false;
205  }
206 #if 0
207  switch (b->type()) {
208  case dods_byte_c:
209  return rops<dods_int8, dods_byte, SUCmp<dods_int8, dods_byte> >(d_buf, static_cast<Byte*>(b)->value());
210  case dods_int16_c:
211  return rops<dods_int8, dods_int16, Cmp<dods_int8, dods_int16> >(d_buf, static_cast<Int16 *>(b)->value());
212  case dods_uint16_c:
213  return rops<dods_int8, dods_uint16, SUCmp<dods_int8, dods_uint16> >(d_buf, static_cast<UInt16 *>(b)->value());
214  case dods_int32_c:
215  return rops<dods_int8, dods_int32, Cmp<dods_int8, dods_int32> >(d_buf, static_cast<Int32 *>(b)->value());
216  case dods_uint32_c:
217  return rops<dods_int8, dods_uint32, SUCmp<dods_int8, dods_uint32> >(d_buf, static_cast<UInt32 *>(b)->value());
218  case dods_int64_c:
219  return rops<dods_int8, dods_int64, Cmp<dods_int8, dods_int64> >(d_buf, static_cast<Int64 *>(b)->value());
220  case dods_uint64_c:
221  return rops<dods_int8, dods_uint64, Cmp<dods_int8, dods_uint64> >(d_buf, static_cast<UInt64 *>(b)->value());
222  case dods_float32_c:
223  return rops<dods_int8, dods_float32, Cmp<dods_int64, dods_float32> >(d_buf, static_cast<Float32 *>(b)->value());
224  case dods_float64_c:
225  return rops<dods_int8, dods_float64, Cmp<dods_int64, dods_float64> >(d_buf, static_cast<Float64 *>(b)->value());
226  default:
227  return false;
228  }
229 #endif
230 }
231 
240 void
241 Int8::dump(ostream &strm) const
242 {
243  strm << DapIndent::LMarg << "Int8::dump - ("
244  << (void *)this << ")" << endl ;
246  BaseType::dump(strm) ;
247  strm << DapIndent::LMarg << "value: " << d_buf << endl ;
249 }
250 
251 } // namespace libdap
252