CPersistentTranslatedIndexMatrix< TTID, TTContent > Class Template Reference

#include <CPersistentTranslatedIndexMatrix.h>

List of all members.

Public Types

typedef map< TTID, TTContent > CIDContentPairList
typedef vector< TTID > CIndexList

Public Member Functions

 CPersistentTranslatedIndexMatrix ()
bool create (const char *inFileName, const CIndexList &inIndexList)
bool open (const char *inFileName)
bool putLineVector (const TTID &inID, const CLineVector &inVector) const
bool getLineVector (const TTID &inID, CLineVector &outVector) const
bool putLineVector (const TTID &inID, const CIDContentPairList &inList) const
bool getLineVector (const TTID &inI, CIDContentPairList &outList) const
bool setValue (const TTID &inX, const TTID &inX, const TTContent &inValue) const
 operator bool () const
long size () const

Protected Types

typedef vector< TTContent > CLineVector
typedef map< TTID, long > CTranslator
 FIXME: taking a map here is a performance flaw.
typedef CPersistentMatrix
< TTContent > 
CMatrix

Protected Attributes

CTranslator mTranslator
CMatrixmContent


Detailed Description

template<class TTID, class TTContent>
class CPersistentTranslatedIndexMatrix< TTID, TTContent >

Definition at line 40 of file CPersistentTranslatedIndexMatrix.h.


Member Typedef Documentation

template<class TTID, class TTContent>
typedef map<TTID,TTContent> CPersistentTranslatedIndexMatrix< TTID, TTContent >::CIDContentPairList

Definition at line 43 of file CPersistentTranslatedIndexMatrix.h.

template<class TTID, class TTContent>
typedef vector<TTID> CPersistentTranslatedIndexMatrix< TTID, TTContent >::CIndexList

Definition at line 45 of file CPersistentTranslatedIndexMatrix.h.

template<class TTID, class TTContent>
typedef vector<TTContent> CPersistentTranslatedIndexMatrix< TTID, TTContent >::CLineVector [protected]

Definition at line 48 of file CPersistentTranslatedIndexMatrix.h.

template<class TTID, class TTContent>
typedef map<TTID,long> CPersistentTranslatedIndexMatrix< TTID, TTContent >::CTranslator [protected]

FIXME: taking a map here is a performance flaw.

Definition at line 50 of file CPersistentTranslatedIndexMatrix.h.

template<class TTID, class TTContent>
typedef CPersistentMatrix<TTContent> CPersistentTranslatedIndexMatrix< TTID, TTContent >::CMatrix [protected]

Definition at line 52 of file CPersistentTranslatedIndexMatrix.h.


Constructor & Destructor Documentation

template<class TTID, class TTContent>
CPersistentTranslatedIndexMatrix< TTID, TTContent >::CPersistentTranslatedIndexMatrix (  )  [inline]

Definition at line 89 of file CPersistentTranslatedIndexMatrix.h.

00089                                   :
00090   mContent(0)
00091 {
00092   
00093 };


Member Function Documentation

template<class TTID, class TTContent>
bool CPersistentTranslatedIndexMatrix< TTID, TTContent >::create ( const char *  inFileName,
const CIndexList inIndexList 
) [inline]

Definition at line 97 of file CPersistentTranslatedIndexMatrix.h.

00098                                  {
00099   CIndexList lIndexList(inIndexList);
00100   sort(lIndexList.begin(),lIndexList.end());
00101 
00102   long lCount=0;
00103   for(typename CIndexList::const_iterator i=lIndexList.begin();
00104       i!=lIndexList.end();
00105       i++,lCount++){
00106     mTranslator.insert(make_pair(*i,lCount));
00107   }
00108   mContent=new CMatrix(lCount,lCount);
00109   if(mContent){
00110     string lStreamName=string(inFileName)+string(".trans");
00111     ofstream lStream(lStreamName.c_str());
00112     if(lStream){
00113       for(typename CTranslator::const_iterator i=mTranslator.begin();
00114     i!=mTranslator.end();
00115     i++){
00116   lStream << i->first 
00117     << " " 
00118     << i->second 
00119     << endl;
00120       }
00121     }
00122     return lStream && mContent->create(inFileName) ;
00123   }
00124   return false;
00125 };

template<class TTID, class TTContent>
bool CPersistentTranslatedIndexMatrix< TTID, TTContent >::open ( const char *  inFileName  )  [inline]

Definition at line 129 of file CPersistentTranslatedIndexMatrix.h.

References HERE.

00129                             {
00130   long lCount=0;
00131 
00132   delete mContent;
00133   
00134   mTranslator.clear();
00135   string lStreamName=string(inFileName)+string(".trans");
00136   ifstream lStream(lStreamName.c_str());
00137   if(lStream){
00138     cout << HERE
00139    << "Opened translator stream" 
00140    << endl;
00141   }else{
00142     cout << HERE << "FAILED" << endl;
00143     assert(0);
00144   }
00145   //reading pairs: left side is ID-element in ascii
00146   //right side is index in vector
00147   if(lStream){
00148     while(lStream){
00149       TTID lFirst;
00150       long lSecond;
00151       lStream >> lFirst 
00152         >> lSecond;
00153       mTranslator.insert(make_pair(lFirst,lSecond));
00154     }
00155   }
00156   cout << HERE 
00157        << "After reading translator: " 
00158        << this->size()
00159        << " elements in translator"
00160        << endl;
00161   mContent=new CMatrix(size(),
00162            size());
00163   mContent->open(inFileName);
00164 
00165   assert(mContent->operator bool());
00166   cout << HERE 
00167        << "OPEN3" 
00168        << endl;
00169   return lStream && mContent->operator bool();
00170 }

