CoeffList.cc

Go to the documentation of this file.
00001 #include "CoeffList.h"
00002 #include <stdlib.h>
00003 namespace nCenterFocus
00004 {
00005 
00006 CoeffListEntry::CoeffListEntry() : porq(PCoefficient), x_exp(-1), y_exp(-1), next(NULL) 
00007 {
00008 }
00009 
00010 
00011 CoeffListEntry::CoeffListEntry( P_or_QPolynom   p_oder_q, 
00012                                 const int       yExp,
00013                                 const int       currentMonomDegree):    porq(p_oder_q),
00014                                                                         x_exp(currentMonomDegree-yExp),
00015                                                                         y_exp(yExp), next(NULL)
00016 {
00017 }
00018 /*
00019 CoeffListEntry::CoeffListEntry( const CoeffListEntry & centry): porq(centry.porq),
00020                                                                                         x_exp(centry.x_exp),
00021                                                                                         y_exp(centry.y_exp), 
00022                                                                                         next(centry.next)
00023 {
00024 
00025 }
00026 */
00027 
00028 
00029 CoeffListEntry const * CoeffListEntry::getNextConst() const
00030 {
00031         
00032         return next;
00033 }
00034 
00035 bool CoeffListEntry::operator==(CoeffListEntry &entry) 
00036 {
00037         return ( (porq==entry.porq)  &&   ( x_exp==entry.x_exp )  &&  ( y_exp==entry.y_exp ) );
00038 }
00039 
00040 
00041 CoeffListEntry::~CoeffListEntry()
00042 {
00043         if (next!=NULL)
00044                 delete next;
00045         next=NULL;
00046 }
00047 
00048 
00049 
00050 
00051 CoeffList::CoeffList():last(&head)
00052 {
00053 }
00054 
00055 
00056 void CoeffList::clear()
00057 {
00058         last=NULL;
00059         delete head.next;
00060         head.next=NULL;
00061         last=&head;
00062         
00063 }
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 //---------------------------------------------------------------------------------------
00073 CoeffListEntry* CoeffList::getFirst()
00074 {
00075         return head.next;
00076 }
00077 
00078 CoeffListEntry const * CoeffList::getFirstConst() const
00079 {
00080                 return head.next;
00081 }
00082 
00083 void CoeffListEntry::printEntry(std::ostream & out) const
00084 {
00085         if ( porq==PCoefficient)
00086         {
00087                 out  << " P coeff " ;
00088         }
00089         else
00090         {
00091                 out  << " Q coeff " ;
00092         }
00093         out << "( "<<  x_exp<<", " << y_exp <<" )";
00094         out << std::endl;
00095 }
00096 
00097 std::ostream &  operator<<(std::ostream & out, const CoeffListEntry& centry)
00098 {
00099         centry.printEntry(out);
00100         return out;
00101 }
00102 
00103 
00104 
00105 bool  CoeffList::containsEntry(P_or_QPolynom    p_oder_q, 
00106                                 const int       xExp,
00107                                 const int       yExp) const
00108 {
00109         CoeffListEntry const * entry = getFirstConst();
00110 
00111         while (entry != NULL) // durchlaufe die komplette Liste
00112         {
00113                                 
00114                 if (entry->porq == p_oder_q )
00115                 {
00116                         if ( entry->x_exp==xExp && entry->y_exp==yExp )
00117                                 return true;
00118 
00119                 }
00120                 
00121                 entry = entry-> getNextConst();
00122         }
00123         return false;
00124 }
00125 
00126 
00127 bool CoeffList::containsEntry(const CoeffListEntry & entry ) const
00128 {
00129         return containsEntry(entry.porq, entry.x_exp, entry.y_exp);
00130 }
00131 
00132 
00133 bool CoeffList::isEmpty() const
00134 {
00135         return (head.next==NULL);
00136 }
00137 
00138  
00139 void CoeffList::append(CoeffListEntry * entry)
00140 {
00141         #ifdef SAFE
00142                 assert(entry!=NULL);
00143         #endif
00144         if (entry!=NULL)
00145         {
00146                 last->next=entry;
00147                 last=entry;
00148         }
00149 }
00150 
00151 
00152 void CoeffList::output(std::ostream &os)
00153 {
00154         CoeffListEntry* tmp =head.next;
00155         
00156         while (tmp!=NULL)
00157         {
00158                 if (tmp->porq==PCoefficient)
00159                 {
00160                         os  << " P coeff " ;
00161                 }
00162                 else
00163                 {
00164                         os  << " Q coeff " ;
00165                 }
00166                 os << "( "<< tmp->x_exp<<", " << tmp->y_exp <<" )";
00167                 tmp=tmp->next;
00168         }
00169         os << std::endl;
00170         return;
00171 }
00172 
00173 
00174 CoeffList::~CoeffList()
00175 {
00176         last=NULL;
00177         if (head.next!=NULL)
00178         delete head.next;
00179         head.next=NULL;
00180 }
00181 
00182 };
Generated on Tue Nov 23 13:10:51 2010 for centerfocus by  doxygen 1.6.3