//# BitFlagsEngine.tcc: Templated virtual column engine to map bit flags to a Bool //# Copyright (C) 2009 //# 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$ #ifndef TABLES_BITFLAGSENGINE_TCC #define TABLES_BITFLAGSENGINE_TCC //# Includes #include #include #include #include #include #include #include #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN template BitFlagsEngine::BitFlagsEngine (const String& virtualColumnName, const String& storedColumnName, T readMask, T writeMask) : BaseMappedArrayEngine (virtualColumnName, storedColumnName), itsBFEReadMask (readMask), itsBFEWriteMask (writeMask), itsReadMask (readMask), itsWriteMask (writeMask), itsIsNew (False) {} template BitFlagsEngine::BitFlagsEngine (const String& virtualColumnName, const String& storedColumnName, const Array& readMaskKeys, const Array& writeMaskKeys) : BaseMappedArrayEngine (virtualColumnName, storedColumnName), itsBFEReadMask (readMaskKeys, 0xffffffff), itsBFEWriteMask (writeMaskKeys, 1), itsReadMask (0xffffffff), itsWriteMask (1), itsIsNew (False) {} template BitFlagsEngine::BitFlagsEngine (const Record& spec) : BaseMappedArrayEngine(), itsIsNew (False) { if (spec.isDefined("SOURCENAME") && spec.isDefined("TARGETNAME")) { setNames (spec.asString("SOURCENAME"), spec.asString("TARGETNAME")); setProperties (spec); } } template BitFlagsEngine::BitFlagsEngine (const BitFlagsEngine& that) : BaseMappedArrayEngine (that), itsBFEReadMask (that.itsBFEReadMask), itsBFEWriteMask (that.itsBFEWriteMask), itsReadMask (that.itsReadMask), itsWriteMask (that.itsWriteMask), itsIsNew (that.itsIsNew) {} template BitFlagsEngine::~BitFlagsEngine() {} //# Clone the engine object. template DataManager* BitFlagsEngine::clone() const { DataManager* dmPtr = new BitFlagsEngine (*this); return dmPtr; } //# Return the type name of the engine (i.e. its class name). template String BitFlagsEngine::dataManagerType() const { return className(); } //# Return the class name. //# Get the data type names using class ValType. template String BitFlagsEngine::className() { return "BitFlagsEngine<" + valDataTypeId (static_cast(0)); } template String BitFlagsEngine::dataManagerName() const { return virtualName(); } template Record BitFlagsEngine::dataManagerSpec() const { Record spec = getProperties(); spec.define ("SOURCENAME", virtualName()); spec.define ("TARGETNAME", storedName()); return spec; } template Record BitFlagsEngine::getProperties() const { Record spec; itsBFEReadMask.toRecord (spec, "Read"); itsBFEWriteMask.toRecord (spec, "Write"); return spec; } template void BitFlagsEngine::setProperties (const Record& spec) { itsBFEReadMask.fromRecord (spec, column(), "Read"); itsBFEWriteMask.fromRecord (spec, column(), "Write"); itsReadMask = T(itsBFEReadMask.getMask()); itsWriteMask = T(itsBFEWriteMask.getMask()); } template DataManager* BitFlagsEngine::makeObject (const String&, const Record& spec) { DataManager* dmPtr = new BitFlagsEngine(spec); return dmPtr; } template void BitFlagsEngine::registerClass() { DataManager::registerCtor (className(), makeObject); } template void BitFlagsEngine::create64 (rownr_t initialNrrow) { BaseMappedArrayEngine::create64 (initialNrrow); itsIsNew = True; } template void BitFlagsEngine::prepare() { BaseMappedArrayEngine::prepare(); // If a new table, derive the mask here. // This cannot be done in create, because the other column may not // be created yet. if (itsIsNew) { itsBFEReadMask.makeMask (column()); itsBFEWriteMask.makeMask(column()); // Store the various parameters as keywords in this column. TableColumn thisCol (table(), virtualName()); itsBFEReadMask.toRecord (thisCol.rwKeywordSet(), "_BitFlagsEngine_Read"); itsBFEWriteMask.toRecord(thisCol.rwKeywordSet(), "_BitFlagsEngine_Write"); } else { // Existing table, get masks from the keywords. TableColumn thisCol (table(), virtualName()); itsBFEReadMask.fromRecord (thisCol.keywordSet(), column(), "_BitFlagsEngine_Read"); itsBFEWriteMask.fromRecord(thisCol.keywordSet(), column(), "_BitFlagsEngine_Write"); } itsReadMask = T(itsBFEReadMask.getMask()); itsWriteMask = T(itsBFEWriteMask.getMask()); } template void BitFlagsEngine::getArray (rownr_t rownr, Array& array) { Array target(array.shape()); column().get (rownr, target); mapOnGet (array, target); } template void BitFlagsEngine::putArray (rownr_t rownr, const Array& array) { Array target(array.shape()); mapOnPut (array, target); column().put (rownr, target); } template void BitFlagsEngine::getSlice (rownr_t rownr, const Slicer& slicer, Array& array) { Array target(array.shape()); column().getSlice (rownr, slicer, target); mapOnGet (array, target); } template void BitFlagsEngine::putSlice (rownr_t rownr, const Slicer& slicer, const Array& array) { Array target(array.shape()); mapOnPut (array, target); column().putSlice (rownr, slicer, target); } template void BitFlagsEngine::getArrayColumn (Array& array) { Array target(array.shape()); column().getColumn (target); mapOnGet (array, target); } template void BitFlagsEngine::putArrayColumn (const Array& array) { Array target(array.shape()); mapOnPut (array, target); column().putColumn (target); } template void BitFlagsEngine::getArrayColumnCells (const RefRows& rownrs, Array& array) { Array target(array.shape()); column().getColumnCells (rownrs, target); mapOnGet (array, target); } template void BitFlagsEngine::putArrayColumnCells (const RefRows& rownrs, const Array& array) { Array target(array.shape()); mapOnPut (array, target); column().putColumnCells (rownrs, target); } template void BitFlagsEngine::getColumnSlice (const Slicer& slicer, Array& array) { Array target(array.shape()); column().getColumn (slicer, target); mapOnGet (array, target); } template void BitFlagsEngine::putColumnSlice (const Slicer& slicer, const Array& array) { Array target(array.shape()); mapOnPut (array, target); column().putColumn (slicer, target); } template void BitFlagsEngine::getColumnSliceCells (const RefRows& rownrs, const Slicer& slicer, Array& array) { Array target(array.shape()); column().getColumnCells (rownrs, slicer, target); mapOnGet (array, target); } template void BitFlagsEngine::putColumnSliceCells (const RefRows& rownrs, const Slicer& slicer, const Array& array) { Array target(array.shape()); mapOnPut (array, target); column().putColumnCells (rownrs, slicer, target); } template void BitFlagsEngine::mapOnGet (Array& array, const Array& stored) { arrayTransform (stored, array, FlagsToBool(itsReadMask)); } template void BitFlagsEngine::mapOnPut (const Array& array, Array& stored) { arrayTransformInPlace (stored, array, BoolToFlags(itsWriteMask)); } } //# NAMESPACE CASACORE - END #endif