| 1 | |
| 2 | /***************************************************************************** |
| 3 | |
| 4 | The following code is derived, directly or indirectly, from the SystemC |
| 5 | source code Copyright (c) 1996-2004 by all Contributors. |
| 6 | All Rights reserved. |
| 7 | |
| 8 | The contents of this file are subject to the restrictions and limitations |
| 9 | set forth in the SystemC Open Source License Version 2.4 (the "License"); |
| 10 | You may not use this file except in compliance with such restrictions and |
| 11 | limitations. You may obtain instructions on how to receive a copy of the |
| 12 | License at http://www.systemc.org/. Software distributed by Contributors |
| 13 | under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF |
| 14 | ANY KIND, either express or implied. See the License for the specific |
| 15 | language governing rights and limitations under the License. |
| 16 | |
| 17 | *****************************************************************************/ |
| 18 | |
| 19 | |
| 20 | #ifndef TLM_FIFO_PEEK_HEADER |
| 21 | #define TLM_FIFO_PEEK_HEADER |
| 22 | |
| 23 | #ifndef TLM_FIFO_HEADER |
| 24 | #include "tlm_core/tlm_fifo/tlm_fifo.h" |
| 25 | #endif |
| 26 | |
| 27 | template < typename T> |
| 28 | inline |
| 29 | T |
| 30 | tlm_fifo<T>::peek( tlm_tag<T> * ) const { |
| 31 | |
| 32 | while( is_empty() ) { |
| 33 | |
| 34 | // this const cast is only needed because sc_prim_channel::wait(.) is |
| 35 | // for some unknown reason, not const |
| 36 | |
| 37 | const_cast< tlm_fifo<T> * >( this )->wait( m_data_written_event ); |
| 38 | |
| 39 | } |
| 40 | |
| 41 | return buffer->read_data(); |
| 42 | |
| 43 | } |
| 44 | |
| 45 | template < typename T> |
| 46 | inline |
| 47 | bool |
| 48 | tlm_fifo<T>::nb_peek( T &t ) const { |
| 49 | |
| 50 | if( used() < 1 ) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | t = buffer->peek_data( 0 ); |
| 55 | return true; |
| 56 | |
| 57 | } |
| 58 | |
| 59 | template < typename T> |
| 60 | inline |
| 61 | bool |
| 62 | tlm_fifo<T>::nb_peek( T &t , int n ) const { |
| 63 | |
| 64 | if( n >= used() || n < -1 ) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | if( n == -1 ) { |
| 69 | n = used() - 1; |
| 70 | } |
| 71 | |
| 72 | t = buffer->peek_data( n ); |
| 73 | return true; |
| 74 | |
| 75 | } |
| 76 | |
| 77 | template< typename T > |
| 78 | inline |
| 79 | bool |
| 80 | tlm_fifo<T>::nb_can_peek( tlm_tag<T> * ) const |
| 81 | { |
| 82 | return !is_empty(); |
| 83 | } |
| 84 | |
| 85 | template < typename T> |
| 86 | inline |
| 87 | bool |
| 88 | tlm_fifo<T>::nb_poke( const T &t , int n ) { |
| 89 | |
| 90 | if( n >= used() || n < 0 ) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | buffer->poke_data( n ) = t; |
| 95 | return true; |
| 96 | |
| 97 | } |
| 98 | |
| 99 | #endif |