//# Record2Interface.cc: Implementation of toArrayX functions //# Copyright (C) 2001 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 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 Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# //# $Id$ #include #include #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN Array RecordInterface::toArrayBool (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpInt: case TpArrayInt: { Array tmp = asArrayInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayBool(id).copy(); } return arr; } Array RecordInterface::toArrayuChar (const RecordFieldId& id) const { return asArrayuChar(id).copy(); } Array RecordInterface::toArrayShort (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: { Array tmp = asArrayuChar (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayShort (id); } return arr; } Array RecordInterface::toArrayInt (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: { Array tmp = asArrayuChar (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpShort: case TpArrayShort: { Array tmp = asArrayShort (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpUInt: case TpArrayUInt: { Array tmp = asArrayuInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt64: case TpArrayInt64: { Array tmp = asArrayInt64 (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayInt (id); } return arr; } Array RecordInterface::toArrayuInt (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: { Array tmp = asArrayuChar (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpShort: case TpArrayShort: { Array tmp = asArrayShort (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt: case TpArrayInt: { Array tmp = asArrayInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt64: case TpArrayInt64: { Array tmp = asArrayInt64 (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayuInt (id); } return arr; } Array RecordInterface::toArrayInt64 (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: { Array tmp = asArrayuChar (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpShort: case TpArrayShort: { Array tmp = asArrayShort (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt: case TpArrayInt: { Array tmp = asArrayInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpUInt: case TpArrayUInt: { Array tmp = asArrayuInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayInt64 (id); } return arr; } Array RecordInterface::toArrayFloat (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: { Array tmp = asArrayuChar (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpShort: case TpArrayShort: { Array tmp = asArrayShort (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt: case TpArrayInt: { Array tmp = asArrayInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpUInt: case TpArrayUInt: { Array tmp = asArrayuInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt64: case TpArrayInt64: { Array tmp = asArrayInt64 (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpDouble: case TpArrayDouble: { Array tmp = asArrayDouble (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayFloat (id); } return arr; } Array RecordInterface::toArrayDouble (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: { Array tmp = asArrayuChar (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpShort: case TpArrayShort: { Array tmp = asArrayShort (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt: case TpArrayInt: { Array tmp = asArrayInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpUInt: case TpArrayUInt: { Array tmp = asArrayuInt (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpInt64: case TpArrayInt64: { Array tmp = asArrayInt64 (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpFloat: case TpArrayFloat: { Array tmp = asArrayFloat (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayDouble (id); } return arr; } Array RecordInterface::toArrayDComplex (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: case TpShort: case TpArrayShort: case TpInt: case TpArrayInt: case TpUInt: case TpArrayUInt: case TpInt64: case TpArrayInt64: case TpFloat: case TpArrayFloat: { Array tmp = toArrayDouble (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpDouble: case TpArrayDouble: { Array tmp = asArrayDouble (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpComplex: case TpArrayComplex: { Array tmp = asArrayComplex (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayDComplex (id); } return arr; } Array RecordInterface::toArrayComplex (const RecordFieldId& id) const { Array arr; Int whichField = idToNumber (id); switch (type(whichField)) { case TpUChar: case TpArrayUChar: case TpShort: case TpArrayShort: case TpInt: case TpArrayInt: case TpUInt: case TpArrayUInt: case TpInt64: case TpArrayInt64: case TpDouble: case TpArrayDouble: { Array tmp = toArrayFloat (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpFloat: case TpArrayFloat: { Array tmp = asArrayFloat (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } case TpDComplex: case TpArrayDComplex: { Array tmp = asArrayDComplex (id); arr.resize (tmp.shape()); convertArray (arr, tmp); break; } default: arr = asArrayComplex (id); } return arr; } Array RecordInterface::toArrayString (const RecordFieldId& id) const { return asArrayString(id).copy(); } ValueHolder RecordInterface::asValueHolder (const RecordFieldId& id) const { switch (dataType(id)) { case TpBool: return ValueHolder(asBool(id)); case TpUChar: return ValueHolder(asuChar(id)); case TpShort: return ValueHolder(asShort(id)); case TpInt: return ValueHolder(asInt(id)); case TpUInt: return ValueHolder(asuInt(id)); case TpInt64: return ValueHolder(asInt64(id)); case TpFloat: return ValueHolder(asFloat(id)); case TpDouble: return ValueHolder(asDouble(id)); case TpComplex: return ValueHolder(asComplex(id)); case TpDComplex: return ValueHolder(asDComplex(id)); case TpString: return ValueHolder(asString(id)); case TpArrayBool: return ValueHolder(asArrayBool(id)); case TpArrayUChar: return ValueHolder(asArrayuChar(id)); case TpArrayShort: return ValueHolder(asArrayShort(id)); case TpArrayInt: return ValueHolder(asArrayInt(id)); case TpArrayUInt: return ValueHolder(asArrayuInt(id)); case TpArrayInt64: return ValueHolder(asArrayInt64(id)); case TpArrayFloat: return ValueHolder(asArrayFloat(id)); case TpArrayDouble: return ValueHolder(asArrayDouble(id)); case TpArrayComplex: return ValueHolder(asArrayComplex(id)); case TpArrayDComplex: return ValueHolder(asArrayDComplex(id)); case TpArrayString: return ValueHolder(asArrayString(id)); default: break; } throw AipsError ("RecordInterface::asValueHolder - unknown data type"); } void RecordInterface::defineFromValueHolder (const RecordFieldId& id, const ValueHolder& value) { switch (value.dataType()) { case TpBool: define (id, value.asBool()); break; case TpUChar: define (id, value.asuChar()); break; case TpShort: define (id, value.asShort()); break; case TpUShort: case TpInt: define (id, value.asInt()); break; case TpUInt: define (id, value.asuInt()); break; case TpInt64: define (id, value.asInt64()); break; case TpFloat: define (id, value.asFloat()); break; case TpDouble: define (id, value.asDouble()); break; case TpComplex: define (id, value.asComplex()); break; case TpDComplex: define (id, value.asDComplex()); break; case TpString: define (id, value.asString()); break; case TpArrayBool: define (id, value.asArrayBool()); break; case TpArrayUChar: define (id, value.asArrayuChar()); break; case TpArrayShort: define (id, value.asArrayShort()); break; case TpArrayUShort: case TpArrayInt: define (id, value.asArrayInt()); break; case TpArrayUInt: define (id, value.asArrayuInt()); break; case TpArrayInt64: define (id, value.asArrayInt64()); break; case TpArrayFloat: define (id, value.asArrayFloat()); break; case TpArrayDouble: define (id, value.asArrayDouble()); break; case TpArrayComplex: define (id, value.asArrayComplex()); break; case TpArrayDComplex: define (id, value.asArrayDComplex()); break; case TpArrayString: define (id, value.asArrayString()); break; case TpOther: // An untyped array is handled as an Int array. define (id, value.asArrayInt()); break; default: throw AipsError ("RecordInterface::defineFromValueHolder - " "unknown data type"); break; } } } //# NAMESPACE CASACORE - END