Generated on Tue Dec 16 13:34:01 2008 for ell-3.0.0 by doxygen 1.5.1

src/ell/protein/S_LP_PullM.cc

Go to the documentation of this file.
00001 #include "ell/State.hh"
00002 #include "ell/protein/S_LP_PullM.hh"
00003 #include <biu/LatticeProtein_Ipnt.hh>
00004 #include <biu/PullMoveSet.hh>
00005 #include <biu/LatticeDescriptorCUB.hh>
00006 #include <biu/assertbiu.hh>
00007 
00008 namespace ell
00009 {
00010 
00011 const std::string S_LP_PullM::ID = std::string("ell::S_LP_PullM");
00012 
00013 // TODO maybe better to replace pointer copy with real clone to avoid dependency to external data
00014 // inconsistency to copy construction 
00015 S_LP_PullM::S_LP_PullM(     biu::LatticeProtein_I* _latProt,
00016                             biu::LatticeMoveSet* _moveSet)
00017     : S_LP(_latProt, _moveSet)
00018     {}
00019 
00020 S_LP_PullM::S_LP_PullM( const S_LP_PullM& s)
00021     : S_LP( s.latProt->clone(), s.moveSet->clone() )
00022     {}
00023 
00024 S_LP_PullM::~S_LP_PullM()
00025     {}
00026 
00027 const std::string & 
00028 S_LP_PullM::getID( void ) const {
00029     return S_LP_PullM::ID; 
00030 }
00031 
00032 
00033 S_LP_PullM* 
00034 S_LP_PullM::clone(State* toFill) const
00035 {
00036     assertbiu(latProt != NULL , "no lattice protein (NULL)");
00037     assertbiu(moveSet != NULL , "no move set (NULL)");
00038     if (toFill == NULL) {
00039         return new S_LP_PullM(*this);
00040     }
00041       // cast toFill
00042     assertbiu(dynamic_cast<S_LP_PullM*>(toFill) != NULL
00043                 , "toFill is no instance of S_LP_PullM");
00044     S_LP_PullM* s = static_cast<S_LP_PullM*>(toFill);
00045       // copy data
00046     s->latProt->operator=(*(this->latProt));
00047       // TODO replace with copying instead of destruction and new allocation !
00048     delete s->moveSet;
00049     s->moveSet = this->moveSet->clone();
00050 
00051     return s;
00052 }
00053 
00054 State* 
00055 S_LP_PullM::fromString(const std::string& stringRep) const {
00056     return new S_LP_PullM(this->latProt->fromString(stringRep), 
00057                             this->moveSet->clone());
00058 }
00059 
00060 
00061 
00063     
00064         /* Access to a compressed sequence representation of the state.
00065          * @return the compressed sequence representation
00066          */
00067     CSequence  
00068     S_LP_PullM::compress(void) const {
00069         return latProt->getLatticeModel()->getDescriptor()->
00070                     getAlphabet()->compress(latProt->getMoveSeqAbs());
00071     }
00072     
00073         /* Access to a compressed sequence representation of the state.
00074          * @param toFill a data structure to write the compressed 
00075          *               representation too
00076          * @return the compressed sequence representation
00077          */
00078     CSequence&  
00079     S_LP_PullM::compress(CSequence& toFill) const {
00080         toFill = latProt->getLatticeModel()->getDescriptor()->
00081                     getAlphabet()->compress(latProt->getMoveSeqAbs());
00082         return toFill;
00083     }
00084     
00085         /* Uncompresses a compressed sequence representation into a new
00086          * State object.
00087          * @param cseq the compressed sequence representation of a state
00088          * @param toFill a state object to uncompress too or NULL if a new 
00089          *               object has to be created
00090          * @return new State object that is encoded in cseq or NULL in error
00091          *         case.
00092          */
00093     State*  
00094     S_LP_PullM::uncompress(const CSequence& cseq, State* toFill) const {
00095         
00096         const std::string newSeq =
00097             latProt->getLatticeModel()->getString(
00098                     latProt->getLatticeModel()->getDescriptor()->
00099                     getAlphabet()->decompress(cseq, latProt->getLength()-1));
00100         
00101         if (toFill==NULL) {
00102             // create new object
00103             biu::LatticeProtein_I* newProt = latProt->clone();
00104             newProt->setMoveStrAbs(newSeq);
00105             toFill = new S_LP_PullM(newProt, moveSet->clone());
00106         }
00107         else
00108         {
00109             S_LP_PullM* s = dynamic_cast<S_LP_PullM*>(toFill);
00110             assertbiu(s != NULL, "casting to S_LP_PullM failed");
00111             s->latProt->setMoveStrAbs(newSeq);
00112             toFill = s;
00113         }
00114         
00115         return toFill;
00116     }
00117     
00118         /* Uncompresses a compressed sequence representation into a this
00119          * State object.
00120          * @param cseq the compressed sequence representation of a state
00121          * @return this or NULL in error case
00122          */
00123     State*  
00124     S_LP_PullM::uncompress(const CSequence& cseq) {
00125         return uncompress(cseq, this);
00126     }
00127 
00128 } // namespace ell