File: BaseType.cc

package info (click to toggle)
libdap 3.20.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 24,568 kB
  • sloc: cpp: 50,809; sh: 41,536; xml: 23,511; ansic: 20,030; yacc: 2,508; exp: 1,544; makefile: 990; lex: 309; perl: 52; fortran: 8
file content (1300 lines) | stat: -rw-r--r-- 47,755 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300

// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// (c) COPYRIGHT URI/MIT 1994-1999
// Please read the full copyright statement in the file COPYRIGHT_URI.
//
// Authors:
//      jhrg,jimg       James Gallagher <jgallagher@gso.uri.edu>

// Implementation for BaseType.
//
// jhrg 9/6/94

#include "config.h"

#include <cstdio>  // for stdin and stdout

#include <sstream>
#include <string>

//#define DODS_DEBUG

#include "BaseType.h"
#include "Byte.h"
#include "Int16.h"
#include "UInt16.h"
#include "Int32.h"
#include "UInt32.h"
#include "Float32.h"
#include "Float64.h"
#include "Str.h"
#include "Url.h"
#include "Array.h"
#include "Structure.h"
#include "Sequence.h"
#include "Grid.h"

#include "D4Attributes.h"
#include "DMR.h"
#include "XMLWriter.h"
#include "D4BaseTypeFactory.h"

#include "InternalErr.h"

#include "util.h"
#include "escaping.h"
#include "DapIndent.h"

#include "debug.h"

using namespace std;

