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

cabal_line.cpp

00001 /*
00002    Cabal - cabal_line
00003    Short description
00004 
00005    $Id: cabal_line.cpp,v 1.3 2004/04/05 21:54:18 jonnymind Exp $
00006 ---------------------------------------------
00007    Begin      : gio mar 25 2004 $TIME$
00008    Author     : Giancarlo Niccolai <gc@niccolai.ws>, (C) 2004
00009 
00010    Last modified because:
00011 
00012 */
00013 
00014 /**************************************************************************
00015 *   This program is free software; you can redistribute it and/or modify  *
00016 *   it under the terms of the GNU Library General Public License as       *
00017 *   published by the Free Software Foundation; either version 2.1 of the  *
00018 *   License, or (at your option) any later version.                       *
00019 ***************************************************************************/
00020 
00021 #include <cabal_os.h>
00022 #include <cabal_line.h>
00023 #include <cabal_conn.h>
00024 
00025 namespace Cabal
00026 {
00027 
00028 Line::Line( const long bwd, const int arraySize )
00029    :Waiter( bwd )
00030 {
00031    assert( arraySize > 0 );
00032    m_aSize = arraySize;
00033    m_conArray = new Connection *[arraySize];
00034    m_conMap = 0;
00035    
00036    for ( int i = 0; i < arraySize; i ++ ) 
00037    {
00038       m_conArray[i] = 0;
00039    }      
00040    
00041 }
00042 
00043 Line::Line( const long bwd )
00044 {
00045    m_bandwidth = bwd;
00046    m_conArray = 0;
00047    m_conMap = new ConMap;
00048    
00049    m_lastSentTime = -1001; // more than one second before 
00050    m_lastSentSize = 0;   
00051 }
00052 
00053 Line::~ Line()
00054 {
00055    if ( m_conArray ) {
00056       for( int i=0; i < m_aSize ; i++ ) {
00057          delete m_conArray[i];
00058       }
00059       delete m_conArray;
00060    }
00061    
00062    if ( m_conMap ) { 
00063       ConMap::iterator iter = m_conMap->begin();
00064       while( iter != m_conMap->end() ){
00065          delete iter->second;
00066          iter++;
00067       }
00068       delete m_conMap;
00069    }
00070 }
00071    
00072 
00073 Connection *Line::set( const int conId, Connection *con )
00074 {
00075    assert( m_conArray != 0 );
00076    assert( conId >= 0 && conId < m_aSize );
00077    if ( m_conArray[ conId ] ) delete m_conArray[ conId ];
00078    m_conArray[ conId ] = con;
00079    con->line( this );
00080    return con;
00081 }
00082 
00083 
00084 Connection *Line::set( const std::string &conName, Connection *con )   
00085 {
00086    assert( m_conMap != 0 );
00087    
00088    ConMap::iterator iter = m_conMap->find( conName );
00089    if ( iter != m_conMap->end() ) {
00090       delete iter->second;
00091       iter->second = con;
00092    }
00093    else {
00094       (*m_conMap)[ conName ] = con;
00095    }
00096    con->line( this );
00097    return con;
00098 }
00099 
00100 
00101 Connection *Line::get( const int conId ) const
00102 {
00103    assert( m_conArray != 0 );
00104    assert( conId >= 0 && conId < m_aSize );
00105    return m_conArray[ conId ];
00106 }
00107    
00108 Connection *Line::get( const std::string &conName ) const
00109 {
00110    assert( m_conMap != 0 );
00111    ConMap::iterator iter = m_conMap->find( conName );
00112    if ( iter != m_conMap->end() ) {
00113       return iter->second;
00114    }
00115    else {
00116       return 0;
00117    }
00118 }
00119 
00120 
00124 void Line::remove( Connection *con )
00125 {
00126    if ( m_conArray ) {
00127       for( int i = 0; i < m_aSize ; i++ )
00128       {
00129          if ( m_conArray[ i ] == con ) {
00130             m_conArray[ i ] = 0;
00131             delete con;
00132             break;
00133          }
00134       }
00135    }
00136    else if ( m_conMap ) {
00137       ConMap::iterator iter = m_conMap->begin();
00138       while( iter != m_conMap->end() ) {
00139          if ( iter->second == con ) {
00140             m_conMap->erase( iter );
00141             delete con;
00142             break;
00143          }
00144       }
00145    }
00146 }
00147 
00148 };
00149 
00150 /* end of cabal_line */

Generated on Sat Apr 10 17:41:48 2004 for Cabal by doxygen 1.3.5