~ckerr-s/mmdb/cmake

« back to all changes in this revision

Viewing changes to src/mmdb_xml.cpp

  • Committer: Morten Kjeldgaard
  • Date: 2015-04-19 21:08:03 UTC
  • Revision ID: mok0@ubuntu.com-20150419210803-o5xw9g0d60722oj8
Tags: mmdb-1.25.6.1
Incorporate upstream updates version 1.25.5. Add fink .info file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
//
6
6
//   Copyright (C) Eugene Krissinel 2000-2008.
7
7
//
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.
12
12
//
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
16
16
//
17
17
//    This program is distributed in the hope that it will be useful,
106
106
}
107
107
 
108
108
void  CXMLObject::InitXMLObject()  {
109
 
  objTag   = NULL;
110
 
  objData  = NULL;
111
 
  nObjects = 0;
112
 
  nAlloc   = 0;
113
 
  object   = NULL;
 
109
  parent      = NULL;
 
110
  objTag      = NULL;
 
111
  objData     = NULL;
 
112
  nObjects    = 0;
 
113
  nAlloc      = 0;
 
114
  object      = NULL;
 
115
  nAttributes = 0;
 
116
  nAttrAlloc  = 0;
 
117
  attr_name   = NULL;
 
118
  attr_value  = NULL;
114
119
}
115
120
 
116
121
void  CXMLObject::FreeMemory()  {
117
122
int i;
 
123
 
118
124
  if (objTag)   delete[] objTag;
119
125
  if (objData)  delete[] objData;
 
126
 
 
127
  objTag   = NULL;
 
128
  objData  = NULL;
 
129
 
120
130
  if (object)  {
121
131
    for (i=0;i<nAlloc;i++)
122
132
      if (object[i])  delete object[i];
123
133
    delete[] object;
124
134
  }
125
 
  objTag   = NULL;
126
 
  objData  = NULL;
 
135
 
127
136
  nObjects = 0;
128
137
  nAlloc   = 0;
129
138
  object   = NULL;
 
139
 
 
140
  if (attr_name)  {
 
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];
 
144
    }
 
145
    FreeVectorMemory ( attr_name ,0 );
 
146
    FreeVectorMemory ( attr_value,0 );
 
147
  }
 
148
 
 
149
  nAttributes = 0;
 
150
  nAttrAlloc  = 0;
 
151
  attr_name   = NULL;
 
152
  attr_value  = NULL;
 
153
 
130
154
}
131
155
 
132
156
void  CXMLObject::SetTag ( cpstr Tag )  {
175
199
  *t = char(0);
176
200
}
177
201
 
 
202
void  CXMLObject::AddAttribute ( cpstr name, cpstr value )  {
 
203
psvector an,av;
 
204
int      i;
 
205
 
 
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++)  {
 
211
      an[i] = NULL;
 
212
      av[i] = NULL;
 
213
    }
 
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];
 
219
    }
 
220
    FreeVectorMemory ( attr_name ,0 );
 
221
    FreeVectorMemory ( attr_value,0 );
 
222
    attr_name  = an;
 
223
    attr_value = av;
 
224
  }
 
225
 
 
226
  CreateCopy ( attr_name [nAttributes],name  );
 
227
  CreateCopy ( attr_value[nAttributes],value );
 
228
  nAttributes++;
 
229
 
 
230
}
 
231
 
 
232
void  CXMLObject::AddAttribute ( cpstr name, const int iV )  {
 
233
char S[100];
 
234
  sprintf ( S,"%i",iV );
 
235
  AddAttribute ( name,S );
 
236
}
 
237
 
 
238
void  CXMLObject::AddAttribute ( cpstr name, const Boolean bV )  {
 
239
  if (bV)  AddAttribute ( name,"Yes" );
 
240
     else  AddAttribute ( name,"No"  );
 
241
}
 
242
 
178
243
void  CXMLObject::SetData ( cpstr Data )  {
179
244
pstr p,d;
180
245
int  n;
220
285
  CreateConcat ( objData,d1,d2 );
221
286
}
222
287
 
223
 
void  CXMLObject::SetData ( realtype V, int length )  {
 
288
void  CXMLObject::SetData ( const realtype V, const int length )  {
224
289
char N[500];
225
290
  sprintf    ( N,"%-.*g",length,V );
226
291
  CreateCopy ( objData,N );
227
292
}
228
293
 
229
 
void  CXMLObject::SetData ( int iV, int length )  {
 
294
void  CXMLObject::SetData ( const int iV, const int length )  {
230
295
char N[500];
231
296
  sprintf    ( N,"%*i",length,iV );
232
297
  CreateCopy ( objData,N );
233
298
}
234
299
 
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")  );
238
303
}
281
346
      k++;
282
347
    }
