gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_attr.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Authors: Gabe Black
28  */
29 
30 #include <utility>
31 
33 
34 namespace sc_core
35 {
36 
37 sc_attr_base::sc_attr_base(const std::string &_name) : _name(_name) {}
40 
41 const std::string &sc_attr_base::name() const { return _name; }
42 
45 {
46  return cltn.begin();
47 }
48 
51 {
52  return cltn.begin();
53 }
54 
57 {
58  return cltn.end();
59 }
60 
63 {
64  return cltn.end();
65 }
66 
68 sc_attr_cltn::sc_attr_cltn(const sc_attr_cltn &other) : cltn(other.cltn) {}
70 
71 bool
73 {
74  if (!attr || (*this)[attr->name()])
75  return false;
76 
77  cltn.push_back(attr);
78  return true;
79 }
80 
82 sc_attr_cltn::operator [] (const std::string &name)
83 {
84  for (auto &attr: cltn)
85  if (attr->name() == name)
86  return attr;
87  return nullptr;
88 }
89 
90 const sc_attr_base *
91 sc_attr_cltn::operator [] (const std::string &name) const
92 {
93  for (auto &attr: cltn)
94  if (attr->name() == name)
95  return attr;
96  return nullptr;
97 }
98 
100 sc_attr_cltn::remove(const std::string &name)
101 {
102  for (auto &attr: cltn) {
103  if (attr->name() == name) {
104  sc_attr_base *ret = attr;
105  std::swap(attr, cltn.back());
106  cltn.pop_back();
107  return ret;
108  }
109  }
110  return nullptr;
111 }
112 
113 void sc_attr_cltn::remove_all() { cltn.clear(); }
114 
115 int sc_attr_cltn::size() const { return cltn.size(); }
116 
117 } // namespace sc_core
std::vector< elem_type >::iterator iterator
Definition: sc_attr.hh:80
const std::string & name()
Definition: trace.cc:54
std::vector< elem_type >::const_iterator const_iterator
Definition: sc_attr.hh:81
sc_attr_base * operator[](const std::string &name)
Definition: sc_attr.cc:82
const std::string & name() const
Definition: sc_attr.cc:41
sc_attr_base * remove(const std::string &name)
Definition: sc_attr.cc:100
const std::string _name
Definition: sc_attr.hh:53
iterator end()
Definition: sc_attr.cc:56
iterator begin()
Definition: sc_attr.cc:44
bool push_back(sc_attr_base *)
Definition: sc_attr.cc:72
std::vector< sc_attr_base * > cltn
Definition: sc_attr.hh:112
virtual ~sc_attr_base()
Definition: sc_attr.cc:39
int size() const
Definition: sc_attr.cc:115

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13