bes  Updated for version 3.20.6
FFUInt16.cc
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of ff_handler a FreeForm API handler for the OPeNDAP
5 // DAP2 data server.
6 
7 // Copyright (c) 2005 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This is free software; you can redistribute it and/or modify it under the
11 // terms of the GNU Lesser General Public License as published by the Free
12 // Software Foundation; either version 2.1 of the License, or (at your
13 // option) any later version.
14 //
15 // This software is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 // 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 // (c) COPYRIGHT URI/MIT 1999
27 // Please read the full copyright statement in the file COPYRIGHT.
28 //
29 // Authors: James Gallagher
30 
31 #include "config_ff.h"
32 
33 static char rcsid[] not_used =
34  { "$Id$" };
35 
36 
37 #include "FFUInt16.h"
38 #include "util_ff.h"
39 
40 #include <cstring>
41 
42 extern long BufPtr;
43 extern char *BufVal;
44 
45 FFUInt16::FFUInt16(const string &n, const string &d) : UInt16(n, d)
46 {
47 }
48 
49 BaseType *FFUInt16::ptr_duplicate()
50 {
51 
52  return new FFUInt16(*this);
53 }
54 
55 bool FFUInt16::read()
56 {
57  if (read_p()) // nothing to do
58  return true;
59 
60  if (BufVal) { // data in cache
61  char *ptr = BufVal + BufPtr;
62 
63  dods_uint16 align;
64  if (width() > sizeof(align))
65  throw InternalErr(__FILE__, __LINE__, "UInt16 size.");
66 
67  memcpy((void *) &align, (void *) ptr, width());
68 
69  val2buf((void *) &align);
70  set_read_p(true);
71 
72  BufPtr += width();
73 
74  return true;
75  }
76 
77  return false;
78 }
FFUInt16
Definition: FFUInt16.h:39