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