Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

breakpoints.cpp

Go to the documentation of this file.
00001 
00034 #include "breakpoints.H"
00035 
00041 Breakpoints::Breakpoints(int quant) {
00042   quantMax = quant;
00043   if ( ( bp = (unsigned int *) calloc( quantMax,
00044                                        sizeof( unsigned int ) ) ) == NULL )
00045     {
00046       perror( "Couldn't allocate breakpoint array." );
00047       quantMax = 0;
00048     }
00049   memset( bp, 255, sizeof(unsigned int)* quantMax );
00050   this->quant = 0; /* no breakpoints at start up */
00051 }
00052 
00053 
00057 Breakpoints::~Breakpoints() {
00058   if ( bp ) free( bp );
00059   bp = NULL;
00060 }
00061 
00062 
00070 int Breakpoints::add(unsigned int address) {
00071   int i, tmp;
00072 
00073   if ( ( ! bp ) || ( quant >= quantMax ) )
00074     return -1;
00075 
00076   for ( i = 0; i < quant; i++ )
00077     /* Insert in order */
00078     if ( address < bp[i] )
00079       {
00080         tmp     = address;
00081         address = bp[i];
00082         bp[i]   = tmp;
00083       }
00084 
00085   bp[ quant ++ ] = address;
00086   return 0;
00087 }
00088 
00089 
00097 int Breakpoints::remove(unsigned int address) {
00098   int i;
00099 
00100   if ( ( ! bp ) || ( quant >= quantMax ) )
00101     return -1;
00102 
00103   for ( i = 0; i < quant; i ++ )
00104     if ( bp[ i ] == address )
00105       {
00106         /* Copy remaining breakpoints: [ a | b | c ] => [ a | c ] */
00107         for ( ; i < ( quant - 1 ); i ++ )
00108           bp[ i ] = bp[ i + 1 ];
00109 
00110         quant --;
00111         return 0;
00112       }
00113 
00114   return -1;
00115 }
00116 
00124 int Breakpoints::exists(unsigned int address) {
00125   int i;
00126 
00127   if ( ( ! bp ) || ( quant >= quantMax ) )
00128     return 0;
00129 
00130   for ( i = 0; i < quant; i ++ )
00131     if ( address == bp[ i ] )
00132       return 1;
00133     else
00134       /* bp is crescent order, so if current element is greater than desired
00135        * address, there's no address in list
00136        */
00137       if (  bp[ i ] > address )
00138         return 0;
00139 
00140   return 0;
00141 }

Generated on Thu Jun 24 08:30:05 2004 for ArchC by doxygen 1.3.4