Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / model / vendor / TLM-2006-11-29 / tlm / tlm_core / tlm_fifo / tlm_fifo_peek.h
CommitLineData
86530b38
AT
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
27template < typename T>
28inline
29T
30tlm_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
45template < typename T>
46inline
47bool
48tlm_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
59template < typename T>
60inline
61bool
62tlm_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
77template< typename T >
78inline
79bool
80tlm_fifo<T>::nb_can_peek( tlm_tag<T> * ) const
81{
82 return !is_empty();
83}
84
85template < typename T>
86inline
87bool
88tlm_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