tlm_fifo_peek.h revision 12027:1eb7dc7aa10b
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20#ifndef __TLM_FIFO_PEEK_H__
21#define __TLM_FIFO_PEEK_H__
22
23namespace tlm {
24
25template < typename T>
26inline
27T
28tlm_fifo<T>::peek( tlm_tag<T> * ) const {
29
30  while( is_empty() ) {
31
32    // call free-standing sc_core::wait(),
33    // since sc_prim_channel::wait(.) is not const
34
35    sc_core::wait( m_data_written_event );
36  }
37
38  return buffer.read_data();
39
40}
41
42template < typename T>
43inline
44bool
45tlm_fifo<T>::nb_peek( T &t ) const {
46
47  if( used() < 1 ) {
48    return false;
49  }
50
51  t = buffer.peek_data( 0 );
52  return true;
53
54}
55
56template < typename T>
57inline
58bool
59tlm_fifo<T>::nb_peek( T &t , int n ) const {
60
61  if( n >= used() || n < -1 ) {
62    return false;
63  }
64
65  if( n == -1 ) {
66    n = used() - 1;
67  }
68
69  t = buffer.peek_data( n );
70  return true;
71
72}
73
74template< typename T >
75inline
76bool
77tlm_fifo<T>::nb_can_peek( tlm_tag<T> * ) const
78{
79  return !is_empty();
80}
81
82template < typename T>
83inline
84bool
85tlm_fifo<T>::nb_poke( const T &t , int n ) {
86
87  if( n >= used() || n < 0 ) {
88    return false;
89  }
90
91  buffer.poke_data( n ) = t;
92  return true;
93
94}
95
96} // namespace tlm
97
98#endif
99