ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new-templateless/OOPSE/libmdtools/GenericData.cpp
(Generate patch)

Comparing:
trunk/OOPSE/libmdtools/GenericData.cpp (file contents), Revision 682 by tim, Tue Aug 12 17:51:33 2003 UTC vs.
branches/new-templateless/OOPSE/libmdtools/GenericData.cpp (file contents), Revision 851 by mmeineke, Wed Nov 5 19:18:17 2003 UTC

# Line 1 | Line 1
1 + #include <stdlib.h>
2 + #include <string.h>
3 +
4   #include "GenericData.hpp"
5  
6   GenericData::GenericData(){
7  
8 <  id = "undefined";
8 >  next   = NULL;
9 >  sameNext = NULL;
10 >  dArray = NULL;
11 >  strcpy( id, "undefined" );
12 > }
13  
14 + GenericData::GenericData(char* theID){
15 +
16 +  next   = NULL;
17 +  sameNext = NULL;
18 +  dArray = NULL;
19 +  strcpy( id, theID );
20   }
21  
22 < GenericData& GenericData::operator = (const GenericData& rhs){
22 > GenericData::GenericData(char* theID, double theDval){
23 >
24 >  next   = NULL;
25 >  sameNext = NULL;
26 >  dArray = NULL;
27 >  strcpy( id, theID );
28 >  dVal = theDval;
29 > }
30 >
31 > GenericData::GenericData(char* theID, char* theCval){
32 >
33 >  next   = NULL;
34 >  sameNext = NULL;
35 >  dArray = NULL;
36 >  strcpy( id, theID );
37 >  strcpy( cVal, theCval );
38 > }
39 >
40 > GenericData::GenericData(char* theID, double* theDarray, int theArrayLength){
41 >  int i;
42    
43 <  if(this == &rhs)
44 <    return (*this);
43 >  next   = NULL;
44 >  sameNext = NULL;
45 >  dArray = NULL;
46 >  strcpy( id, theID );
47    
48 <  id = rhs.id;
48 >  arrayLength = theArrayLength;
49 >  dArray = new double[arrayLength];
50 >  for(i=0;i<arrayLength;i++)
51 >    dArray[i]=theDarray[i];
52 > }
53 >
54 > GenericData* GenericData::add(char* theID){
55    
56 <  return *this;
56 >  if( !strcmp( theID, id ) ){
57 >    
58 >    if( sameNext != NULL )
59 >      return sameNext->add( theID );
60 >    
61 >    sameNext = new GenericData( theID );
62 >    return sameNext;
63 >  }
64 >
65 >  if( next != NULL )
66 >    return next->add( theID );
67 >
68 >  next = new GenericData( theID );
69 >  return next;
70   }
71  
72 < ZConsParaData::ZConsParaData(){
73 <  id = ZCONSPARADATA_ID;
72 > GenericData* GenericData::add(char* theID, double theDval){
73 >  
74 >  if( !strcmp( theID, id ) ){
75 >    
76 >    if( sameNext != NULL )
77 >      return sameNext->add( theID, theDval );
78 >    
79 >    sameNext = new GenericData( theID, theDval );
80 >    return sameNext;
81 >  }
82 >
83 >  if( next != NULL )
84 >    return next->add( theID, theDval );
85 >
86 >  next = new GenericData( theID, theDval );
87 >  return next;
88   }
89  
90 < void ZConsParaData::sortByIndex(){
91 <  sort(data.begin(), data.end(), ZConsParaSortCriterion());
92 < }
90 > GenericData* GenericData::add(char* theID, char* theCval){
91 >  
92 >  if( !strcmp( theID, id ) ){
93 >    
94 >    if( sameNext != NULL )
95 >      return sameNext->add( theID, theCval );
96 >    
97 >    sameNext = new GenericData( theID, theCval );
98 >    return sameNext;
99 >  }
100 >
101 >  if( next != NULL )
102 >    return next->add( theID, theCval );
103 >
104 >  next = new GenericData( theID, theCval );
105 >  return next;
106 > }
107 >
108 > GenericData* GenericData::add(char* theID,
109 >                              double* theDarray,
110 >                              int theArrayLength){
111 >  
112 >  if( !strcmp( theID, id ) ){
113 >    
114 >    if( sameNext != NULL )
115 >      return sameNext->add( theID, theDarray, theArrayLength );
116 >    
117 >    sameNext = new GenericData( theID, theDarray, theArrayLength );
118 >    return sameNext;
119 >  }
120 >
121 > if( next != NULL )
122 >    return next->add( theID, theDarray, theArrayLength );
123 >
124 >  next = new GenericData( theID, theDarray, theArrayLength );
125 >  return next;
126 > }
127 >
128 > void GenericData::setValue(double theDval){
129 >  dVal = theDval;
130 > }
131 >
132 > void GenericData::setValue(char* theCval){
133 >  strcpy( cVal, theCval );
134 > }
135 >  
136 > void GenericData::setValue(double* theDarray, int theArrayLength){
137 >  
138 >  int i;
139 >  
140 >  arrayLength = theArrayLength;
141 >  dArray = new double[arrayLength];
142 >  for(i=0;i<arrayLength;i++)
143 >    dArray[i]=theDarray[i];
144 > }
145 >
146 > void GenericData::setID( char* theID ){
147 >  strcpy( id, theID );
148 > }
149 >
150 > int GenericData::getDarray( double* &outArray ){
151 >
152 >  int i;
153 >  
154 >  outArray = new double[arrayLength];
155 >  for(i=0;i<arrayLength;i++)
156 >    outArray[i] = dArray[i];
157 >
158 >  return arrayLength;
159 > }
160 >
161 > GenericData* GenericData::find( char* findID ){
162 >
163 >  if(!strcmp( findID, id ))
164 >    return this;
165 >  
166 >  if( next != NULL )
167 >    return next->find( findID );
168 >  
169 >  return NULL;  
170 > }
171 >
172 >
173 > // void ZConsParaData::sortByIndex(){
174 > //   sort(data.begin(), data.end(), ZConsParaSortCriterion());
175 > // }
176 > // bool ZConsParaData::isIndexUnique(){
177 >  
178 > //   for(int i = 0; i < (int)(data.size() - 1); i++)
179 > //     for(int j = i + 1; j < (int)(data.size()); j++)
180 > //       if(data[i].zconsIndex == data[j].zconsIndex)
181 > //         return false;  
182 >
183 > //   return true;
184 > // }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines