TLM-2.0  2.0.4
Accellera TLM-2.0 proof-of-concept library
tlm_fifo_peek.h
Go to the documentation of this file.
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 
23 namespace tlm {
24 
25 template < typename T>
26 inline
27 T
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 
42 template < typename T>
43 inline
44 bool
45 tlm_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 
56 template < typename T>
57 inline
58 bool
59 tlm_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 
74 template< typename T >
75 inline
76 bool
78 {
79  return !is_empty();
80 }
81 
82 template < typename T>
83 inline
84 bool
85 tlm_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
bool nb_poke(const T &, int n=0)
Definition: tlm_fifo_peek.h:85
bool nb_peek(T &) const
Definition: tlm_fifo_peek.h:45
bool nb_can_peek(tlm_tag< T > *=0) const
Definition: tlm_fifo_peek.h:77
T peek(tlm_tag< T > *=0) const
Definition: tlm_fifo_peek.h:28
void SC_API wait(int, sc_simcontext *)