00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00026 #include <string>
00027
00028 #include "Lattice/Lattice.h"
00029 #include "Lattice/LatticeBuilder.h"
00030 #include "Lattice/LatticeMaker.h"
00031 #include "MessageService/MsgService.h"
00032
00033 ClassImp(LatticeMaker)
00034
00035
00036
00037
00038 CVSID("$Id: LatticeMaker.cxx,v 1.2 2001/03/02 08:19:06 west Exp $");
00039
00040
00041
00042
00043
00044
00045
00046
00047 Lattice* LatticeMaker::CreateLattice( const char* nameLeft,
00048 const char* nameRight,
00049 const char* type ) {
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 string latType = type;
00070
00071
00072 if ( latType == "1:n"
00073 ) return new Lattice(nameLeft,
00074 nameRight,
00075 LatticeBase::LNodeMulti,
00076 LatticeBase::RLinkMulti);
00077
00078
00079 if ( latType == "n:1"
00080 ) return new Lattice(nameLeft,
00081 nameRight,
00082 LatticeBase::RNodeMulti,
00083 LatticeBase::LLinkMulti);
00084
00085
00086 return new Lattice(nameLeft,
00087 nameRight,
00088 LatticeBase::LNodeMulti,
00089 LatticeBase::RNodeMulti,
00090 LatticeBase::LLinkMulti,
00091 LatticeBase::RLinkMulti);
00092 }
00093
00094
00095 Lattice* LatticeMaker::CreateLattice( const TObject* objLeft,
00096 const TObject* objRight,
00097 const char* type ) {
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 return CreateLattice(objLeft->ClassName(),
00119 objRight->ClassName(),
00120 type);
00121
00122 }
00123
00124
00125 Lattice* LatticeMaker::CreateLattice(const TCollection* setLeft,
00126 const TCollection* setRight,
00127 AssociateFunc* asFunc,
00128 const char* type ) {
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 TIter itrLeft(setLeft);
00148 TIter itrRight(setRight);
00149 TObject* objLeft = itrLeft();
00150 TObject* objRight = itrRight();
00151
00152 if ( ! objLeft || ! objRight ) {
00153 MSG("Lat",Msg::kWarning)
00154 << "Cannot build lattice; one or both sets empty," << endl;
00155 return 0;
00156 }
00157
00158
00159 Lattice* lat = CreateLattice(objLeft->ClassName(),
00160 objRight->ClassName(),
00161 type);
00162
00163 string latType = type;
00164 itrLeft.Reset();
00165 itrRight.Reset();
00166
00167 if ( latType == "1:n" ) {
00168 while ( (objRight = itrRight()) ){
00169 itrLeft.Reset();
00170 while ( (objLeft = itrLeft()) ) {
00171 if ( asFunc(objLeft,objRight) ) {
00172 lat->ConnectLR(objLeft,0,objRight);
00173 break;
00174 }
00175 }
00176 }
00177
00178 }
00179 else if ( latType == "n:1" ) {
00180 while ( (objLeft = itrLeft()) ){
00181 itrRight.Reset();
00182 while ( (objRight = itrRight()) ) {
00183 if ( asFunc(objLeft,objRight) ) {
00184 lat->ConnectLR(objLeft,0,objRight);
00185 break;
00186 }
00187 }
00188 }
00189 }
00190
00191 else {
00192 while ( (objLeft = itrLeft()) ){
00193 itrRight.Reset();
00194 while ( (objRight = itrRight()) ) {
00195 if ( asFunc(objLeft,objRight)
00196 ) lat->ConnectLR(objLeft,0,objRight);
00197 }
00198 }
00199 }
00200
00201
00202 return lat;
00203
00204 }
00205
00206
00207 Lattice* LatticeMaker::Create1ToNLattice(const TCollection* setLeft,
00208 const TCollection* setRight,
00209 KeyFunc* leftFunc,
00210 KeyFunc* rightFunc ) {
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 TIter itrLeft(setLeft);
00233 TIter itrRight(setRight);
00234 TObject* objLeft = itrLeft();
00235 TObject* objRight = itrRight();
00236
00237 if ( ! objLeft || ! objRight ) {
00238 MSG("Lat",Msg::kWarning)
00239 << "Cannot build lattice; one or both sets empty," << endl;
00240 return 0;
00241 }
00242
00243
00244 Lattice* lat = CreateLattice(objLeft->ClassName(),
00245 objRight->ClassName(),
00246 "1:n");
00247
00248
00249
00250 LatticeBuilder builder;
00251 builder.DockLattice(lat, Lattice::kLeft);
00252
00253
00254 itrLeft.Reset();
00255 while ( (objLeft = itrLeft() )
00256 ) builder.AddPrimary(leftFunc(objLeft), objLeft);
00257
00258
00259 itrRight.Reset();
00260 while ( (objRight = itrRight() )
00261 ) builder.AddSecondary(rightFunc(objRight), objRight);
00262
00263 return lat;
00264
00265 }