TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_fifo_resize.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_RESIZE_H__
19 #define __TLM_FIFO_RESIZE_H__
20 
21 /******************************************************************
22 //
23 // resize interface
24 //
25 ******************************************************************/
26 
27 namespace tlm {
28 
29 template < typename T>
30 inline
31 void
32 tlm_fifo<T>::nb_expand( unsigned int n ) {
33 
34  if( m_size >= 0 ) {
35  m_expand = true;
36  m_size += n;
37  request_update();
38  }
39 }
40 
41 template < typename T>
42 inline
43 void
44 tlm_fifo<T>::nb_unbound( unsigned int n ) {
45 
46  m_expand = true;
47  m_size = -n;
48 
49  if( buffer.size() < static_cast<int>( n ) ) {
50  buffer.resize( n );
51  }
52 
53  request_update();
54 
55 }
56 
57 template < typename T>
58 inline
59 bool
60 tlm_fifo<T>::nb_reduce( unsigned int n ) {
61 
62  if( m_size < 0 ) {
63  return false;
64  }
65 
66  return nb_bound( size() - n );
67 
68 }
69 
70 template < typename T>
71 inline
72 bool
73 tlm_fifo<T>::nb_bound( unsigned int new_size ) {
74 
75  bool ret = true;
76 
77  if( static_cast<int>( new_size ) < used() ) {
78 
79  new_size = used();
80  ret = false;
81 
82  }
83 
84  m_size = new_size;
85  return ret;
86 
87 }
88 
89 } // namespace tlm
90 
91 #endif
bool nb_reduce(unsigned int n=1)
void nb_expand(unsigned int n=1)
bool nb_bound(unsigned int n)
void nb_unbound(unsigned int n=16)