/* Copyright (c) 20011 Hovanes Egiyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "BaseIUBuffer.hh" //! Check if connections with conNum have messages //! in this particular buffer without creating new keys. bool BaseIUBuffer::KeyExists( const string portName ) const { return (count( portName ) != 0); } //! Check if port portName and address addr have messages //! in this particular buffer without creating new keys. bool BaseIUBuffer::KeyExists( const string portName, const int addr ) const { if ( KeyExists( portName ) ) { const map >& tmpMap = (*const_cast( this ))[portName]; return (tmpMap.count( addr ) != 0); } else { return false; } } //! Remove all messages from port portName and address addr //! Remove the keys as well void BaseIUBuffer::Clear( const string portName, const int addr ) { // cout << "Erasing address " << hex << showbase << addr << " frm FIFO for " // << portName << endl; if ( KeyExists( portName, addr ) ) { (*this)[portName][addr].clear(); //! Clear the deque (*this)[portName].erase( addr ); //! removed the address key from map } // cout << "Removed" << endl; return; } //! remove all messages from port portName. Remove address keys as well. void BaseIUBuffer::Clear( const string portName ) { if ( KeyExists( portName ) ) { map >& tmpMap = (*this)[portName]; for ( map >::iterator it = tmpMap.begin(); it != tmpMap.end(); it++ ) { int addr = it->first; tmpMap[addr].clear(); //! Clear the deque // tmpMap.erase( addr ); //! removed the address key from map } tmpMap.clear(); } return; } //! Print content of the buffer into the stream void BaseIUBuffer::Print( ostream& os ) const { msgMap::iterator itNum; //! drop constness BaseIUBuffer* varBuffer = const_cast( this ); //! get the reference to the map msgMap& numMap = dynamic_cast( *varBuffer ); for ( itNum = numMap.begin(); itNum != numMap.end(); itNum++ ) { map >::iterator itAddr; string portName = itNum->first; map >& addrMap = itNum->second; os << "Port name " << portName << endl; for ( itAddr = addrMap.begin(); itAddr != addrMap.end(); itAddr++ ) { int address = itAddr->first; deque& msgDeq = itAddr->second; os << " Address " << address << endl; for ( unsigned iMsg = 0; iMsg < msgDeq.size(); iMsg++ ) { os << " Message # " << iMsg << endl; os << msgDeq[iMsg] << endl; } os << endl; } } } //! Non-member function to print out BaseIUBuffer class through stream ostream& operator<<( ostream& os, const BaseIUBuffer& buffer ) { buffer.Print( os ); return os; }