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