//# ColDescSet.cc: This class defines a set of column descriptions //# Copyright (C) 1994,1995,1996,1997,2000,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 namespace casacore { //# NAMESPACE CASACORE - BEGIN ColumnDescSet::ColumnDescSet() : colSeq_p (0) { } ColumnDescSet::ColumnDescSet (const ColumnDescSet& that) : colSeq_p (0) { operator= (that); } ColumnDescSet::~ColumnDescSet() {} ColumnDescSet& ColumnDescSet::operator= (const ColumnDescSet& that) { if (this != &that) { uInt nrcol = that.cols_p.size(); colSeq_p.resize (nrcol); cols_p.clear(); //# Now we have to fill in the column order, which is the //# same as the order in the source. //# Make a copy of the ColumnDesc object and keep a pointer to it. for (uInt i=0; i col = that.cols_p.at(colName); cols_p.insert (std::make_pair (colName, CountedPtr(new ColumnDesc(*col)))); colSeq_p[i] = cols_p.at(colName).get(); } } return *this; } ColumnDesc& ColumnDescSet::operator[] (const String& name) { // Throw an exception if the column is undefined. std::map>::iterator iter = cols_p.find (name); if (iter == cols_p.end()) { throw (TableError ("Table column " + name + " is unknown")); } return *(iter->second); } //# Add a column to the set with another name. ColumnDesc& ColumnDescSet::addColumn (const ColumnDesc& cd, const String& newname) { //# First make a copy to be able to change the name. ColumnDesc coldes (cd); coldes.setName (newname); return addColumn (coldes); } //# Add a column to the set. ColumnDesc& ColumnDescSet::addColumn (const ColumnDesc& cd) { //# First check if the column name already exists. if (isDefined (cd.name())) { throw (TableInvColumnDesc (cd.name(), "column already exists")); } cd.checkAdd (*this); cols_p.insert (std::make_pair(cd.name(), CountedPtr(new ColumnDesc(cd)))); //# Get actual column description object. ColumnDesc& coldes = *(cols_p.at(cd.name())); //# Add the new column to the sequence block. uInt nrcol = ncolumn(); if (nrcol > colSeq_p.nelements()) { colSeq_p.resize (nrcol + 63); } colSeq_p[nrcol-1] = &coldes; coldes.handleAdd (*this); return coldes; } //# Remove a column. //# Let the column first act upon its removal. void ColumnDescSet::remove (const String& name) { ColumnDesc& cd = (*this)[name]; cd.handleRemove (*this); //# Remove it first from the sequence block. uInt nrcol = ncolumn(); for (uInt i=0; i(colSeq_p[inx])->name() == oldname) { break; } } AlwaysAssert (inx < colSeq_p.size(), AipsError); CountedPtr cdesc = cols_p.at(oldname); cdesc->checkRename (*this, newname); cols_p.erase (oldname); cols_p.insert (std::make_pair(newname, cdesc)); ColumnDesc& cd = *(cols_p.at(newname)); colSeq_p[inx] = &cd; //# Actually rename in BaseColDesc object. cd.setName (newname); //# Handle rename for other things. cd.handleRename (*this, oldname); for (auto& x : cols_p) { x.second->renameAction (newname, oldname); } } //# Check recursevily if the descriptions of all subtables are known. void ColumnDescSet::checkSubTableDesc() const { uInt nrcol = ncolumn(); for (uInt i=0; icheckSubTableDesc(); // check recursively } } } Bool ColumnDescSet::isEqual (const ColumnDescSet& other, Bool& equalDataTypes) const { equalDataTypes = False; if (ncolumn() != other.ncolumn()) { return False; } return allExist (other, equalDataTypes); } Bool ColumnDescSet::isSubset (const ColumnDescSet& other, Bool& equalDataTypes) const { equalDataTypes = False; if (ncolumn() > other.ncolumn()) { return False; } return allExist (other, equalDataTypes); } Bool ColumnDescSet::isStrictSubset (const ColumnDescSet& other, Bool& equalDataTypes) const { equalDataTypes = False; if (ncolumn() >= other.ncolumn()) { return False; } return allExist (other, equalDataTypes); } Bool ColumnDescSet::allExist (const ColumnDescSet& other, Bool& equalDataTypes) const { equalDataTypes = True; uInt nrcol = ncolumn(); for (uInt i=0; i> nrcol; for (uInt i=0; i