scc 2026.07
SystemC components library
tlm_array.h
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_NW_TLM_ARRAY_H_INCLUDED_
21#define TLM_NW_TLM_ARRAY_H_INCLUDED_
22
23#include <vector>
24
25#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
26#pragma warning(push)
27#pragma warning(disable : 4251) // DLL import for std::string,vector
28#endif
29
30namespace tlm {
31namespace nw {
32// This implements a lean and fast array class that supports array expansion on
33// request. The class is primarily used for storing the pointers to the extensions.
34//
35// Individual array elements can be accessed through the [] operators, and the
36// array length is returned by the size() method.
37//
38// The size can be dynamically expanded using the expand(uint) method. There
39// is no shrinking mechanism implemented, because the extension mechanism
40// does not require this feature. Bear in mind that calling the expand method
41// may invalidate all direct pointers into the array.
42
43// the tlm_array shall always be used with T=tlm_extension_base*
44template <typename T> class tlm_array : private std::vector<T> {
45 typedef std::vector<T> base_type;
46 typedef typename base_type::size_type size_type;
47
48public:
49 // constructor:
50 tlm_array(size_type size = 0)
51 : base_type(size)
52 , m_entries() {
53 // m_entries.reserve(size); // optional
54 }
55
56 // copy constructor:
57 // tlm_array(const tlm_array& orig) = default;
58
59 // destructor:
60 // ~tlm_array() = default;
61
62 // operators for dereferencing:
63 using base_type::operator[];
64
65 // array size:
66 using base_type::size;
67
68 // expand the array if needed:
69 void expand(size_type new_size) {
70 if(new_size > size()) {
71 base_type::resize(new_size);
72 // m_entries.reserve(new_size); // optional
73 }
74 }
75
76 static const char* const kind_string;
77 const char* kind() const { return kind_string; }
78
79 // this function shall get a pointer to a array slot
80 // it stores this slot in a cache of active slots
81 void insert_in_cache(T* p) {
82 // sc_assert( (p-&(*this)[0]) < size() );
83 m_entries.push_back(p - &(*this)[0]);
84 }
85
86 // this functions clears all active slots of the array
87 void free_entire_cache() {
88 while(m_entries.size()) {
89 if((*this)[m_entries.back()]) // we make sure no one cleared the slot manually
90 (*this)[m_entries.back()]->free(); //...and then we call free on the content of the slot
91 (*this)[m_entries.back()] = 0; // afterwards we set the slot to NULL
92 m_entries.pop_back();
93 }
94 }
95
96protected:
97 std::vector<size_type> m_entries;
98};
99
100template <typename T> const char* const tlm_array<T>::kind_string = "tlm_array";
101
102#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
103#pragma warning(pop)
104#endif
105} // namespace nw
106} // namespace tlm
107
108#endif /* TLM_CORE_TLM2_TLM_ARRAY_H_INCLUDED_ */
SCC TLM utilities.
Definition cxs_tlm.h:544
SystemC TLM.
Definition dmi_mgr.h:19