| 1 |
mmeineke |
850 |
#include <stdlib.h> |
| 2 |
|
|
#include <string.h> |
| 3 |
|
|
|
| 4 |
tim |
658 |
#include "GenericData.hpp" |
| 5 |
|
|
|
| 6 |
|
|
GenericData::GenericData(){ |
| 7 |
|
|
|
| 8 |
mmeineke |
850 |
next = NULL; |
| 9 |
|
|
sameNext = NULL; |
| 10 |
|
|
dArray = NULL; |
| 11 |
|
|
strcpy( id, "undefined" ); |
| 12 |
|
|
} |
| 13 |
tim |
658 |
|
| 14 |
mmeineke |
850 |
GenericData::GenericData(char* theID){ |
| 15 |
|
|
|
| 16 |
|
|
next = NULL; |
| 17 |
|
|
sameNext = NULL; |
| 18 |
|
|
dArray = NULL; |
| 19 |
|
|
strcpy( id, theID ); |
| 20 |
tim |
658 |
} |
| 21 |
|
|
|
| 22 |
mmeineke |
850 |
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 |
tim |
658 |
|
| 43 |
mmeineke |
850 |
next = NULL; |
| 44 |
|
|
sameNext = NULL; |
| 45 |
|
|
dArray = NULL; |
| 46 |
|
|
strcpy( id, theID ); |
| 47 |
tim |
658 |
|
| 48 |
mmeineke |
850 |
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 |
tim |
658 |
|
| 56 |
mmeineke |
850 |
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 |
tim |
658 |
} |
| 71 |
|
|
|
| 72 |
mmeineke |
850 |
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 |
tim |
658 |
} |
| 89 |
|
|
|
| 90 |
mmeineke |
850 |
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 |
tim |
736 |
} |
| 107 |
mmeineke |
850 |
|
| 108 |
|
|
GenericData* GenericData::add(char* theID, |
| 109 |
|
|
double* theDarray, |
| 110 |
|
|
int theArrayLength){ |
| 111 |
tim |
736 |
|
| 112 |
mmeineke |
850 |
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 |
tim |
736 |
|
| 121 |
mmeineke |
850 |
if( next != NULL ) |
| 122 |
|
|
return next->add( theID, theDarray, theArrayLength ); |
| 123 |
|
|
|
| 124 |
|
|
next = new GenericData( theID, theDarray, theArrayLength ); |
| 125 |
|
|
return next; |
| 126 |
tim |
736 |
} |
| 127 |
mmeineke |
850 |
|
| 128 |
mmeineke |
851 |
void GenericData::setValue(double theDval){ |
| 129 |
mmeineke |
850 |
dVal = theDval; |
| 130 |
|
|
} |
| 131 |
|
|
|
| 132 |
mmeineke |
851 |
void GenericData::setValue(char* theCval){ |
| 133 |
mmeineke |
850 |
strcpy( cVal, theCval ); |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
mmeineke |
851 |
void GenericData::setValue(double* theDarray, int theArrayLength){ |
| 137 |
mmeineke |
850 |
|
| 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 |
mmeineke |
851 |
int GenericData::getDarray( double* &outArray ){ |
| 151 |
mmeineke |
850 |
|
| 152 |
|
|
int i; |
| 153 |
|
|
|
| 154 |
mmeineke |
851 |
outArray = new double[arrayLength]; |
| 155 |
mmeineke |
850 |
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 |
|
|
// } |