template<class TTID, class TTContent>
bool CPersistentTranslatedIndexMatrix< TTID, TTContent >::putLineVector ( const TTID &  inID,
const CLineVector inVector 
) const [inline]

Definition at line 228 of file CPersistentTranslatedIndexMatrix.h.

00229                                      {
00230 
00231   if(mTranslator.find(inID)!=mTranslator.end()){
00232     long lLine=mTranslator.find(inID)->second;
00233 
00234     return mContent->putLineVector(lLine,inVector);
00235   }else{
00236     assert(!"There is no ID of this kind");
00237   }
00238   return 0;
00239 };

template<class TTID, class TTContent>
bool CPersistentTranslatedIndexMatrix< TTID, TTContent >::getLineVector ( const TTID &  inID,
CLineVector outVector 
) const [inline]

Definition at line 174 of file CPersistentTranslatedIndexMatrix.h.

00175                                 {
00176   assert(mContent);
00177 
00178 #ifdef CPTIM_DEBUG
00179   cout << "(" << inID << ")" << endl;
00180 #endif
00181 
00182   if(mTranslator.find(inID)!=mTranslator.end()){
00183     long lLocalLine=mTranslator.find(inID)->second;
00184 #ifdef CPTIM_DEBUG
00185     cout << "getting Line: " 
00186    << lLocalLine 
00187    << endl;
00188 #endif
00189     return mContent->getLineVector(lLocalLine,outVector);
00190   }else{
00191     cout <<"<<dumping"<<endl;
00192     for(typename CTranslator::const_iterator i=mTranslator.begin();
00193   i!=mTranslator.end();
00194   i++){
00195       cout << i->first << "," << i->second << endl;
00196     }
00197     cout << "dumping>>"<<endl;
00198     assert(!"NotFound");
00199   }
00200   return false;
00201 };

template<class TTID, class TTContent>
bool CPersistentTranslatedIndexMatrix< TTID, TTContent >::putLineVector ( const TTID &  inID,
const CIDContentPairList inList 
) const [inline]

Definition at line 243 of file CPersistentTranslatedIndexMatrix.h.

00244                                           {
00245   CLineVector lVector(size());
00246   bool lReturnValue=getLineVector(inID,
00247           lVector);
00248   cout << "inID" << inID << endl;
00249   assert(lReturnValue);
00250 
00251   for(typename CIDContentPairList::const_iterator i=inList.begin();
00252       i!=inList.end();
00253       i++){
00254     typename CTranslator::const_iterator lXPosition=mTranslator.find(i->first);
00255     if(lXPosition!=mTranslator.end()){
00256       lVector[lXPosition->second]=i->second;
00257     }
00258   }
00259 
00260   return lReturnValue && putLineVector(inID,
00261                lVector);
00262 };

template<class TTID, class TTContent>
bool CPersistentTranslatedIndexMatrix< TTID, TTContent >::getLineVector ( const TTID &  inI,
CIDContentPairList outList 
) const [inline]

Definition at line 205 of file CPersistentTranslatedIndexMatrix.h.

00206                                      {
00207   assert(mContent);
00208 
00209   CLineVector lVector(size());
00210   bool lReturnValue=getLineVector(inI,
00211           lVector);
00212   outList.clear();
00213   try{
00214     for(typename CTranslator::const_iterator i=mTranslator.begin();
00215   i!=mTranslator.end();
00216   i++){
00217       outList.insert(make_pair(i->first,
00218              lVector[i->second]));
00219     }
00220   }catch(...){
00221     return false;
00222   }
00223   return lReturnValue;
00224 };

template<class TTID, class TTContent>
bool CPersistentTranslatedIndexMatrix< TTID, TTContent >::setValue ( const TTID &  inX,
const TTID &  inX,
const TTContent &  inValue 
) const

template<class TTID, class TTContent>
CPersistentTranslatedIndexMatrix< TTID, TTContent >::operator bool (  )  const [inline]

Definition at line 272 of file CPersistentTranslatedIndexMatrix.h.

References CPersistentTranslatedIndexMatrix< TTID, TTContent >::mContent.

00272                                                                     {
00273   return mContent && bool(*mContent);
00274 }

template<class TTID, class TTContent>
long CPersistentTranslatedIndexMatrix< TTID, TTContent >::size (  )  const [inline]

Definition at line 267 of file CPersistentTranslatedIndexMatrix.h.

00267            {
00268   return mTranslator.size();
00269 }


Member Data Documentation

template<class TTID, class TTContent>
CTranslator CPersistentTranslatedIndexMatrix< TTID, TTContent >::mTranslator [protected]

Definition at line 54 of file CPersistentTranslatedIndexMatrix.h.

template<class TTID, class TTContent>
CMatrix* CPersistentTranslatedIndexMatrix< TTID, TTContent >::mContent [protected]


The documentation for this class was generated from the following file:

Generated on Wed Jan 7 00:31:10 2009 for Gift by  doxygen 1.5.6