29#include <libdap/BaseType.h>
30#include <libdap/Structure.h>
31#include <libdap/Array.h>
32#include <libdap/Int32.h>
33#include <libdap/Str.h>
35#include <libdap/util.h>
58void roi_bbox_valid_slice(BaseType *btp)
61 if (btp->type() != dods_structure_c)
62 throw Error(
"In function roi(): Expected an Array of Structures for the slice information.");
64 Structure *
slice =
static_cast<Structure*
>(btp);
66 Constructor::Vars_iter i =
slice->var_begin();
67 if (i ==
slice->var_end() || (*i)->name() !=
"start" || (*i)->type() != dods_int32_c)
68 throw Error(
"In function roi(): Could not find valid 'start' field in slice information");
71 if (i ==
slice->var_end() || (*i)->name() !=
"stop" || (*i)->type() != dods_int32_c)
72 throw Error(
"In function roi(): Could not find valid 'stop' field in slice information");
75 if (i ==
slice->var_end() || (*i)->name() !=
"name" || (*i)->type() != dods_str_c)
76 throw Error(
"In function roi(): Could not find valid 'name' field in slice information");
92unsigned int roi_valid_bbox(BaseType *btp)
95 throw InternalErr(__FILE__, __LINE__,
"Function called with null slice array.");
97 if (btp->type() != dods_array_c)
98 throw Error(
"Function expected last argument to be a Bounding Box (i.e., an Array of Structures) (1).");
100 Array *slices =
static_cast<Array*
>(btp);
101 if (slices->dimensions() != 1)
102 throw Error(
"Function expected last argument to be a Bounding Box (i.e., an Array of Structures) (2).");
104 int rank = slices->dimension_size(slices->dim_begin());
105 for (
int i = 0; i < rank; ++i) {
106 roi_bbox_valid_slice(slices->var(i));
124void roi_bbox_get_slice_data(Array *slices,
unsigned int i,
int &start,
int &stop,
string &name)
126 BaseType *btp = slices->var(i);
128 Structure *
slice =
static_cast<Structure*
>(btp);
129 Constructor::Vars_iter vi =
slice->var_begin();
131 start =
static_cast<Int32*
>(*vi++)->value();
132 stop =
static_cast<Int32*
>(*vi++)->value();
133 name =
static_cast<Str*
>(*vi++)->value();
155Structure *roi_bbox_build_slice(
unsigned int start_value,
unsigned int stop_value,
const string &dim_name)
157 Structure *
slice =
new Structure(
"slice");
159 Int32 *start =
new Int32(
"start");
160 start->set_value(start_value);
161 slice->add_var_nocopy(start);
163 Int32 *stop =
new Int32(
"stop");
164 stop->set_value(stop_value);
165 slice->add_var_nocopy(stop);
167 Str *name =
new Str(
"name");
168 name->set_value(dim_name);
169 slice->add_var_nocopy(name);
171 slice->set_read_p(
true);
172 slice->set_send_p(
true);
194unique_ptr<Array> roi_bbox_build_empty_bbox(
unsigned int num_dim,
const string &bbox_name)
199 Structure *proto =
new Structure(bbox_name);
200 proto->add_var_nocopy(
new Int32(
"start"));
201 proto->add_var_nocopy(
new Int32(
"stop"));
202 proto->add_var_nocopy(
new Str(
"name"));
205 unique_ptr<Array> response(
new Array(bbox_name, proto));
207 response->append_dim(num_dim, bbox_name);