283
348
  }
284
 
 
 
349
  
285
350
  if (SName)  {
286
351
    if (SName[0]!=char(1))
287
352
      AddObject ( XMLObject1 );
329
394
    }
330
395
    XMLObject1->AddObject ( XMLObject2 );
331
396
  }
332
 
 
 
397
  
333
398
  if (SName)  {
334
399
    if (SName[0]!=char(1))
335
400
      AddObject ( XMLObject1 );
463
528
  return XMLObject;
464
529
}
465
530
 
 
531
PCXMLObject CXMLObject::GetFirstObject()  {
 
532
  if (nObjects>0)  return object[0];
 
533
  return NULL;
 
534
}
 
535
 
 
536
PCXMLObject CXMLObject::GetLastObject()  {
 
537
  if (nObjects>0)  return object[nObjects-1];
 
538
  return NULL;
 
539
}
 
540
 
 
541
PCXMLObject CXMLObject::GetObject ( int objectNo )  {
 
542
  if ((0<=objectNo) && (objectNo<nObjects))
 
543
    return object[objectNo];
 
544
  return NULL;
 
545
}
 
546
 
 
547
 
466
548
void  CXMLObject::AddObject ( PCXMLObject XMLObject, int lenInc )  {
467
549
PPCXMLObject obj1;
468
550
int          i;
482
564
 
483
565
  if (object[nObjects])  delete object[nObjects];
484
566
  object[nObjects] = XMLObject;
 
567
  XMLObject->SetParent ( this );
485
568
  nObjects++;
486
569
 
487
570
}
513
596
    f.Write ( indstr    );
514
597
    f.Write ( pstr("<") );
515
598
    f.Write ( objTag    );
 
599
    for (i=0;i<nAttributes;i++)  {
 
600
      f.Write ( " " );
 
601
      f.Write ( attr_name[i] );
 
602
      f.Write ( "=\"" );
 
603
      f.Write ( attr_value[i] );
 
604
      f.Write ( "\"" );
 
605
    }
516
606
    if ((!objData) && (nObjects<=0))  {
517
607
      f.WriteLine ( pstr("/>") );
518
608
      delete[] indstr;
607
697
int         k,k1,k2,rc;
608
698
Boolean     Done;
609
699
 
610
 
  k2 = 0; // else may become undefined
611
 
 
612
700
  FreeMemory();
613
701
 
614
702
  rc = XMLR_Ok;
615
703
 
616
704
  k1 = -1;
 
705
  k2 = -1;
617
706
  while ((!f.FileEnd()) && (k1<0))  {
618
707
    k = strlen(S);
619
708
    while ((pos<k) && (k1<0))
717
806
 
718
807
  if (rc!=XMLR_Ok)  FreeMemory();
719
808
  return rc;
720
 
 
 
809
   
721
810
}
722
811
 
723
812
 
724
813
void  CXMLObject::Copy ( PCXMLObject XMLObject )  {
725
814
int i;
 
815
 
726
816
  FreeMemory();
 
817
 
727
818
  CreateCopy ( objTag ,XMLObject->objTag  );
728
819
  CreateCopy ( objData,XMLObject->objData );
 
820
 
729
821
  nObjects = XMLObject->nObjects;
730
822
  nAlloc   = nObjects;
731
823
  if (nObjects>0)  {
737
829
      } else
738
830
        object[i] = NULL;
739
831
  }
 
832
 
 
833
  nAttributes = XMLObject->nAttributes;
 
834
  nAttrAlloc  = nAttributes;
 
835
  if (nAttributes>0)  {
 
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] );
 
843
    }
 
844
  }
 
845
 
740
846
}
741
847
 
742
848
 
743
849
void  CXMLObject::write ( RCFile f )  {
744
850
int i;
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] );
 
860
  }
750
861
}
751
862
 
752
863
void  CXMLObject::read ( RCFile f )  {
753
864
int i;
 
865
 
754
866
  FreeMemory();
 
867
 
755
868
  f.CreateRead ( objTag    );
756
869
  f.CreateRead ( objData   );
 
870
 
757
871
  f.ReadInt    ( &nObjects );
758
872
  nAlloc = nObjects;
759
873
  if (nObjects>0)  {
763
877
      StreamRead ( f,object[i] );
764
878
    }
765
879
  }
 
880
 
 
881
  f.ReadInt    ( &nAttributes );
 
882
  nAttrAlloc = nAttributes;
 
883
  if (nAttributes>0)  {
 
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] );
 
891
    }
 
892
  }
 
893
 
766
894
}
767
895
 
768
896