bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
TabularFunction.h
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the BES, A C++ implementation of the OPeNDAP
4// Hyrax data server
5
6// Copyright (c) 2015 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24
25#include <libdap/ServerFunction.h>
26
27namespace libdap {
28class BaseType;
29class Array;
30class DDS;
31}
32
33namespace functions {
34
35class TabularFunction: public libdap::ServerFunction
36{
37private:
38 friend class TabularFunctionTest;
39 friend class Dap4_TabularFunctionTest;
40
41 typedef std::vector< std::vector<libdap::BaseType*> *> SequenceValues;
42 typedef std::vector<unsigned long> Shape;
43
44 static void function_dap2_tabular(int argc, libdap::BaseType *argv[], libdap::DDS &dds, libdap::BaseType **btpp);
45
46#if 0
47 static void function_dap2_tabular_2(int argc, libdap::BaseType *argv[], libdap::DDS &, libdap::BaseType **btpp);
48#endif
49 // These are static so that the code does not have to make a TabularFunction
50 // instance to access them. They are 'in' TabularFunction to control the name
51 // space - they were static functions but that made it impossible to write
52 // unit tests.
53 static Shape array_shape(libdap::Array *a);
54 static bool shape_matches(libdap::Array *a, const Shape &shape);
55 static bool dep_indep_match(const Shape &dep_shape, const Shape &indep_shape);
56
57 static unsigned long number_of_values(const Shape &shape);
58
59 static void build_columns(unsigned long n, libdap::BaseType *btp, std::vector<libdap::Array*> &arrays, Shape &shape);
60
61 static void read_values(const std::vector<libdap::Array*> &arrays);
62
63 static void build_sequence_values(const std::vector<libdap::Array*> &arrays, SequenceValues &sv);
64 static void combine_sequence_values(SequenceValues &dep, const SequenceValues &indep);
65 static void add_index_column(const Shape &indep_shape, const Shape &dep_shape,
66 std::vector<libdap::Array*> &dep_vars);
67
68public:
69 TabularFunction()
70 {
71 setName("tabular");
72 setDescriptionString("The tabular() function transforms one or more arrays into a sequence.");
73 setUsageString("tabular()");
74 setRole("http://services.opendap.org/dap4/server-side-function/tabular");
75 setDocUrl("https://docs.opendap.org/index.php/Server_Side_Processing_Functions#tabular");
76 setFunction(TabularFunction::function_dap2_tabular);
77 // FIXME setFunction(libdap::TabularFunction::function_dap4_tabular);
78 setVersion("1.0");
79 }
80
81 virtual ~TabularFunction()
82 {
83 }
84};
85
86} // functions namespace