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 --- 13 unchanged lines hidden (view full) --- 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 |
32#include "base/logging.hh" 33#include "systemc/ext/core/sc_attr.hh" 34 35namespace sc_core 36{ 37 |
38sc_attr_base::sc_attr_base(const std::string &_name) : _name(_name) {} 39sc_attr_base::sc_attr_base(const sc_attr_base &other) : _name(other._name) {} 40sc_attr_base::~sc_attr_base() {} |
41 |
42const std::string &sc_attr_base::name() const { return _name; } |
43 |
44sc_attr_cltn::iterator 45sc_attr_cltn::begin() 46{ |
47 return cltn.begin(); |
48} 49 50sc_attr_cltn::const_iterator 51sc_attr_cltn::begin() const 52{ |
53 return cltn.begin(); |
54} 55 56sc_attr_cltn::iterator 57sc_attr_cltn::end() 58{ |
59 return cltn.end(); |
60} 61 62sc_attr_cltn::const_iterator 63sc_attr_cltn::end() const 64{ |
65 return cltn.end(); |
66} 67 |
68sc_attr_cltn::sc_attr_cltn() {} 69sc_attr_cltn::sc_attr_cltn(const sc_attr_cltn &other) : cltn(other.cltn) {} 70sc_attr_cltn::~sc_attr_cltn() {} |
71 |
72bool 73sc_attr_cltn::push_back(sc_attr_base *attr) |
74{ |
75 if (!attr || (*this)[attr->name()]) 76 return false; |
77 |
78 cltn.push_back(attr); 79 return true; |
80} 81 |
82sc_attr_base * 83sc_attr_cltn::operator [] (const std::string &name) 84{ |
85 for (auto &attr: cltn) 86 if (attr->name() == name) 87 return attr; |
88 return nullptr; 89} 90 91const sc_attr_base * 92sc_attr_cltn::operator [] (const std::string &name) const 93{ |
94 for (auto &attr: cltn) 95 if (attr->name() == name) 96 return attr; |
97 return nullptr; 98} 99 100sc_attr_base * 101sc_attr_cltn::remove(const std::string &name) 102{ |
103 for (auto &attr: cltn) { 104 if (attr->name() == name) { 105 sc_attr_base *ret = attr; 106 std::swap(attr, cltn.back()); 107 cltn.pop_back(); 108 return ret; 109 } 110 } |
111 return nullptr; 112} 113 |
114void sc_attr_cltn::remove_all() { cltn.clear(); } |
115 |
116int sc_attr_cltn::size() const { return cltn.size(); } 117 |
118} // namespace sc_core |