bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
DODS_Time_Factory.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 1998
27// Please read the full copyright statement in the file COPYRIGHT.
28//
29// Authors:
30// jhrg,jimg James Gallagher (jgallagher@gso.uri.edu)
31
32// Implementation of the DODS_Time_Factory class
33
34#include "config_ff.h"
35
36static char rcsid[] not_used ="$Id$";
37
38
39#include <string>
40
41#include <libdap/AttrTable.h>
42#include <libdap/Error.h>
43#include <libdap/InternalErr.h>
44#include <libdap/dods-datatypes.h>
45#include <libdap/util.h>
46#include "util_ff.h"
47
48#include "DODS_Time_Factory.h"
49
50// attribute_name defaults to "DODS_TIME".
51DODS_Time_Factory::DODS_Time_Factory(DDS &dds, const string &attribute_name)
52{
53 // Read the names of the variables which encode hours, minutes and
54 // seconds from the DAS. These are contained in the DODS_Time attribute
55 // container.
56
57 AttrTable *at = dds.get_attr_table().find_container(attribute_name);
58 if (!at)
59 throw Error(string("DODS_Time_Factory requires that the ")
60 + attribute_name + string(" attribute be present."));
61
62 string hours_name = at->get_attr("hours_variable");
63 string mins_name = at->get_attr("minutes_variable");
64 string secs_name = at->get_attr("seconds_variable");
65 string gmt = at->get_attr("gmt_time");
66
67 // If the gmt attribute is present that meanas that the times are GMT/UTC
68 // times. Set the _gmt flag true, otherwise set it false.
69
70 downcase(gmt);
71 if (gmt == "true")
72 _gmt = true;
73 else
74 _gmt = false;
75
76 // Now check that these variables actually exist and that they have
77 // sensible types.
78
79 _hours = dds.var(hours_name);
80 if (_hours && !is_integer_type(_hours))
81 throw Error("DODS_Time_Factory: The variable used for hours must be an integer.");
82
83 _minutes = dds.var(mins_name);
84 if (_minutes && !is_integer_type(_minutes))
85 throw Error("DODS_Time_Factory: The variable used for minutes must be an integer.");
86
87 _seconds = dds.var(secs_name);
88 if (_seconds && !(is_integer_type(_seconds) || is_float_type(_seconds)))
89 throw Error("DODS_Time_Factory: The variable used for seconds must be an integer.");
90}
91
94{
95 return DODS_Time(get_integer_value(_hours), get_integer_value(_minutes),
96 get_float_value(_seconds), _gmt);
97}
virtual DODS_Time get()