tlm_fifo_resize.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_RESIZE_H__
21#define __TLM_FIFO_RESIZE_H__
22
23/******************************************************************
24//
25// resize interface
26//
27******************************************************************/
28
29namespace tlm {
30
31template < typename T>
32inline
33void
34tlm_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
43template < typename T>
44inline
45void
46tlm_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
59template < typename T>
60inline
61bool
62tlm_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
72template < typename T>
73inline
74bool
75tlm_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