00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef CASA_RECORDINTERFACE_H
00031 #define CASA_RECORDINTERFACE_H
00032
00033
00034
00035 #include <casacore/casa/aips.h>
00036 #include <casacore/casa/BasicSL/String.h>
00037 #include <casacore/casa/Utilities/Notice.h>
00038 #include <casacore/casa/Utilities/DataType.h>
00039 #include <casacore/casa/Containers/RecordFieldId.h>
00040 #include <casacore/casa/Arrays/Array.h>
00041
00042 namespace casacore {
00043
00044
00045 class RecordDesc;
00046 class ValueHolder;
00047 class IPosition;
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 class RecordInterface : public NoticeSource
00145 {
00146 public:
00147
00148
00149 enum RecordType {
00150
00151
00152 Fixed,
00153
00154
00155 Variable};
00156
00157
00158
00159
00160
00161
00162 enum DuplicatesFlag {
00163
00164
00165 RenameDuplicates,
00166
00167 SkipDuplicates,
00168
00169
00170 OverwriteDuplicates,
00171
00172 ThrowOnDuplicates};
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 typedef Bool CheckFieldFunction (const String& fieldName,
00184 DataType dataType,
00185 const void* extraArgument,
00186 String& message);
00187
00188
00189
00190 RecordInterface();
00191
00192
00193
00194
00195
00196
00197 RecordInterface (RecordType type, CheckFieldFunction* funcPtr,
00198 const void* checkArgument);
00199
00200
00201 RecordInterface (const RecordInterface& other);
00202
00203
00204
00205
00206
00207 RecordInterface& operator= (const RecordInterface& other);
00208
00209
00210
00211 ~RecordInterface();
00212
00213
00214 virtual RecordInterface* clone() const = 0;
00215
00216
00217
00218
00219 virtual void assign (const RecordInterface& that) = 0;
00220
00221
00222
00223 Bool isFixed() const;
00224
00225
00226
00227 virtual uInt nfields() const = 0;
00228 uInt size() const
00229 { return nfields(); }
00230
00231
00232
00233 bool empty() const
00234 { return size() == 0; }
00235
00236
00237
00238 virtual Int fieldNumber (const String& fieldName) const = 0;
00239
00240
00241
00242 Int idToNumber (const RecordFieldId&) const;
00243
00244
00245
00246 Bool isDefined (const String& fieldName) const;
00247
00248
00249
00250 virtual DataType type (Int whichField) const = 0;
00251 DataType dataType (const RecordFieldId&) const;
00252
00253
00254
00255 String name (const RecordFieldId&) const;
00256
00257
00258 virtual const String& comment (const RecordFieldId&) const = 0;
00259
00260
00261 virtual void setComment (const RecordFieldId&, const String& comment) = 0;
00262
00263
00264
00265 IPosition shape (const RecordFieldId&) const;
00266
00267
00268 RecordDesc description() const;
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 virtual void restructure (const RecordDesc& newDescription,
00283 Bool recursive=True) = 0;
00284
00285
00286
00287
00288
00289
00290
00291 virtual void removeField (const RecordFieldId&) = 0;
00292
00293
00294
00295
00296 virtual ValueHolder asValueHolder (const RecordFieldId&) const;
00297 virtual void defineFromValueHolder (const RecordFieldId&,
00298 const ValueHolder&);
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 void define (const RecordFieldId&, Bool value);
00313 void define (const RecordFieldId&, uChar value);
00314 void define (const RecordFieldId&, Short value);
00315 void define (const RecordFieldId&, Int value);
00316 void define (const RecordFieldId&, uInt value);
00317 void define (const RecordFieldId&, Int64 value);
00318 void define (const RecordFieldId&, Float value);
00319 void define (const RecordFieldId&, Double value);
00320 void define (const RecordFieldId&, const Complex& value);
00321 void define (const RecordFieldId&, const DComplex& value);
00322 void define (const RecordFieldId&, const Char* value);
00323 void define (const RecordFieldId&, const String& value);
00324 void define (const RecordFieldId&, const Array<Bool>& value,
00325 Bool FixedShape = False);
00326 void define (const RecordFieldId&, const Array<uChar>& value,
00327 Bool FixedShape = False);
00328 void define (const RecordFieldId&, const Array<Short>& value,
00329 Bool FixedShape = False);
00330 void define (const RecordFieldId&, const Array<Int>& value,
00331 Bool FixedShape = False);
00332 void define (const RecordFieldId&, const Array<uInt>& value,
00333 Bool FixedShape = False);
00334 void define (const RecordFieldId&, const Array<Int64>& value,
00335 Bool FixedShape = False);
00336 void define (const RecordFieldId&, const Array<Float>& value,
00337 Bool FixedShape = False);
00338 void define (const RecordFieldId&, const Array<Double>& value,
00339 Bool FixedShape = False);
00340 void define (const RecordFieldId&, const Array<Complex>& value,
00341 Bool FixedShape = False);
00342 void define (const RecordFieldId&, const Array<DComplex>& value,
00343 Bool FixedShape = False);
00344 void define (const RecordFieldId&, const Array<String>& value,
00345 Bool FixedShape = False);
00346 virtual void defineRecord (const RecordFieldId&,
00347 const RecordInterface& value,
00348 RecordType = Variable) = 0;
00349
00350
00351
00352
00353
00354
00355
00356
00357 void get (const RecordFieldId&, Bool& value) const;
00358 void get (const RecordFieldId&, uChar& value) const;
00359 void get (const RecordFieldId&, Short& value) const;
00360 void get (const RecordFieldId&, Int& value) const;
00361 void get (const RecordFieldId&, uInt& value) const;
00362 void get (const RecordFieldId&, Int64& value) const;
00363 void get (const RecordFieldId&, Float& value) const;
00364 void get (const RecordFieldId&, Double& value) const;
00365 void get (const RecordFieldId&, Complex& value) const;
00366 void get (const RecordFieldId&, DComplex& value) const;
00367 void get (const RecordFieldId&, String& value) const;
00368 void get (const RecordFieldId&, Array<Bool>& value) const;
00369 void get (const RecordFieldId&, Array<uChar>& value) const;
00370 void get (const RecordFieldId&, Array<Short>& value) const;
00371 void get (const RecordFieldId&, Array<Int>& value) const;
00372 void get (const RecordFieldId&, Array<uInt>& value) const;
00373 void get (const RecordFieldId&, Array<Int64>& value) const;
00374 void get (const RecordFieldId&, Array<Float>& value) const;
00375 void get (const RecordFieldId&, Array<Double>& value) const;
00376 void get (const RecordFieldId&, Array<Complex>& value) const;
00377 void get (const RecordFieldId&, Array<DComplex>& value) const;
00378 void get (const RecordFieldId&, Array<String>& value) const;
00379
00380
00381
00382
00383
00384
00385
00386
00387 Bool asBool (const RecordFieldId&) const;
00388 uChar asuChar (const RecordFieldId&) const;
00389 Short asShort (const RecordFieldId&) const;
00390 Int asInt (const RecordFieldId&) const;
00391 uInt asuInt (const RecordFieldId&) const;
00392 Int64 asInt64 (const RecordFieldId&) const;
00393 Float asFloat (const RecordFieldId&) const;
00394 Double asDouble (const RecordFieldId&) const;
00395 Complex asComplex (const RecordFieldId&) const;
00396 DComplex asDComplex(const RecordFieldId&) const;
00397 const String& asString (const RecordFieldId&) const;
00398 const Array<Bool>& asArrayBool (const RecordFieldId&) const;
00399 const Array<uChar>& asArrayuChar (const RecordFieldId&) const;
00400 const Array<Short>& asArrayShort (const RecordFieldId&) const;
00401 const Array<Int>& asArrayInt (const RecordFieldId&) const;
00402 const Array<uInt>& asArrayuInt (const RecordFieldId&) const;
00403 const Array<Int64>& asArrayInt64 (const RecordFieldId&) const;
00404 const Array<Float>& asArrayFloat (const RecordFieldId&) const;
00405 const Array<Double>& asArrayDouble (const RecordFieldId&) const;
00406 const Array<Complex>& asArrayComplex (const RecordFieldId&) const;
00407 const Array<DComplex>& asArrayDComplex(const RecordFieldId&) const;
00408 const Array<String>& asArrayString (const RecordFieldId&) const;
00409 virtual const RecordInterface& asRecord (const RecordFieldId&) const = 0;
00410 virtual RecordInterface& asrwRecord (const RecordFieldId&) = 0;
00411
00412
00413
00414
00415
00416
00417
00418 Array<Bool> toArrayBool (const RecordFieldId&) const;
00419 Array<uChar> toArrayuChar (const RecordFieldId&) const;
00420 Array<Short> toArrayShort (const RecordFieldId&) const;
00421 Array<Int> toArrayInt (const RecordFieldId&) const;
00422 Array<uInt> toArrayuInt (const RecordFieldId&) const;
00423 Array<Int64> toArrayInt64 (const RecordFieldId&) const;
00424 Array<Float> toArrayFloat (const RecordFieldId&) const;
00425 Array<Double> toArrayDouble (const RecordFieldId&) const;
00426 Array<Complex> toArrayComplex (const RecordFieldId&) const;
00427 Array<DComplex> toArrayDComplex(const RecordFieldId&) const;
00428 Array<String> toArrayString (const RecordFieldId&) const;
00429 void toArray (const RecordFieldId& id, Array<Bool>& array) const
00430 { array.reference (toArrayBool (id)); }
00431 void toArray (const RecordFieldId& id, Array<uChar>& array) const
00432 { array.reference (toArrayuChar (id)); }
00433 void toArray (const RecordFieldId& id, Array<Short>& array) const
00434 { array.reference (toArrayShort (id)); }
00435 void toArray (const RecordFieldId& id, Array<Int>& array) const
00436 { array.reference (toArrayInt (id)); }
00437 void toArray (const RecordFieldId& id, Array<uInt>& array) const
00438 { array.reference (toArrayuInt (id)); }
00439 void toArray (const RecordFieldId& id, Array<Int64>& array) const
00440 { array.reference (toArrayInt64 (id)); }
00441 void toArray (const RecordFieldId& id, Array<Float>& array) const
00442 { array.reference (toArrayFloat (id)); }
00443 void toArray (const RecordFieldId& id, Array<Double>& array) const
00444 { array.reference (toArrayDouble (id)); }
00445 void toArray (const RecordFieldId& id, Array<Complex>& array) const
00446 { array.reference (toArrayComplex (id)); }
00447 void toArray (const RecordFieldId& id, Array<DComplex>& array) const
00448 { array.reference (toArrayDComplex (id)); }
00449 void toArray (const RecordFieldId& id, Array<String>& array) const
00450 { array.reference (toArrayString (id)); }
00451
00452
00453
00454
00455
00456
00457 Float asfloat (const RecordFieldId&) const;
00458 Double asdouble (const RecordFieldId&) const;
00459 const Array<Float>& asArrayfloat (const RecordFieldId&) const;
00460 const Array<Double>& asArraydouble (const RecordFieldId&) const;
00461
00462
00463
00464
00465 virtual void makeUnique() = 0;
00466
00467
00468
00469
00470 virtual void defineDataField (Int whichField, DataType type,
00471 const void* value) = 0;
00472
00473
00474
00475
00476
00477
00478
00479 virtual void* get_pointer (Int whichField, DataType type) const = 0;
00480 virtual void* get_pointer (Int whichField, DataType type,
00481 const String& recordType) const = 0;
00482
00483
00484
00485
00486
00487
00488 friend inline std::ostream& operator<< (std::ostream& os,
00489 const RecordInterface& rec)
00490 { rec.print (os, 25, " "); return os; }
00491 virtual void print (std::ostream&,
00492 Int maxNrValues = 25,
00493 const String& indent="") const = 0;
00494
00495
00496
00497 protected:
00498
00499
00500 virtual void addDataField (const String& name, DataType type,
00501 const IPosition& shape, Bool fixedShape,
00502 const void* value) = 0;
00503
00504
00505
00506
00507 void throwIfFixed() const;
00508
00509
00510
00511
00512 void checkName (const String& fieldName, DataType type) const;
00513
00514
00515
00516
00517 RecordType& recordType();
00518 RecordType recordType() const;
00519
00520
00521
00522
00523 Int newIdToNumber (const RecordFieldId&) const;
00524
00525
00526
00527
00528 void defineField (const RecordFieldId&, DataType type, const void* value);
00529
00530
00531
00532
00533 void defineField (const RecordFieldId&, DataType type,
00534 const IPosition& shape, Bool fixedShape,
00535 const void* value);
00536
00537
00538 private:
00539
00540 virtual RecordDesc getDescription() const = 0;
00541
00542
00543 CheckFieldFunction* checkFunction_p;
00544 const void* checkArgument_p;
00545
00546
00547 RecordType type_p;
00548 };
00549
00550
00551 inline Bool RecordInterface::isFixed() const
00552 {
00553 return (type_p == Fixed);
00554 }
00555 inline Bool RecordInterface::isDefined (const String& fieldName) const
00556 {
00557 return (fieldNumber(fieldName) >= 0);
00558 }
00559 inline RecordInterface::RecordType& RecordInterface::recordType()
00560 {
00561 return type_p;
00562 }
00563 inline RecordInterface::RecordType RecordInterface::recordType() const
00564 {
00565 return type_p;
00566 }
00567 inline DataType RecordInterface::dataType (const RecordFieldId& id) const
00568 {
00569 return type (idToNumber(id));
00570 }
00571 inline void RecordInterface::define (const RecordFieldId& id, const Char* value)
00572 {
00573 define (id, String(value));
00574 }
00575 inline Float RecordInterface::asfloat (const RecordFieldId& id) const
00576 {
00577 return asFloat (id);
00578 }
00579 inline Double RecordInterface::asdouble (const RecordFieldId& id) const
00580 {
00581 return asDouble (id);
00582 }
00583 inline const Array<Float>& RecordInterface::asArrayfloat
00584 (const RecordFieldId& id) const
00585 {
00586 return asArrayFloat (id);
00587 }
00588 inline const Array<Double>& RecordInterface::asArraydouble
00589 (const RecordFieldId& id) const
00590 {
00591 return asArrayDouble (id);
00592 }
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 class RecordNotice : public Notice
00618 {
00619 public:
00620
00621 enum NoticeType {
00622
00623 DETACH,
00624
00625
00626 ACQUIRE,
00627
00628
00629 REMOVE};
00630
00631
00632
00633 RecordNotice (NoticeType changeType, uInt fieldNumber);
00634
00635
00636 virtual uInt type() const;
00637
00638
00639 virtual int operator== (const Notice& that) const;
00640
00641
00642 NoticeType changeType() const;
00643
00644
00645 Int fieldNumber() const;
00646
00647 private:
00648 NoticeType changeType_p;
00649 uInt fieldNumber_p;
00650 };
00651
00652
00653 inline RecordNotice::NoticeType RecordNotice::changeType() const
00654 {
00655 return changeType_p;
00656 }
00657 inline Int RecordNotice::fieldNumber() const
00658 {
00659 return fieldNumber_p;
00660 }
00661
00662
00663
00664
00665 }
00666
00667 #endif