// $Id: mmdb_uddata.cpp $ // ================================================================= // // CCP4 Coordinate Library: support of coordinate-related // functionality in protein crystallography applications. // // Copyright (C) Eugene Krissinel 2000-2013. // // This library is free software: you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License version 3, modified in accordance with the provisions // of the license to address the requirements of UK law. // // You should have received a copy of the modified GNU Lesser // General Public License along with this library. If not, copies // may be downloaded from http://www.ccp4.ac.uk/ccp4license.php // // This program 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. // // ================================================================= // // 12.09.13 <-- Date of Last Modification. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ----------------------------------------------------------------- // // **** Module : MMDBF_UDData // ~~~~~~~~~ // **** Project : MacroMolecular Data Base (MMDB) // ~~~~~~~~~ // // **** Classes : mmdb::UDData ( user-defined data ) // ~~~~~~~~~ // // (C) E. Krissinel 2000-2013 // // ================================================================= // #include #include "mmdb_uddata.h" namespace mmdb { // ======================== UDRegister ========================== #define nUDRTypes 5 UDRegister::UDRegister() : io::Stream() { InitUDRegister(); } UDRegister::UDRegister ( io::RPStream Object ) : io::Stream(Object) { InitUDRegister(); } UDRegister::~UDRegister() { FreeUDRegister(); } void UDRegister::InitUDRegister() { int i; for (i=0;i=0) && (udr_type=0) && (udr_type=0) && (udr_type=0) && (udr_type0) { IUDRegister[j] = new pstr[nIUDR[j]]; for (i=0;i0) { RUDRegister[j] = new pstr[nRUDR[j]]; for (i=0;i0) { SUDRegister[j] = new pstr[nSUDR[j]]; for (i=0;i> 8); SUData[0][1] = byte((newN & 0x00FF0000) >> 16); SUData[0][0] = byte((newN & 0xFF000000) >> 24); } int UDData::putUDData ( int UDDhandle, int iudd ) { ivector IUD; int i,l,udh; udh = UDDhandle & UDRF_MASK; if (udh<1) return UDDATA_WrongHandle; l = getNofIUData(); if (udh>l) { GetVectorMemory ( IUD,udh+1,0 ); IUD[0] = udh; for (i=1;i<=l;i++) IUD[i] = IUData[i]; for (i=l+1;il) { GetVectorMemory ( RUD,udh+1,0 ); RUD[0] = udh; for (i=1;i<=l;i++) RUD[i] = RUData[i]; for (i=l+1;il) { if (l>0) { GetVectorMemory ( SUD,udh+1,0 ); for (i=0;i<=l;i++) SUD[i] = SUData[i]; for (i=l+1;i<=udh;i++) SUD[i] = NULL; FreeVectorMemory ( SUData,0 ); SUData = SUD; } else { GetVectorMemory ( SUData,udh+1,0 ); SUData[0] = new char[4]; for (i=1;i<=udh;i++) SUData[i] = NULL; } setNofSUData ( udh ); } CreateCopy ( SUData[udh],sudd ); return UDDATA_Ok; } int UDData::getUDData ( int UDDhandle, int & iudd ) { int l,udh; iudd = 0; udh = UDDhandle & UDRF_MASK; if (udh<1) return UDDATA_WrongHandle; l = getNofIUData(); if (udh>l) return UDDATA_NoData; iudd = IUData[udh]; if (iudd==MinInt4) return UDDATA_NoData; return UDDATA_Ok; } int UDData::getUDData ( int UDDhandle, realtype & rudd ) { int l,udh; rudd = 0.0; udh = UDDhandle & UDRF_MASK; if (udh<1) return UDDATA_WrongHandle; l = getNofRUData(); if (udh>l) return UDDATA_NoData; rudd = RUData[udh]; if (rudd==-MaxReal) return UDDATA_NoData; return UDDATA_Ok; } int UDData::getUDData ( int UDDhandle, pstr sudd, int maxLen ) { int l,udh; sudd[0] = char(0); udh = UDDhandle & UDRF_MASK; if (udh<1) return UDDATA_WrongHandle; l = getNofSUData(); if (udh>l) return UDDATA_NoData; if (!SUData[udh]) return UDDATA_NoData; strcpy_n0 ( sudd,SUData[udh],maxLen-1 ); return UDDATA_Ok; } pstr UDData::getUDData ( int UDDhandle, int * retcode ) { int l,udh; udh = UDDhandle & UDRF_MASK; if (udh<1) { if (retcode) *retcode = UDDATA_WrongHandle; return NULL; } l = getNofSUData(); if (udh>l) { if (retcode) *retcode = UDDATA_NoData; return NULL; } if (!SUData[udh]) { if (retcode) *retcode = UDDATA_NoData; return NULL; } if (retcode) *retcode = UDDATA_Ok; return SUData[udh]; } int UDData::getUDData ( int UDDhandle, pstr & sudd ) { int l,udh; udh = UDDhandle & UDRF_MASK; if (udh<1) { if (sudd) { delete[] sudd; sudd = NULL; } return UDDATA_WrongHandle; } l = getNofSUData(); if (udh>l) { if (sudd) { delete[] sudd; sudd = NULL; } return UDDATA_NoData; } if (!SUData[udh]) { if (sudd) { delete[] sudd; sudd = NULL; } return UDDATA_NoData; } CreateCopy ( sudd,SUData[udh] ); return UDDATA_Ok; } void UDData::write ( io::RFile f ) { int i,l; byte Version=1; f.WriteByte ( &Version ); Mask::write ( f ); if (IUData) l = IUData[0]; else l = -1; f.WriteVector ( IUData,l+1,0 ); if (RUData) l = mround(RUData[0]); else l = -1; f.WriteVector ( RUData,l+1,0 ); l = getNofSUData(); f.WriteInt ( &l ); for (i=1;i<=l;i++) f.CreateWrite ( SUData[i] ); } void UDData::read ( io::RFile f ) { int i,l; byte Version; f.ReadByte ( &Version ); FreeUDDMemory(); Mask::read ( f ); f.CreateReadVector ( IUData,0 ); f.CreateReadVector ( RUData,0 ); f.ReadInt ( &l ); if (l>0) { SUData = new pstr[l+1]; SUData[0] = new char[4]; setNofSUData ( l ); for (i=1;i<=l;i++) { SUData[i] = NULL; f.CreateRead ( SUData[i] ); } } } MakeStreamFunctions(UDData) } // namespace mmdb