namespace libdap {

// Protected copy mfunc

/** Perform a deep copy. Copies the values of \e bt into \c *this. Pointers
    are dereferenced and their values are copied into a newly allocated
    instance.

    @brief Perform a deep copy.
    @param bt The source object. */
void
BaseType::m_duplicate(const BaseType &bt)
{
    DBG(cerr << "In BaseType::m_duplicate for " << bt.name() << endl);

    d_name = bt.d_name;
    d_type = bt.d_type;
    d_dataset = bt.d_dataset;
    d_is_read = bt.d_is_read; // added, reza
    d_is_send = bt.d_is_send; // added, reza
    d_in_selection = bt.d_in_selection;
    d_is_synthesized = bt.d_is_synthesized; // 5/11/2001 jhrg

    d_parent = bt.d_parent; // copy pointers 6/4/2001 jhrg

    d_attr = bt.d_attr;  // Deep copy.

    if (bt.d_attributes)
        d_attributes = new D4Attributes(*bt.d_attributes); // deep copy
    else
        d_attributes = 0; // init to null if not used.

    d_is_dap4 = bt.d_is_dap4;

    DBG(cerr << "Exiting BaseType::m_duplicate for " << bt.name() << endl);
}

// Public mfuncs

/** The BaseType constructor needs a name  and a type.
    The BaseType class exists to provide data to
    type classes that inherit from it.  The constructors of those
    classes call the BaseType constructor; it is never called
    directly.

    @brief The BaseType constructor.

    @param n A string containing the name of the new variable.
    @param t The type of the variable.
    @param is_dap4 True if this is a DAP4 variable. Default is False
    @see Type */
BaseType::BaseType(const string &n, const Type &t, bool is_dap4)
: d_name(n), d_type(t), d_dataset(""), d_is_read(false), d_is_send(false),
  d_parent(0), d_attributes(0), d_is_dap4(is_dap4),
  d_in_selection(false), d_is_synthesized(false)
{}

/** The BaseType constructor needs a name, a dataset, and a type.
    The BaseType class exists to provide data to
    type classes that inherit from it.  The constructors of those
    classes call the BaseType constructor; it is never called
    directly.

    @brief The BaseType constructor.
    @param n A string containing the name of the new variable.
    @param d A string containing the dataset name.
    @param t The type of the variable. Default is False
    @param is_dap4 True if this is a DAP4 variable.
    @see Type */
BaseType::BaseType(const string &n, const string &d, const Type &t, bool is_dap4)
: d_name(n), d_type(t), d_dataset(d), d_is_read(false), d_is_send(false),
  d_parent(0), d_attributes(0), d_is_dap4(is_dap4),
  d_in_selection(false), d_is_synthesized(false)
{}

/** @brief The BaseType copy constructor. */
BaseType::BaseType(const BaseType &copy_from) : DapObj()
{
    DBG(cerr << "In BaseTpe::copy_ctor for " << copy_from.name() << endl);
    m_duplicate(copy_from);
}

BaseType::~BaseType()
{
    DBG2(cerr << "Entering ~BaseType (" << this << ")" << endl);

    if (d_attributes)
        delete d_attributes;

    DBG2(cerr << "Exiting ~BaseType" << endl);
}

BaseType &
BaseType::operator=(const BaseType &rhs)
{
    if (this == &rhs)
        return *this;
    m_duplicate(rhs);
    return *this;
}

/** Write out the object's internal fields in a string. To be used for
    debugging when regular inspection w/ddd or gdb isn't enough.

    @return A string which shows the object's internal stuff. */
string BaseType::toString()
{
    ostringstream oss;
    oss << "BaseType (" << this << "):" << endl
        << "          _name: " << name() << endl
        << "          _type: " << type_name() << endl
        << "          _dataset: " << d_dataset << endl
        << "          _read_p: " << d_is_read << endl
        << "          _send_p: " << d_is_send << endl
        << "          _synthesized_p: " << d_is_synthesized << endl
        << "          d_parent: " << d_parent << endl
        << "          d_attr: " << hex << &d_attr << dec << endl;

    return oss.str();
}

/** @brief DAP2 to DAP4 transform
 *
 * For the current BaseType, return a DAP4 'copy' of the variable.
 *
 * @note For most DAP2 types, in this implementation of DAP4 the corresponding
 * DAP4 type is the same. The different types are Sequences (which are D4Sequences
 * in the DAP4 implementation), Grids (which are coverages) and Arrays (which use
 * shared dimensions).
 *
 * @param root The root group that should hold this new variable. Add Group-level
 * stuff here (e.g., D4Dimensions).
 * @param container Add the new variable to this container.
 *
 * @return A pointer to the transformed variable
 */
void
BaseType::transform_to_dap4(D4Group */*root*/, Constructor *container)
{
    BaseType *dest = ptr_duplicate();
    // If it's already a DAP4 object then we can just return it!
    if(!is_dap4()){
        dest->attributes()->transform_to_dap4(get_attr_table());
        dest->set_is_dap4(true);
    }
    container->add_var_nocopy(dest);
}


/** @brief DAP4 to DAP2 transform
 *
 * For the current BaseType, return a DAP2 'copy' of the variable.
 *
 * @note For most DAP4 types, in this implementation of DAP2 the corresponding
 * DAP4 type is the same.
 * These types have a different representations in DAP2 and DAP4:
 *  Sequences (which are D4Sequences in the DAP4 implementation),
 *  - Grids (which are semantically subsumed by coverages in DAP4)
 *  - Arrays (which use shared dimensions in DAP4)
 *
 *  Additionally DAP4 adds the following types:
 *  - UInt8, Int8, and Char which map to Byte in DAP2.
 *  - Int64, Unit64 which have no natural representation in DAP2.
 *  - Opaque Possible Byte stuff[] plus metadata?
 *  - Enum's can be represented as Int32.
 *
 *  - Groups, with the exception of the root group "disappear" into the
 *    names of their member variables. Specifically the Group name is add as a prefix
 *    followed by a "/" separator to the names of all of the Group's member groups
 *    variables.
 *
 * @param  The AttrTable pointer parent_attr_table is used by Groups, which disappear
 * from the DAP2 representation. Their children are returned in the the BAseType vector
 * their attributes are added to parent_attr_table;
 * @return A pointer to a vector of BaseType pointers (right?). In most cases this vector
 * will contain a single pointer but DAP4 types 'disappear' such as Group will return all
 * of their member variables in the vector. DAP4 types with no representation in DAP2
 * (ex: UInt64) the will return a NULL pointer and so this must be tested!
 */
std::vector<BaseType *> *
BaseType::transform_to_dap2(AttrTable *)
{
    BaseType *dest = this->ptr_duplicate();
    // convert the d4 attributes to a dap2 attribute table.
    // HK-403. jhrg 6/17/19
#if 0
    AttrTable *attrs = this->attributes()->get_AttrTable(name());
    dest->set_attr_table(*attrs);
#else
    if (dest->get_attr_table().get_size() == 0) {
        attributes()->transform_attrs_to_dap2(&dest->get_attr_table());
        dest->get_attr_table().set_name(name());
    }
#endif

    dest->set_is_dap4(false);

    vector<BaseType *> *result =  new vector<BaseType *>();
    result->push_back(dest);
    return result;
}


/** @brief dumps information about this object
 *
 * Displays the pointer value of this instance and then displays information
 * about this base type.
 *
 * @param strm C++ i/o stream to dump the information to
 * @return void
 */
void
BaseType::dump(ostream &strm) const
{
    strm << DapIndent::LMarg << "BaseType::dump - ("
        << (void *)this << ")" << endl ;
    DapIndent::Indent() ;

    strm << DapIndent::LMarg << "name: " << name() << endl ;
    strm << DapIndent::LMarg << "type: " << type_name() << endl ;
    strm << DapIndent::LMarg << "dataset: " << d_dataset << endl ;
    strm << DapIndent::LMarg << "read_p: " << d_is_read << endl ;
    strm << DapIndent::LMarg << "send_p: " << d_is_send << endl ;
    strm << DapIndent::LMarg << "synthesized_p: " << d_is_synthesized << endl ;
    strm << DapIndent::LMarg << "parent: " << (void *)d_parent << endl ;
    strm << DapIndent::LMarg << "attributes: " << endl ;
    DapIndent::Indent() ;

    if (d_attributes)
        d_attributes->dump(strm);
    else
        d_attr.dump(strm) ;

    DapIndent::UnIndent() ;

    DapIndent::UnIndent() ;
}

/** @brief Returns the name of the class instance.
 */
string
BaseType::name() const
{
    return d_name;
}

/**
 * Return the FQN for this variable. This will include the D4 Group
 * component of the name.
 *
 * @return The FQN in a string
 */
string
BaseType::FQN() const
{
    if (get_parent() == 0)
        return name();
    else if (get_parent()->type() == dods_group_c)
        return get_parent()->FQN() + name();
    else
        return get_parent()->FQN() + "." + name();
}

/** @brief Sets the name of the class instance. */
void
BaseType::set_name(const string &n)
{
    string name = n;
    d_name = www2id(name); // www2id writes into its param.
}

/** @brief Returns the name of the dataset used to create this instance

    A dataset from which the data is to be read. The meaning of this string
    will vary among different types of data sources. It \e may be the name
    of a data file or an identifier used to read data from a relational
    database.
 */
string
BaseType::dataset() const
{
    return d_dataset;
}

/** @brief Returns the type of the class instance. */
Type
BaseType::type() const
{
    return d_type;
}

/** @brief Sets the type of the class instance. */
void
BaseType::set_type(const Type &t)
{
    d_type = t;
}

/** @brief Returns the type of the class instance as a string. */
string
BaseType::type_name() const
{
    if (is_dap4())
        return libdap::D4type_name(d_type);
    else
        return libdap::D2type_name(d_type);
}

/** @brief Returns true if the instance is a numeric, string or URL
    type variable.
    @return True if the instance is a scalar numeric, String or URL variable,
    False otherwise. Arrays (even of simple types) return False.
    @see is_vector_type() */
bool
BaseType::is_simple_type() const
{
    return libdap::is_simple_type(type());
}

/** @brief Returns true if the instance is a vector (i.e., array) type
    variable.
    @return True if the instance is an Array, False otherwise. */
bool
BaseType::is_vector_type() const
{
    return libdap::is_vector_type(type());
}

/** @brief Returns true if the instance is a constructor (i.e., Structure,
    Sequence or Grid) type variable.
    @return True if the instance is a Structure, Sequence or Grid, False
    otherwise. */
bool
BaseType::is_constructor_type() const
{
    return libdap::is_constructor_type(type());
}

/** Return a count of the total number of variables in this variable.
    This is used to count the number of variables held by a constructor
    variable - for simple type and vector variables it always
    returns 1.

    For compound data types, there are two ways to count members.
    You can count the members, or you can count the simple members
    and add that to the count of the compound members.  For
    example, if a Structure contains an Int32 and another
    Structure that itself contains two Int32 members, the element
    count of the top-level structure could be two (one Int32 and
    one Structure) or three (one Int32 by itself and two Int32's
    in the subsidiary Structure).  Use the <i>leaves</i> parameter
    to control which kind of counting you desire.

    @brief Count the members of constructor types.
    @return Returns 1 for simple
    types.  For compound members, the count depends on the
    <i>leaves</i> argument.
    @param leaves This parameter is only relevant if the object
    contains other compound data types.  If FALSE, the function
    counts only the data variables mentioned in the object's
    declaration.  If TRUE, it counts the simple members, and adds
    that to the sum of the counts for the compound members.
    This parameter has no effect for simple type variables. */
int
BaseType::element_count(bool)
{
    return 1;
}

/** Returns true if the variable is a synthesized variable. A synthesized
    variable is one that is added to the dataset by the server (usually
    with a `projection function'. */
bool
BaseType::synthesized_p()
{
    return d_is_synthesized;
}

/** Set the synthesized flag. Before setting this flag be sure to set the
    <tt>read_p()</tt> state. Once this flag is set you cannot
    alter the state of the <tt>read_p</tt> flag!

    @see synthesized_p() */
void
BaseType::set_synthesized_p(bool state)
{
    d_is_synthesized = state;
}

// Return the state of d_is_read (true if the value of the variable has been
// read (and is in memory) false otherwise).

/** Returns true if the value(s) for this variable have been read from the
    data source, otherwise returns false. This method is used to determine
    when values need to be read using the read() method. When read_p()
    returns true, this library assumes that buf2val() (and other methods
    such as get_vec()) can be used to access the value(s) of a variable.

    @brief Has this variable been read?
    @return True if the variable's value(s) have been read, false otherwise. */
bool
BaseType::read_p()
{
    return d_is_read;
}

/** Sets the value of the <tt>read_p</tt> property. This indicates that the
    value(s) of this variable has/have been read. An implementation of the
    read() method should use this to set the \c read_p property to true.

    @note If the is_synthesized property is true, this method will _not_
    alter the is_read property. If you need that behavior, specialize the
    method in your subclasses if the various types.

    @note For most of the types the default implementation of this method is
    fine. However, if you're building a server which must handle data
    represented using nested sequences, then you may need to provide a
    specialization of Sequence::set_read_p(). By default Sequence::set_read_p()
    recursively sets the \e read_p property for all child variables to
    \e state. For servers where one Sequence reads an outer set of values
    and another reads an inner set, this is cumbersome. In such a case, it is
    easier to specialize Sequence::set_read_p() so that it does \e not
    recursively set the \e read_p property for the inner Sequence. Be sure
    to see the documentation for the read() method!

    @todo Look at making synthesized variables easier to implement and at
    making them more integrated into the overall CE evaluation process.
    Maybe the code that computes the synthesized var's value should be in the
    that variable's read() method? This might provide a way to get rid of the
    awkward 'projection functions' by replacing them with real children of
    BaseType. It would also provide a way to clean up the way the
    \e synthesized_p prop intrudes on the \e read_p prop.

    @see BaseType::read()
    @brief Sets the value of the \e read_p property.
    @param state Set the \e read_p property to this state. */
void
BaseType::set_read_p(bool state)
{
    // The this comment is/was wrong!
    // The is_synthesized property was not being used and the more I thought
    // about how this was coded, the more this code below seemed like a bad idea.
    // Once the property was set, the read_p property could not be changed.
    // That seems a little silly. Also, I think I need to use this is_synthesized
    // property for some of the server function code I'm working on for Raytheon,
    // and I'd like to be able to control the read_p property! jhrg 3/9/15

    // What's true: The is_synthesized property is used by
    // 'projection functions' in the freeform handler. It might be better
    // to modify the FFtypes to support this behavior, but for now I'm returning
    // the library to its old behavior. That this change (setting is_read
    // of the value of is_syn...) broke the FF handler was not detected
    // because the FF tests were not being run due to an error in the FF
    // bes-testsuite Makefile.am). jhrg 9/9/15

#if 1
    if (!d_is_synthesized) {
        d_is_read = state;
    }
#else
    d_is_read = state;
#endif
}

/** Returns the state of the \c send_p property. If true, this variable
    should be sent to the client, if false, it should not. If no constraint
    expression (CE) has been evaluated, this property is true for all
    variables in a data source (i.e., for all the variables listed in a DDS).
    If a CE has been evaluated, this property is true only for those
    variables listed in the <em>projection part</em> of the CE.

    @brief Should this variable be sent?
    @return True if the variable should be sent to the client, false
    otherwise. */
bool
BaseType::send_p()
{
    return d_is_send;
}

/** Sets the value of the <tt>send_p</tt> flag.  This
    function is meant to be called from within the constraint evaluator of
    other code which determines that this variable should be returned to the
    client.  Data are ready to be sent when <i>both</i> the <tt>d_is_send</tt>
    and <tt>d_is_read</tt> flags are set to TRUE.

    @param state The logical state to set the <tt>send_p</tt> flag.
 */
void
BaseType::set_send_p(bool state)
{
    DBG2(cerr << "Calling BaseType::set_send_p() for: " << this->name()
        << endl);
    d_is_send = state;
}


/** Get this variable's AttrTable. It's generally a bad idea to return a
    reference to a contained object, but in this case it seems that building
    an interface inside BaseType is overkill.

    Use the AttrTable methods to manipulate the table. */
AttrTable &
BaseType::get_attr_table()
{
    return d_attr;
}

/** Set this variable's attribute table.
    @param at Source of the attributes. */
void
BaseType::set_attr_table(const AttrTable &at)
{
    d_attr = at;
}

/** DAP4 Attribute methods
 * @{
 */
D4Attributes *
BaseType::attributes()
{
    if (!d_attributes) d_attributes = new D4Attributes();
    return d_attributes;
}

void
BaseType::set_attributes(D4Attributes *attrs)
{
    d_attributes = new D4Attributes(*attrs);
}

void
BaseType::set_attributes_nocopy(D4Attributes *attrs)
{
    d_attributes = attrs;
}
///@}

/**
 * Transfer attributes from a DAS object into this variable. Because of the
 * rough history of the DAS object and the way that various server code built
 * the DAS, this is necessarily a heuristic process. The intent is that this
 * method will be overridden by handlers that need to look for certain patterns
 * in the DAS (e.g., hdf4's odd variable_dim_n; where n = 0, 1, 2, ...)
 * attribute containers.
 *
 * There should be a one-to-one
 * mapping between variables and attribute containers. However, in some cases
 * one variable has attributes spread across several top level containers and
 * in some cases one container is used by several variables
 *
 * @note This method is technically \e unnecessary because a server (or
 * client) can easily add attributes directly using the DDS::get_attr_table
 * or BaseType::get_attr_table methods and then poke values in using any
 * of the methods AttrTable provides. This method exists to ease the
 * transition to DDS objects which contain attribute information for the
 * existing servers (Since they all make DAS objects separately from the
 * DDS). They could be modified to use the same AttrTable methods but
 * operate on the AttrTable instances in a DDS/BaseType instead of those in
 * a DAS.
 *
 * @param at_container Transfer attributes from this container.
 * @return void
 */
void BaseType::transfer_attributes(AttrTable *at_container) {

    DBG(cerr << __func__ << "() -  BEGIN name:'" << name() << "'" << endl);

    AttrTable *at = at_container->get_attr_table(name());
    DBG(cerr << __func__ << "() - at: "<< (void *) at << endl);


    if (at) {
        at->set_is_global_attribute(false);
        DBG(cerr << __func__ << "() - Processing AttrTable: " << at->get_name() << endl);

        AttrTable::Attr_iter at_p = at->attr_begin();
        while (at_p != at->attr_end()) {
            DBG(cerr << __func__ << "() -  Attribute '" << at->get_name(at_p) << "' is type: " << at->get_type(at_p) << endl);
            if (at->get_attr_type(at_p) == Attr_container){
                // An attribute container may actually represent a child member variable. When
                // that's the case we don't want to add the container to the parent type, but
                // rather let any child of BaseType deal with those containers in the child's
                // overridden transfer_attributes() method.
                // We capitalize on the magic of the BaseType API and utilize the var() method
                // to check for a child variable of the same name and, if one exists, we'll skip
                // this AttrTable and let a child constructor class like Grid or Constructor
                // deal with it.
                BaseType *bt = var(at->get_name(at_p),true);
                if(bt==0){
                    DBG(cerr << __func__ << "() - Adding container '" << at->get_name(at_p) << endl);
                    get_attr_table().append_container(new AttrTable(*at->get_attr_table(at_p)), at->get_name(at_p));
                }
                else {
                    DBG(cerr << __func__ << "() - Found child var: '"<< bt->type_name()<< " " << bt->name() << " (address:" << (void *) bt << ")" << endl);
                    DBG(cerr << __func__ << "() -  Skipping container '" << at->get_name(at_p) << endl);
                }
            }
            else {
                DBG(cerr << __func__ << "() - Adding Attribute '" << at->get_name(at_p) << endl);
                get_attr_table().append_attr(at->get_name(at_p), at->get_type(at_p), at->get_attr_vector(at_p));
            }
            at_p++;
        }
    }
    else {
        DBG(cerr << __func__ << "() - Unable to locate AttrTable '" << name() << "'  SKIPPING" << endl);

    }
}

/** Does this variable appear in either the selection part or as a function
    argument in the current constrain expression. If this property is set
    (true) then implementations of the read() method should read this
    variable.

    @note This method does not check, nor does it know about the semantics of,
    string arguments passed to functions. Those functions might include
    variable names in strings; they are responsible for reading those variables.
    See the grid (func_grid_select()) for an example.
    @see BaseType::read()
    @brief Is this variable part of the current selection? */
bool
BaseType::is_in_selection()
{
    return d_in_selection;
}

/** Set the \e in_selection property to \e state. This property indicates
    that the variable is used as a parameter to a constraint expression
    function or that it appears as an argument in a selection sub-expression.
    If set (true), implementations of the BaseType::read() method should read
    this variable.

    @param state Set the \e in_selection property to this state.
    @see BaseType::read()
    @see BaseType::is_in_selection() for more information. */
void
BaseType::set_in_selection(bool state)
{
    d_in_selection = state;
}

// Protected method.
/** Set the <tt>parent</tt> property for this variable.

    @note Added ability to set parent to null. 10/19/12 jhrg

    @param parent Pointer to the Constructor of Vector parent variable or null
    if the variable has no parent (if it is at the top-level of a DAP2/3 DDS).
    @exception InternalErr thrown if called with anything other than a
    Constructor, Vector or Null. */
void
BaseType::set_parent(BaseType *parent)
{
    if (!dynamic_cast<Constructor *>(parent)
        && !dynamic_cast<Vector *>(parent)
        && parent != 0)
        throw InternalErr("Call to set_parent with incorrect variable type.");

    d_parent = parent;
}

// Public method.

/** Return a pointer to the Constructor or Vector which holds (contains)
    this variable. If this variable is at the top level, this method
    returns null.

    @return A BaseType pointer to the variable's parent. */
BaseType *
BaseType::get_parent() const
{
    return d_parent;
}

// Documented in the header file.
BaseType *
BaseType::var(const string &/*name*/, bool /*exact_match*/, btp_stack */*s*/)
{
    return static_cast<BaseType *>(0);
}

/** This version of var(...) searches for <i>name</i> and returns a
    pointer to the BaseType object if found. It uses the same search
    algorithm as BaseType::var(const string &, bool, btp_stack *) when
    <i>exact_match</i> is false. In addition to returning a pointer to
    the variable, it pushes onto <i>s</i> a BaseType pointer to each
    constructor type that ultimately contains <i>name</i>.

    @note The BaseType implementation always returns null. There are no default
    values for the parameters. If var() is called w/o any params, the three
    parameter version will be used.

    @deprecated This method is deprecated because it tries first to use
    exact_match and, if that fails, then tries leaf_match. It's better to use
    the alternate form of var(...) and specify exactly what you'd like to do.

    @return A pointer to the named variable. */
BaseType *
BaseType::var(const string &, btp_stack &)
{
    return static_cast<BaseType *>(0);
}

/** Adds a variable to an instance of a constructor class, such as Array,
    Structure <em>et cetera</em>. This function is only used by those
    classes. For constructors with more than one variable, the variables
    appear in the same order in which they were added (i.e., the order in
    which add_var() was called). Since this method is only for use by Vectors
    and Constructors, the BaseType implementation throws InternalErr.

    @note For the implementation of this method in Structure, Sequence, et c.,
    first copy \e bt and then insert the copy. If \e bt is itself a constructor
    type you must either use the var() method to get a pointer to the actual
    instance added to \c *this or you must first add all of <em>bt</em>'s
    children to it before adding it to \c *this. The implementations should use
    m_duplicate() to perform a deep copy of \e bt.

    @brief Add a variable.

    @todo We should get rid of the Part parameter and adopt the convention
    that the first variable is the Array and all subsequent ones are Maps
    (when dealing with a Grid, the only time Part matters). This would enable
    several methods to migrate from Structure, Sequence and Grid to
    Constructor.

    @param bt The variable to be added to this instance. The caller of this
    method <i>must</i> free memory it allocates for <tt>v</tt>. This method
    will make a deep copy of the object pointed to by <tt>v</tt>.
    @param part The part of the constructor data to be modified. Only
    meaningful for Grid variables.

    @see Part */
void
BaseType::add_var(BaseType *, Part)
{
    throw InternalErr(__FILE__, __LINE__, "BaseType::add_var unimplemented");
}

void
BaseType::add_var_nocopy(BaseType *, Part)
{
    throw InternalErr(__FILE__, __LINE__, "BaseType::add_var_nocopy unimplemented");
}

/** This method should be implemented for each of the data type classes (Byte,
    ..., Grid) when using the DAP class library to build a server. This
    method is only for DAP servers. The library provides a default
    definition here which throws an InternalErr exception \e unless the read_p
    property has been set. In that case it returns false, indicating that all
    the data have been read. The latter case can happen when building a
    constant value that needs to be passed to a function. The variable/constant
    is loaded with a value when it is created.

    When implementing a new DAP server, the Byte, ..., Grid data type classes
    are usually specialized. In each of those specializations read() should
    be defined to read values from the data source and store them in the
    object's local buffer. The read() method is called by other methods in
    this library. When writing read(), follow these rules:

    <ul>
    <li> read() should throw Error if it encounters an error. The message
   should be verbose enough to be understood by someone running a
   client on a different machine.</li>
    <li> The value(s) should be read if and only if either send_p() or
          is_in_selection() return true. If neither of these return true, the
   value(s) should not be read. This is important when writing read()
   for a Constructor type such as Grid where a client may ask for only
   the map vectors (and thus reading the much larger Array part is not
   needed).</li>
    <li> For each specialization of read(), the method should first test
          the value of the \c read_p property (using the read_p() method)
          and read values only if the value of read_p() is false. Once the
          read() method reads data and stores it in the instance, it must
          set the value of the \c read_p property to true using set_read_p().
          If your read() methods fail to do this data may not serialize
          correctly.</li>
    <li> The Array::read() and Grid::read() methods should take into account
   any restrictions on Array sizes.</li>
    <li> If you are writing Sequence::read(), be sure to check the
          documentation for Sequence::read_row() and Sequence::serialize()
          so you understand how Sequence::read() is being called.</li>
    <li> For Sequence::read(), your specialization must correctly manage the
          \c unsent_data property and row count in addition to the \c read_p
          property (handle the \c read_p property as describe above). For a
          Sequence to serialize correctly, once all data from the Sequence
          has been read, \c unsent_data property must be set to false (use
          Sequence::set_unsent_data()). Also, at that time the row number
          counter must be reset (use Sequence::reset_row_counter()). Typically
          the correct time to set \c unsent_data to false and reset the row
          counter is the time when Sequence::read() return false indicating
          that all the data for the Sequence have been read. Failure to
          handle these tasks will break serialization of nested Sequences. Note
          that when Sequence::read() returns with a result of true (indicating
          there is more data to send, the value of the \c unsent_data property
          should be true.

          Also, if you server must handle nested sequences, be sure to read
          about subclassing set_read_p().</li>
    </ul>

    @brief Read data into a local buffer.

	@todo Modify the D4 serialize code so that it supports the true/false
	behavior of read() for arrays.

	@todo Modify all of the stock handlers so they conform to this!

    @return False means more data remains to be read, True indicates that no
    more data need to be read. For Sequence and D4Sequence, this method will
    generally read one instance of the Sequence; for other types it will generally
    read the entire variable modulo any limitations due to a constraint. However,
    the library should be written so that read can return less than all of the data
    for a variable - serialize() would then call the function until it returns
    True.

    @see BaseType */
bool
BaseType::read()
{
    if (d_is_read)
        return true;

    throw InternalErr("Unimplemented BaseType::read() method called for the variable named: " + name());
}

void
BaseType::intern_data(ConstraintEvaluator &, DDS &/*dds*/)
{
#if USE_LOCAL_TIMEOUT_SCHEME
    dds.timeout_on();
#endif
    DBG2(cerr << "BaseType::intern_data: " << name() << endl);
    if (!read_p())
        read();          // read() throws Error and InternalErr
#if USE_LOCAL_TIMEOUT_SCHEME
    dds.timeout_off();
#endif
}

/**
 * @brief Read data into this variable
 * @param eval Evaluator for a constraint expression
 * @param dmr DMR for the whole dataset
 */
void
BaseType::intern_data(/*Crc32 &checksum, DMR &, ConstraintEvaluator &*/)
{
    if (!read_p())
        read();          // read() throws Error and InternalErr
#if 0
    compute_checksum(checksum);
#endif
}

bool
BaseType::serialize(ConstraintEvaluator &, DDS &,  Marshaller &, bool)
{
    throw InternalErr(__FILE__, __LINE__, "The DAP2 serialize() method has not been implemented for " + type_name());
}

bool
BaseType::deserialize(UnMarshaller &, DDS *, bool)
{
    throw InternalErr(__FILE__, __LINE__, "The DAP2 deserialize() method has not been implemented for " + type_name());
}

void
BaseType::serialize(D4StreamMarshaller &, DMR &, /*ConstraintEvaluator &,*/ bool)
{
    throw InternalErr(__FILE__, __LINE__, "The DAP4 serialize() method has not been implemented for " + type_name());
}

void
BaseType::deserialize(D4StreamUnMarshaller &, DMR &)
{
    throw InternalErr(__FILE__, __LINE__, "The DAP4 deserialize() method has not been implemented for " + type_name());
}

/** Write the variable's declaration in a C-style syntax. This
    function is used to create textual representation of the Data
    Descriptor Structure (DDS).  See <i>The DODS User Manual</i> for
    information about this structure.

    A simple array declaration might look like this:
    \verbatim
    Float64 lat[lat = 180];
    \endverbatim
    While a more complex declaration (for a Grid, in this case),
    would look like this:
    \verbatim
    Grid {
    ARRAY:
    Int32 sst[time = 404][lat = 180][lon = 360];
    MAPS:
    Float64 time[time = 404];
    Float64 lat[lat = 180];
    Float64 lon[lon = 360];
    } sst;
    \endverbatim

    @brief Print an ASCII representation of the variable structure.
    @param out The output stream on which to print the
    declaration.
    @param space Each line of the declaration will begin with the
    characters in this string.  Usually used for leading spaces.
    @param print_semi A boolean value indicating whether to print a
    semicolon at the end of the declaration.
    @param constraint_info A boolean value indicating whether
    constraint information is to be printed with the declaration.
    If the value of this parameter is TRUE, <tt>print_decl()</tt> prints
    the value of the variable's <tt>send_p()</tt> flag after the
    declaration.
    @param constrained If this boolean value is TRUE, the variable's
    declaration is only printed if is the <tt>send_p()</tt> flag is TRUE.
    If a constraint expression is in place, and this variable is not
    requested, the <tt>send_p()</tt> flag is FALSE.

    @see DDS
    @see DDS::CE
 */
void
BaseType::print_decl(FILE *out, string space, bool print_semi,
    bool constraint_info, bool constrained)
{
    ostringstream oss;
    print_decl(oss, space, print_semi, constraint_info, constrained);
    fwrite(oss.str().data(), sizeof(char), oss.str().length(), out);
}

/** Write the variable's declaration in a C-style syntax. This
    function is used to create textual representation of the Data
    Descriptor Structure (DDS).  See <i>The DODS User Manual</i> for
    information about this structure.

    A simple array declaration might look like this:
    \verbatim
    Float64 lat[lat = 180];
    \endverbatim
    While a more complex declaration (for a Grid, in this case),
    would look like this:
    \verbatim
    Grid {
    ARRAY:
    Int32 sst[time = 404][lat = 180][lon = 360];
    MAPS:
    Float64 time[time = 404];
    Float64 lat[lat = 180];
    Float64 lon[lon = 360];
    } sst;
    \endverbatim

    @brief Print an ASCII representation of the variable structure.
    @param out The output stream on which to print the
    declaration.
    @param space Each line of the declaration will begin with the
    characters in this string.  Usually used for leading spaces.
    @param print_semi A boolean value indicating whether to print a
    semicolon at the end of the declaration.
    @param constraint_info A boolean value indicating whether
    constraint information is to be printed with the declaration.
    If the value of this parameter is TRUE, <tt>print_decl()</tt> prints
    the value of the variable's <tt>send_p()</tt> flag after the
    declaration.
    @param constrained If this boolean value is TRUE, the variable's
    declaration is only printed if is the <tt>send_p()</tt> flag is TRUE.
    If a constraint expression is in place, and this variable is not
    requested, the <tt>send_p()</tt> flag is FALSE.

    @see DDS
    @see DDS::CE
 */
void
BaseType::print_decl(ostream &out, string space, bool print_semi,
    bool constraint_info, bool constrained)
{
    // if printing the constrained declaration, exit if this variable was not
    // selected.
    if (constrained && !send_p())
        return;

    out << space << type_name() << " " << id2www(name()) ;

    if (constraint_info) {
        if (send_p())
            out << ": Send True" ;
        else
            out << ": Send False" ;
    }

    if (print_semi)
        out << ";\n" ;
}

/** Prints the value of the variable, with its declaration. This
function is primarily intended for debugging DODS
applications. However, it can be overloaded and used to do
some useful things. Take a look at the asciival and writeval
clients, both of which overload this to output the values of
variables in different ways.

@brief Prints the value of the variable.

@param out The output stream on which to print the value.
@param space This value is passed to the print_decl()
function, and controls the leading spaces of the output.
@param print_decl_p A boolean value controlling whether the
variable declaration is printed as well as the value. */
void
BaseType::print_val(FILE *out, string space, bool print_decl_p)
{
    ostringstream oss;
    print_val(oss, space, print_decl_p);
    fwrite(oss.str().data(), sizeof(char), oss.str().length(), out);
}

/** Write the XML representation of this variable. This method is used to
    build the DDX XML response.
    @param out Destination.
    @param space Use this to indent child declarations. Default is "".
    @param constrained If true, only print this if it's part part of the
    current projection. Default is False.
    @deprecated */
void
BaseType::print_xml(FILE *out, string space, bool constrained)
{
    XMLWriter xml(space);
    print_xml_writer(xml, constrained);
    fwrite(xml.get_doc(), sizeof(char), xml.get_doc_size(), out);
}

/** Write the XML representation of this variable. This method is used to
    build the DDX XML response.
    @param out Destination output stream
    @param space Use this to indent child declarations. Default is "".
    @param constrained If true, only print this if it's part part of the
    current projection. Default is False.
    @deprecated */
void
BaseType::print_xml(ostream &out, string space, bool constrained)
{
    XMLWriter xml(space);
    print_xml_writer(xml, constrained);
    out << xml.get_doc();
}

/** Write the XML representation of this variable. This method is used to
    build the DDX XML response.
    @param out Destination output stream
    @param space Use this to indent child declarations. Default is "".
    @param constrained If true, only print this if it's part part of the
    current projection. Default is False. */
void
BaseType::print_xml_writer(XMLWriter &xml, bool constrained)
{
    if (constrained && !send_p())
        return;

    if (xmlTextWriterStartElement(xml.get_writer(), (const xmlChar*)type_name().c_str()) < 0)
        throw InternalErr(__FILE__, __LINE__, "Could not write " + type_name() + " element");

    if (!name().empty())
        if (xmlTextWriterWriteAttribute(xml.get_writer(), (const xmlChar*) "name", (const xmlChar*)name().c_str()) < 0)
            throw InternalErr(__FILE__, __LINE__, "Could not write attribute for name");

    if (is_dap4())
        attributes()->print_dap4(xml);

    if (!is_dap4() && get_attr_table().get_size() > 0)
        get_attr_table().print_xml_writer(xml);

    if (xmlTextWriterEndElement(xml.get_writer()) < 0)
        throw InternalErr(__FILE__, __LINE__, "Could not end " + type_name() + " element");
}

/** Write the DAP4 XML representation for this variable. This method is used
 * to build the DAP4 DMR response object.
 *
 * @param xml An XMLWriter that will do the serialization
 * @param constrained True if the response should show the variables subject
 * to the current constraint expression.
 */
void
BaseType::print_dap4(XMLWriter &xml, bool constrained)
{
    print_xml_writer(xml, constrained);
}

// Compares the object's current state with the semantics of a particular
// type. This will typically be defined in ctor classes (which have
// complicated semantics). For BaseType, an object is semantically correct if
// it has both a non-null name and type.
//
// NB: This is not the same as an invariant -- during the parse objects exist
// but have no name. Also, the bool ALL defaults to false for BaseType. It is
// used by children of CtorType.
//
// Returns: true if the object is semantically correct, false otherwise.

/** This function checks the class instance for internal
    consistency.  This is important to check for complex constructor
    classes.  For BaseType, an object is semantically correct if it
    has both a non-null name and type.

    For example, an Int32 instance would return FALSE if it had no
    name or no type defined.  A Grid instance might return FALSE for
    more complex reasons, such as having Map arrays of the wrong
    size or shape.

    This function is used by the DDS class, and will rarely, if
    ever, be explicitly called by a DODS application program.  A
    variable must pass this test before it is sent, but there may be
    many other stages in a retrieve operation where it would fail.

    @brief Compare an object's current state with the semantics of its
    type.
    @return Returns FALSE when the current state violates some
    aspect of the type semantics, TRUE otherwise.

    @param msg A returned string, containing a message indicating
    the source of any problem.
    @param all For complex constructor types (Grid,
    Sequence, Structure), this flag indicates whether to check the
    semantics of the member variables, too.

    @see DDS::check_semantics
 */
bool
BaseType::check_semantics(string &msg, bool)
{
    bool sem = (d_type != dods_null_c && name().length());

    if (!sem)
        msg = "Every variable must have both a name and a type\n";

    return sem;
}

/** This method contains the relational operators used by the constraint
    expression evaluator in the DDS class. Each class that wants to be able
    to evaluate relational expressions must overload this function. The
    implementation in BaseType throws an InternalErr exception. The DAP
    library classes Byte, ..., Url provide specializations of this method. It
    is not meaningful for classes such as Array because relational
    expressions using Array are not supported.

    The <i>op</i> argument refers to a table generated by bison from
    the constraint expression parser.  Use statements like the
    following to correctly interpret its value:

    \verbatim
    switch (op) {
        case EQUAL: return i1 == i2;
        case NOT_EQUAL: return i1 != i2;
        case GREATER: return i1 > i2;
        case GREATER_EQL: return i1 >= i2;
        case LESS: return i1 < i2;
        case LESS_EQL: return i1 <= i2;
        case REGEXP: throw Error("Regular expressions are not supported for integer values");
        default: throw Error("Unknown operator");
    }
    \endverbatim

    This function is used by the constraint expression evaluator.

    @brief Evaluate relational operators.
    @param b Compare the value of this instance with \e b.
    @param op An integer index indicating which relational operator
    is implied. Choose one from the following: <tt>EQUAL</tt>,
    <tt>NOT_EQUAL</tt>, <tt>GREATER</tt>, <tt>GREATER_EQL</tt>,
    <tt>LESS</tt>, <tt>LESS_EQL</tt>, and <tt>REGEXP</tt>.
    @return The boolean value of the comparison.
    @see BaseType::d4_ops(BaseType *, int)
 */
bool
BaseType::ops(BaseType *, int)
{
    // Even though ops is a public method, it can never be called because
    // they will never have a BaseType object since this class is abstract,
    // however any of the child classes could by mistake call BaseType::ops
    // so this is an internal error. Jose Garcia
    throw InternalErr(__FILE__, __LINE__, "Unimplemented operator.");
}

/**
 * @brief Evaluator a relop for DAP4
 *
 * This method is used by the filter expression evaluation code in DAP4.
 * Each of the 'data type' classes that support relops must overload this
 * method. In an expression of the form arg1 op arg2, this object is arg1,
 * the parameter 'b' is arg2 and op is the relational operator.
 *
 * @note I used the same relop codes for DAP4 as in the DAP2 parser/scanner
 * which makes for some coupling between them, but cuts way down on the
 * duplication of the evaluator logic, which is somewhat involved.
 *
 * @param b The second argument in the relational expression
 * @param op The infix relational operator
 * @return True if the expression is true, False otherwise.
 */
bool
BaseType::d4_ops(BaseType *, int)
{
    throw InternalErr(__FILE__, __LINE__, "Unimplemented operator.");
}

/**
 * @brief How many bytes does this variable use
 * Return the number of bytes of storage this variable uses. For scalar types,
 * this is pretty simple (an int32 uses 4 bytes, etc.). For arrays and Constructors,
 * it is a bit more complex. Note that a scalar String variable uses sizeof(String*)
 * bytes, not the length of the string value. The width() of a String array returns
 * the number of elements in the array times sizeof(String*).
 *
 * @param constrained Should the current constraint be taken into account?
 * @return Bytes of storage
 */
unsigned int
BaseType::width(bool /* constrained */) const
{
    throw InternalErr(__FILE__, __LINE__, "not implemented");
}

} // namespace libdap