6
6
// Copyright (C) Eugene Krissinel 2000-2008.
8
// This library is free software: you can redistribute it and/or
9
// modify it under the terms of the GNU Lesser General Public
10
// License version 3, modified in accordance with the provisions
8
// This library is free software: you can redistribute it and/or
9
// modify it under the terms of the GNU Lesser General Public
10
// License version 3, modified in accordance with the provisions
11
11
// of the license to address the requirements of UK law.
13
// You should have received a copy of the modified GNU Lesser
14
// General Public License along with this library. If not, copies
13
// You should have received a copy of the modified GNU Lesser
14
// General Public License along with this library. If not, copies
15
15
// may be downloaded from http://www.ccp4.ac.uk/ccp4license.php
17
17
// This program is distributed in the hope that it will be useful,
108
108
void CXMLObject::InitXMLObject() {
116
121
void CXMLObject::FreeMemory() {
118
124
if (objTag) delete[] objTag;
119
125
if (objData) delete[] objData;
121
131
for (i=0;i<nAlloc;i++)
122
132
if (object[i]) delete object[i];
141
for (i=0;i<nAttrAlloc;i++) {
142
if (attr_name [i]) delete[] attr_name [i];
143
if (attr_value[i]) delete[] attr_value[i];
145
FreeVectorMemory ( attr_name ,0 );
146
FreeVectorMemory ( attr_value,0 );
132
156
void CXMLObject::SetTag ( cpstr Tag ) {
202
void CXMLObject::AddAttribute ( cpstr name, cpstr value ) {
206
if (nAttributes>=nAttrAlloc) {
207
nAttrAlloc = nAttributes + 10;
208
GetVectorMemory ( an,nAttrAlloc,0 );
209
GetVectorMemory ( av,nAttrAlloc,0 );
210
for (i=0;i<nAttrAlloc;i++) {
214
for (i=0;i<nAttributes;i++) {
215
CreateCopy ( an[i],attr_name [i] );
216
CreateCopy ( av[i],attr_value[i] );
217
if (attr_name [i]) delete[] attr_name [i];
218
if (attr_value[i]) delete[] attr_value[i];
220
FreeVectorMemory ( attr_name ,0 );
221
FreeVectorMemory ( attr_value,0 );
226
CreateCopy ( attr_name [nAttributes],name );
227
CreateCopy ( attr_value[nAttributes],value );
232
void CXMLObject::AddAttribute ( cpstr name, const int iV ) {
234
sprintf ( S,"%i",iV );
235
AddAttribute ( name,S );
238
void CXMLObject::AddAttribute ( cpstr name, const Boolean bV ) {
239
if (bV) AddAttribute ( name,"Yes" );
240
else AddAttribute ( name,"No" );
178
243
void CXMLObject::SetData ( cpstr Data ) {
220
285
CreateConcat ( objData,d1,d2 );
223
void CXMLObject::SetData ( realtype V, int length ) {
288
void CXMLObject::SetData ( const realtype V, const int length ) {
225
290
sprintf ( N,"%-.*g",length,V );
226
291
CreateCopy ( objData,N );
229
void CXMLObject::SetData ( int iV, int length ) {
294
void CXMLObject::SetData ( const int iV, const int length ) {
231
296
sprintf ( N,"%*i",length,iV );
232
297
CreateCopy ( objData,N );
235
void CXMLObject::SetData ( Boolean bV ) {
300
void CXMLObject::SetData ( const Boolean bV ) {
236
301
if (bV) CreateCopy ( objData,pstr("Yes") );
237
302
else CreateCopy ( objData,pstr("No") );
463
528
return XMLObject;
531
PCXMLObject CXMLObject::GetFirstObject() {
532
if (nObjects>0) return object[0];
536
PCXMLObject CXMLObject::GetLastObject() {
537
if (nObjects>0) return object[nObjects-1];
541
PCXMLObject CXMLObject::GetObject ( int objectNo ) {
542
if ((0<=objectNo) && (objectNo<nObjects))
543
return object[objectNo];
466
548
void CXMLObject::AddObject ( PCXMLObject XMLObject, int lenInc ) {
467
549
PPCXMLObject obj1;
513
596
f.Write ( indstr );
514
597
f.Write ( pstr("<") );
515
598
f.Write ( objTag );
599
for (i=0;i<nAttributes;i++) {
601
f.Write ( attr_name[i] );
603
f.Write ( attr_value[i] );
516
606
if ((!objData) && (nObjects<=0)) {
517
607
f.WriteLine ( pstr("/>") );
718
807
if (rc!=XMLR_Ok) FreeMemory();
724
813
void CXMLObject::Copy ( PCXMLObject XMLObject ) {
727
818
CreateCopy ( objTag ,XMLObject->objTag );
728
819
CreateCopy ( objData,XMLObject->objData );
729
821
nObjects = XMLObject->nObjects;
730
822
nAlloc = nObjects;
731
823
if (nObjects>0) {
738
830
object[i] = NULL;
833
nAttributes = XMLObject->nAttributes;
834
nAttrAlloc = nAttributes;
836
GetVectorMemory ( attr_name ,nAttrAlloc,0 );
837
GetVectorMemory ( attr_value,nAttrAlloc,0 );
838
for (i=0;i<nAttributes;i++) {
839
attr_name [i] = NULL;
840
attr_value[i] = NULL;
841
CreateCopy ( attr_name [i],XMLObject->attr_name [i] );
842
CreateCopy ( attr_value[i],XMLObject->attr_value[i] );
743
849
void CXMLObject::write ( RCFile f ) {
745
f.CreateWrite ( objTag );
746
f.CreateWrite ( objData );
747
f.WriteInt ( &nObjects );
851
f.CreateWrite ( objTag );
852
f.CreateWrite ( objData );
853
f.WriteInt ( &nObjects );
748
854
for (i=0;i<nObjects;i++)
749
855
StreamWrite ( f,object[i] );
856
f.WriteInt ( &nAttributes );
857
for (i=0;i<nAttributes;i++) {
858
f.CreateWrite ( attr_name [i] );
859
f.CreateWrite ( attr_value[i] );
752
863
void CXMLObject::read ( RCFile f ) {
755
868
f.CreateRead ( objTag );
756
869
f.CreateRead ( objData );
757
871
f.ReadInt ( &nObjects );
758
872
nAlloc = nObjects;
759
873
if (nObjects>0) {
763
877
StreamRead ( f,object[i] );
881
f.ReadInt ( &nAttributes );
882
nAttrAlloc = nAttributes;
884
GetVectorMemory ( attr_name ,nAttrAlloc,0 );
885
GetVectorMemory ( attr_value,nAttrAlloc,0 );
886
for (i=0;i<nAttributes;i++) {
887
attr_name [i] = NULL;
888
attr_value[i] = NULL;
889
f.CreateRead ( attr_name [i] );
890
f.CreateRead ( attr_value[i] );