fei_Pattern.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include "fei_Pattern.hpp"
00010 
00011 //-----------------------------------------------------------------------------
00012 fei::Pattern::Pattern(int numIDs, int idType)
00013   : type_(Pattern::NO_FIELD),
00014     numIDs_(numIDs),
00015     totalNumFields_(0),
00016     numIndices_(numIDs),
00017     data_()
00018 {
00019   int i, len = numIDs_*4;
00020   data_.resize(len);
00021   int offset = 0;
00022 
00023   //set idTypes
00024   for(i=0; i<numIDs_; ++i) {
00025     data_[offset++] = idType;
00026   }
00027 
00028   //set numFieldsPerID
00029   for(i=0; i<numIDs_; ++i) {
00030     data_[offset++] = 0;
00031   }
00032 
00033   //set numIndicesPerID
00034   for(i=0; i<numIDs_; ++i) {
00035     data_[offset++] = 1;
00036   }
00037 
00038   //set fieldIDs
00039   for(i=0; i<numIDs_; ++i) {
00040     data_[offset++] = -1;
00041   }
00042 
00043   idTypes_        = &(data_[0]);
00044   numFieldsPerID_ = idTypes_+numIDs_;
00045   numIndicesPerID_= idTypes_+2*numIDs_;
00046   fieldIDs_       = idTypes_+3*numIDs_;
00047 }
00048 
00049 //-----------------------------------------------------------------------------
00050 fei::Pattern::Pattern(int numIDs, int idType,
00051         int fieldID, int fieldSize)
00052   : type_(Pattern::SIMPLE),
00053     numIDs_(numIDs),
00054     totalNumFields_(numIDs),
00055     numIndices_(0), //numIndices_ to be calculated
00056     data_()
00057 {
00058   int i, len = numIDs_*4;
00059   data_.resize(len);
00060   int offset = 0;
00061 
00062   //set idTypes
00063   for(i=0; i<numIDs_; ++i) {
00064     data_[offset++] = idType;
00065   }
00066 
00067   //set numFieldsPerID
00068   for(i=0; i<numIDs_; ++i) {
00069     data_[offset++] = 1;
00070   }
00071 
00072   //set numIndicesPerID
00073   for(i=0; i<numIDs_; ++i) {
00074     data_[offset++] = fieldSize;
00075   }
00076 
00077   //set fieldIDs
00078   for(i=0; i<numIDs_; ++i) {
00079     data_[offset++] = fieldID;
00080   }
00081 
00082   numIndices_ = numIDs_*fieldSize;
00083 
00084   idTypes_        = &(data_[0]);
00085   numFieldsPerID_ = idTypes_+numIDs_;
00086   numIndicesPerID_= idTypes_+2*numIDs_;
00087   fieldIDs_       = idTypes_+3*numIDs_;
00088 }
00089 
00090 //-----------------------------------------------------------------------------
00091 fei::Pattern::Pattern(int numIDs, int idType,
00092         const int* numFieldsPerID,
00093         const int* fieldIDs,
00094         const int* fieldSizes)
00095   : type_(Pattern::SINGLE_IDTYPE),
00096     numIDs_(numIDs),
00097     totalNumFields_(0), //totalNumFields_ to be calculated
00098     numIndices_(0), //numIndices_ to be calculated
00099     data_()
00100 {
00101   int i, len = numIDs_*3;
00102   int maxNumFieldsPerID = 0;
00103   bool oneDistinctFieldID = true;
00104 
00105   for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
00106   data_.resize(len);
00107 
00108   int offset = 0;
00109   //set idTypes
00110   for(i=0; i<numIDs_; ++i) {
00111     data_[offset++] = idType;
00112   }
00113 
00114   //set numFieldsPerID
00115   for(i=0; i<numIDs; ++i) {
00116     data_[offset++] = numFieldsPerID[i];
00117     if (numFieldsPerID[i] > maxNumFieldsPerID) {
00118       maxNumFieldsPerID = numFieldsPerID[i];
00119     }
00120   }
00121 
00122   //next set numIndicesPerID and fieldIDs
00123   int firstFieldID = 0;
00124   if (numIDs > 0) firstFieldID = fieldIDs[0];
00125 
00126   int fieldIDOffset = offset + numIDs;
00127   for(i=0; i<numIDs; ++i) {
00128     int thisNumIndices = 0;
00129     for(int j=0; j<numFieldsPerID[i]; ++j) {
00130       int fieldSize = fieldSizes[totalNumFields_];
00131       int fieldID = fieldIDs[totalNumFields_++];
00132       if (fieldID != firstFieldID) oneDistinctFieldID = false;
00133       data_[fieldIDOffset++] = fieldID;
00134       numIndices_ += fieldSize;
00135       thisNumIndices += fieldSize;
00136     }
00137     data_[offset+i] = thisNumIndices;
00138   }
00139 
00140   if (oneDistinctFieldID == true && maxNumFieldsPerID < 2) {
00141     type_ = Pattern::SIMPLE;
00142   }
00143 
00144   idTypes_        = &(data_[0]);
00145   numFieldsPerID_ = idTypes_+numIDs_;
00146   numIndicesPerID_= idTypes_+2*numIDs_;
00147   fieldIDs_       = idTypes_+3*numIDs_;
00148 }
00149 
00150 //-----------------------------------------------------------------------------
00151 fei::Pattern::Pattern(int numIDs, const int* idTypes,
00152         const int* numFieldsPerID,
00153         const int* fieldIDs,
00154         const int* fieldSizes)
00155   : type_(Pattern::GENERAL),
00156     numIDs_(numIDs),
00157     totalNumFields_(0), //totalNumFields_ to be calculated
00158     numIndices_(0), //numIndices_ to be calculated
00159     data_()
00160 {
00161   int i, len = numIDs*3;
00162   int maxNumFieldsPerID = 0;
00163   bool oneDistinctFieldID = true;
00164   bool oneDistinctIDType = true;
00165 
00166   for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
00167   data_.resize(len);
00168 
00169   int firstIDType = 0;
00170   if (numIDs > 0) firstIDType = idTypes[0];
00171 
00172   int offset = 0;
00173   //set idTypes
00174   for(i=0; i<numIDs; ++i) {
00175     data_[offset++] = idTypes[i];
00176     if (idTypes[i] != firstIDType) oneDistinctIDType = false;
00177   }
00178 
00179   //set numFieldsPerID
00180   for(i=0; i<numIDs; ++i) {
00181     data_[offset++] = numFieldsPerID[i];
00182     if (numFieldsPerID[i] > maxNumFieldsPerID) {
00183       maxNumFieldsPerID = numFieldsPerID[i];
00184     }
00185   }
00186 
00187   //next set numIndicesPerID and fieldIDs
00188   int firstFieldID = 0;
00189   if (numIDs > 0) firstFieldID = fieldIDs[0];
00190 
00191   int fieldIDOffset = offset + numIDs;
00192   for(i=0; i<numIDs; ++i) {
00193     int thisNumIndices = 0;
00194     for(int j=0; j<numFieldsPerID[i]; ++j) {
00195       int fieldSize = fieldSizes[totalNumFields_];
00196       int fieldID = fieldIDs[totalNumFields_++];
00197       if (fieldID != firstFieldID) oneDistinctFieldID = false;
00198       data_[fieldIDOffset++] = fieldID;
00199       numIndices_ += fieldSize;
00200       thisNumIndices += fieldSize;
00201     }
00202     data_[offset+i] = thisNumIndices;
00203   }
00204 
00205   if (oneDistinctFieldID == true && maxNumFieldsPerID < 2 &&
00206       oneDistinctIDType == true) {
00207     type_ = Pattern::SIMPLE;
00208   }
00209   else if (oneDistinctIDType == true) {
00210     type_ = Pattern::SINGLE_IDTYPE;
00211   }
00212 
00213   idTypes_        = &(data_[0]);
00214   numFieldsPerID_ = idTypes_+numIDs_;
00215   numIndicesPerID_= idTypes_+2*numIDs_;
00216   fieldIDs_       = idTypes_+3*numIDs_;
00217 }
00218 
00219 //-----------------------------------------------------------------------------
00220 fei::Pattern::~Pattern()
00221 {
00222 }
00223 
00224 //-----------------------------------------------------------------------------
00225 bool fei::Pattern::operator==(const fei::Pattern& rhs) const
00226 {
00227   return type_ == rhs.type_ &&
00228          numIDs_ == rhs.numIDs_ &&
00229          totalNumFields_ == rhs.totalNumFields_ &&
00230          numIndices_ == rhs.numIndices_ &&
00231          data_ == rhs.data_;
00232 }
00233 
00234 //-----------------------------------------------------------------------------
00235 bool fei::Pattern::operator!=(const fei::Pattern& rhs) const
00236 {
00237   return !(*this == rhs);
00238 }
00239 

Generated on Tue Jul 13 09:27:45 2010 for FEI by  doxygen 1.4.7