60#include "D4Attributes.h"
61#include "D4BaseTypeFactory.h"
65#include "InternalErr.h"
85void BaseType::m_duplicate(
const BaseType &bt) {
86 DBG(cerr <<
"In BaseType::m_duplicate for " << bt.name() << endl);
90 d_dataset = bt.d_dataset;
91 d_is_read = bt.d_is_read;
92 d_is_send = bt.d_is_send;
93 d_in_selection = bt.d_in_selection;
94 d_is_synthesized = bt.d_is_synthesized;
96 d_parent = bt.d_parent;
105 d_is_dap4 = bt.d_is_dap4;
107 DBG(cerr <<
"Exiting BaseType::m_duplicate for " << bt.name() << endl);
124BaseType::BaseType(
const string &n,
const Type &t,
bool is_dap4)
125 : d_name(n), d_type(t), d_dataset(
""), d_is_read(false), d_is_send(false), d_parent(0), d_attributes(0),
126 d_is_dap4(is_dap4), d_in_selection(false), d_is_synthesized(false) {}
140BaseType::BaseType(
const string &n,
const string &d,
const Type &t,
bool is_dap4)
141 : d_name(n), d_type(t), d_dataset(d), d_is_read(false), d_is_send(false), d_parent(0), d_attributes(0),
142 d_is_dap4(is_dap4), d_in_selection(false), d_is_synthesized(false) {}
145BaseType::BaseType(
const BaseType ©_from) : DapObj() {
146 DBG(cerr <<
"In BaseTpe::copy_ctor for " << copy_from.name() << endl);
147 m_duplicate(copy_from);
150BaseType::~BaseType() {
151 DBG2(cerr <<
"Entering ~BaseType (" <<
this <<
")" << endl);
156 DBG2(cerr <<
"Exiting ~BaseType" << endl);
170string BaseType::toString() {
172 oss <<
"BaseType (" <<
this <<
"):" << endl
173 <<
" _name: " << name() << endl
175 <<
" _dataset: " << d_dataset << endl
176 <<
" _read_p: " << d_is_read << endl
177 <<
" _send_p: " << d_is_send << endl
178 <<
" _synthesized_p: " << d_is_synthesized << endl
179 <<
" d_parent: " << d_parent << endl
180 <<
" d_attr: " << hex << &d_attr << dec << endl;
200void BaseType::transform_to_dap4(D4Group * , Constructor *container) {
204 dest->attributes()->transform_to_dap4(get_attr_table());
205 dest->set_is_dap4(
true);
207 container->add_var_nocopy(dest);
240std::vector<BaseType *> *BaseType::transform_to_dap2(AttrTable *) {
245 AttrTable *attrs = this->attributes()->get_AttrTable(name());
246 dest->set_attr_table(*attrs);
248 if (dest->get_attr_table().get_size() == 0) {
250 dest->get_attr_table().set_name(name());
254 dest->set_is_dap4(
false);
256 vector<BaseType *> *result =
new vector<BaseType *>();
257 result->push_back(dest);
269void BaseType::dump(ostream &strm)
const {
270 strm << DapIndent::LMarg <<
"BaseType::dump - (" << (
void *)
this <<
")" << endl;
273 strm << DapIndent::LMarg <<
"name: " << name() << endl;
274 strm << DapIndent::LMarg <<
"type: " <<
type_name() << endl;
275 strm << DapIndent::LMarg <<
"dataset: " << d_dataset << endl;
276 strm << DapIndent::LMarg <<
"read_p: " << d_is_read << endl;
277 strm << DapIndent::LMarg <<
"send_p: " << d_is_send << endl;
278 strm << DapIndent::LMarg <<
"synthesized_p: " << d_is_synthesized << endl;
279 strm << DapIndent::LMarg <<
"d_is_dap4: " << d_is_dap4 << endl;
280 strm << DapIndent::LMarg <<
"parent: " << (
void *)d_parent << endl;
281 strm << DapIndent::LMarg <<
"attributes: " << endl;
285 d_attributes->dump(strm);
289 DapIndent::UnIndent();
291 DapIndent::UnIndent();
296string BaseType::name()
const {
return d_name; }
304string BaseType::FQN()
const {
305 if (get_parent() == 0)
307 else if (get_parent()->type() == dods_group_c)
308 return get_parent()->FQN() + name();
310 return get_parent()->FQN() +
"." + name();
314void BaseType::set_name(
const string &n) {
326string BaseType::dataset()
const {
return d_dataset; }
329Type BaseType::type()
const {
return d_type; }
332void BaseType::set_type(
const Type &t) { d_type = t; }
335string BaseType::type_name()
const {
385int BaseType::element_count(
bool) {
return 1; }
390bool BaseType::synthesized_p() {
return d_is_synthesized; }
397void BaseType::set_synthesized_p(
bool state) { d_is_synthesized = state; }
410bool BaseType::read_p() {
return d_is_read; }
442void BaseType::set_read_p(
bool state) {
460 if (!d_is_synthesized) {
478bool BaseType::send_p() {
return d_is_send; }
488void BaseType::set_send_p(
bool state) {
489 DBG2(cerr <<
"Calling BaseType::set_send_p() for: " << this->name() << endl);
498AttrTable &BaseType::get_attr_table() {
return d_attr; }
502void BaseType::set_attr_table(
const AttrTable &at) { d_attr = at; }
507D4Attributes *BaseType::attributes() {
509 d_attributes =
new D4Attributes();
513void BaseType::set_attributes(D4Attributes *attrs) { d_attributes =
new D4Attributes(*attrs); }
515void BaseType::set_attributes_nocopy(D4Attributes *attrs) { d_attributes = attrs; }
544void BaseType::transfer_attributes(AttrTable *at_container) {
546 DBG(cerr << __func__ <<
"() - BEGIN name:'" << name() <<
"'" << endl);
548 AttrTable *at = at_container->get_attr_table(name());
549 DBG(cerr << __func__ <<
"() - at: " << (
void *)at << endl);
552 at->set_is_global_attribute(
false);
553 DBG(cerr << __func__ <<
"() - Processing AttrTable: " << at->get_name() << endl);
555 AttrTable::Attr_iter at_p = at->attr_begin();
556 while (at_p != at->attr_end()) {
557 DBG(cerr << __func__ <<
"() - Attribute '" << at->get_name(at_p) <<
"' is type: " << at->get_type(at_p)
559 if (at->get_attr_type(at_p) == Attr_container) {
568 BaseType *bt =
var(at->get_name(at_p),
true);
570 DBG(cerr << __func__ <<
"() - Adding container '" << at->get_name(at_p) << endl);
571 get_attr_table().
append_container(
new AttrTable(*at->get_attr_table(at_p)), at->get_name(at_p));
573 DBG(cerr << __func__ <<
"() - Found child var: '" << bt->type_name() <<
" " << bt->name()
574 <<
" (address:" << (
void *)bt <<
")" << endl);
575 DBG(cerr << __func__ <<
"() - Skipping container '" << at->get_name(at_p) << endl);
578 DBG(cerr << __func__ <<
"() - Adding Attribute '" << at->get_name(at_p) << endl);
579 get_attr_table().
append_attr(at->get_name(at_p), at->get_type(at_p), at->get_attr_vector(at_p),
580 (*at_p)->is_utf8_str);
585 DBG(cerr << __func__ <<
"() - Unable to locate AttrTable '" << name() <<
"' SKIPPING" << endl);
600bool BaseType::is_in_selection() {
return d_in_selection; }
611void BaseType::set_in_selection(
bool state) { d_in_selection = state; }
622void BaseType::set_parent(
BaseType *parent) {
623 if (!
dynamic_cast<Constructor *
>(parent) && !
dynamic_cast<Vector *
>(parent) && parent != 0)
624 throw InternalErr(
"Call to set_parent with incorrect variable type.");
636BaseType *BaseType::get_parent()
const {
return d_parent; }
640 return d_parent->get_ancestor();
646BaseType *BaseType::var(
const string & ,
bool , btp_stack * ) {
647 return static_cast<BaseType *
>(0);
666BaseType *BaseType::var(
const string &, btp_stack &) {
return static_cast<BaseType *
>(0); }
697void BaseType::add_var(
BaseType *, Part) {
throw InternalErr(__FILE__, __LINE__,
"BaseType::add_var unimplemented"); }
699void BaseType::add_var_nocopy(
BaseType *, Part) {
700 throw InternalErr(__FILE__, __LINE__,
"BaseType::add_var_nocopy unimplemented");
775bool BaseType::read() {
779 throw InternalErr(
"Unimplemented BaseType::read() method called for the variable named: " + name());
782void BaseType::intern_data(ConstraintEvaluator &, DDS & ) {
783#if USE_LOCAL_TIMEOUT_SCHEME
787 throw Error(
string(
"A method usable only with DAP2 variables was called on a DAP4 variable (")
792 DBG2(cerr <<
"BaseType::intern_data: " << name() << endl);
795#if USE_LOCAL_TIMEOUT_SCHEME
805void BaseType::intern_data() {
810bool BaseType::serialize(ConstraintEvaluator &, DDS &, Marshaller &,
bool) {
811 throw InternalErr(__FILE__, __LINE__,
"The DAP2 serialize() method has not been implemented for " +
type_name());
814bool BaseType::deserialize(UnMarshaller &, DDS *,
bool) {
815 throw InternalErr(__FILE__, __LINE__,
"The DAP2 deserialize() method has not been implemented for " +
type_name());
818void BaseType::serialize(D4StreamMarshaller &, DMR &,
bool) {
819 throw InternalErr(__FILE__, __LINE__,
"The DAP4 serialize() method has not been implemented for " +
type_name());
822void BaseType::deserialize(D4StreamUnMarshaller &, DMR &) {
823 throw InternalErr(__FILE__, __LINE__,
"The DAP4 deserialize() method has not been implemented for " +
type_name());
868void BaseType::print_decl(FILE *out,
string space,
bool print_semi,
bool constraint_info,
bool constrained) {
870 print_decl(oss, space, print_semi, constraint_info, constrained);
871 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
916void BaseType::print_decl(ostream &out,
string space,
bool print_semi,
bool constraint_info,
bool constrained) {
919 if (constrained && !
send_p())
924 if (constraint_info) {
926 out <<
": Send True";
928 out <<
": Send False";
949void BaseType::print_val(FILE *out,
string space,
bool print_decl_p) {
952 fwrite(oss.str().data(),
sizeof(
char), oss.str().length(), out);
962void BaseType::print_xml(FILE *out,
string space,
bool constrained) {
963 XMLWriter xml(space);
964 print_xml_writer(xml, constrained);
965 fwrite(xml.get_doc(),
sizeof(
char), xml.get_doc_size(), out);
975void BaseType::print_xml(ostream &out,
string space,
bool constrained) {
976 XMLWriter xml(space);
977 print_xml_writer(xml, constrained);
978 out << xml.get_doc();
987void BaseType::print_xml_writer(XMLWriter &xml,
bool constrained) {
988 if (constrained && !
send_p())
991 if (xmlTextWriterStartElement(xml.get_writer(), (
const xmlChar *)
type_name().c_str()) < 0)
992 throw InternalErr(__FILE__, __LINE__,
"Could not write " +
type_name() +
" element");
995 if (xmlTextWriterWriteAttribute(xml.get_writer(), (
const xmlChar *)
"name", (
const xmlChar *)name().c_str()) < 0)
996 throw InternalErr(__FILE__, __LINE__,
"Could not write attribute for name");
999 attributes()->print_dap4(xml);
1001 if (!is_dap4() && get_attr_table().get_size() > 0)
1004 if (xmlTextWriterEndElement(xml.get_writer()) < 0)
1005 throw InternalErr(__FILE__, __LINE__,
"Could not end " +
type_name() +
" element");
1015void BaseType::print_dap4(XMLWriter &xml,
bool constrained) { print_xml_writer(xml, constrained); }
1056bool BaseType::check_semantics(
string &msg,
bool) {
1057 bool sem = (d_type != dods_null_c && name().length());
1060 msg =
"Every variable must have both a name and a type\n";
1101bool BaseType::ops(
BaseType *,
int) {
1106 throw InternalErr(__FILE__, __LINE__,
"Unimplemented operator.");
1125bool BaseType::d4_ops(
BaseType *,
int) {
throw InternalErr(__FILE__, __LINE__,
"Unimplemented operator."); }
1138unsigned int BaseType::width(
bool )
const {
throw InternalErr(__FILE__, __LINE__,
"not implemented"); }
1140int64_t BaseType::width_ll(
bool )
const {
throw InternalErr(__FILE__, __LINE__,
"not implemented"); }
1148bool BaseType::is_dap4_projected(std::vector<string> &inventory) {
1149 bool has_projected_dap4 =
false;
1151 has_projected_dap4 = attributes()->
has_dap4_types(FQN(), inventory);
1153 return has_projected_dap4;
Contains the attributes for a dataset.
virtual AttrTable * append_container(const string &name)
Add a container to the attribute table.
virtual unsigned int append_attr(const string &name, const string &type, const string &value)
Add an attribute to the table.
void print_xml_writer(XMLWriter &xml)
void transform_attrs_to_dap2(AttrTable *d2_attr_table)
Copy the attributes from this D4Attributes object to a DAP2 AttrTable.
bool has_dap4_types(const std::string &path, std::vector< std::string > &inventory) const
top level DAP object to house generic methods
virtual BaseType * ptr_duplicate()=0
Type
Identifies the data type.
virtual bool is_simple_type() const
Returns true if the instance is a numeric, string or URL type variable.
virtual bool read_p()
Has this variable been read?
virtual string type_name() const
Returns the type of the class instance as a string.
virtual BaseType * var(const string &name="", bool exact_match=true, btp_stack *s=nullptr)
Returns a pointer to a member of a constructor class.
string www2id(const string &in, const string &escape, const string &except)
virtual bool send_p()
Should this variable be sent?
string D2type_name(Type t)
Returns the type of the class instance as a string. Supports all DAP2 types and not the DAP4-only typ...
string D4type_name(Type t)
Returns the type of the class instance as a string. Supports all DAP4 types and not the DAP2-only typ...
virtual void print_val(FILE *out, string space="", bool print_decl_p=true)
Prints the value of the variable.
virtual bool is_constructor_type() const
Returns true if the instance is a constructor (i.e., Structure, Sequence or Grid) type variable.
virtual bool is_vector_type() const
Returns true if the instance is a vector (i.e., array) type variable.
string id2www(string in, const string &allowable)