summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-06-22 14:14:47 -0700
committerGabe Black <gabeblack@google.com>2018-09-05 06:00:06 +0000
commit642fa515b822aca10839e0382e3a5d94eca20dd2 (patch)
treefa9adb998dc7aca23c88fbeda8bad48b0a329b0c
parentd86151e70ff6046fd1cfadf675d686309271fcf1 (diff)
downloadgem5-642fa515b822aca10839e0382e3a5d94eca20dd2.tar.xz
systemc: Implement the sc_attr classes.
Change-Id: Ibbe6da957b1b36687178f226e80718adc0f4ab81 Reviewed-on: https://gem5-review.googlesource.com/11609 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r--src/systemc/core/sc_attr.cc95
-rw-r--r--src/systemc/ext/core/sc_attr.hh31
2 files changed, 47 insertions, 79 deletions
diff --git a/src/systemc/core/sc_attr.cc b/src/systemc/core/sc_attr.cc
index ca9e0af66..37a6575de 100644
--- a/src/systemc/core/sc_attr.cc
+++ b/src/systemc/core/sc_attr.cc
@@ -27,115 +27,92 @@
* Authors: Gabe Black
*/
+#include <utility>
+
#include "base/logging.hh"
#include "systemc/ext/core/sc_attr.hh"
namespace sc_core
{
-sc_attr_base::sc_attr_base(const std::string &)
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
+sc_attr_base::sc_attr_base(const std::string &_name) : _name(_name) {}
+sc_attr_base::sc_attr_base(const sc_attr_base &other) : _name(other._name) {}
+sc_attr_base::~sc_attr_base() {}
-sc_attr_base::sc_attr_base(const sc_attr_base &)
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
-
-sc_attr_base::~sc_attr_base()
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
-
-const std::string &
-sc_attr_base::name() const
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return *(const std::string *)nullptr;
-}
-
-void
-sc_attr_base::warn_unimpl(const char *func)
-{
- warn("%s not implemented.\n", func);
-}
+const std::string &sc_attr_base::name() const { return _name; }
sc_attr_cltn::iterator
sc_attr_cltn::begin()
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return (iterator)nullptr;
+ return cltn.begin();
}
sc_attr_cltn::const_iterator
sc_attr_cltn::begin() const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return (const_iterator)nullptr;
+ return cltn.begin();
}
sc_attr_cltn::iterator
sc_attr_cltn::end()
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return (iterator)nullptr;
+ return cltn.end();
}
sc_attr_cltn::const_iterator
sc_attr_cltn::end() const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return (const_iterator)nullptr;
+ return cltn.end();
}
-sc_attr_cltn::sc_attr_cltn()
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
-
-sc_attr_cltn::sc_attr_cltn(const sc_attr_cltn &)
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
-
-sc_attr_cltn::~sc_attr_cltn()
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
+sc_attr_cltn::sc_attr_cltn() {}
+sc_attr_cltn::sc_attr_cltn(const sc_attr_cltn &other) : cltn(other.cltn) {}
+sc_attr_cltn::~sc_attr_cltn() {}
bool
-sc_attr_cltn::push_back(sc_attr_base *)
+sc_attr_cltn::push_back(sc_attr_base *attr)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
- return false;
+ if (!attr || (*this)[attr->name()])
+ return false;
+
+ cltn.push_back(attr);
+ return true;
}
sc_attr_base *
sc_attr_cltn::operator [] (const std::string &name)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ for (auto &attr: cltn)
+ if (attr->name() == name)
+ return attr;
return nullptr;
}
const sc_attr_base *
sc_attr_cltn::operator [] (const std::string &name) const
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ for (auto &attr: cltn)
+ if (attr->name() == name)
+ return attr;
return nullptr;
}
sc_attr_base *
sc_attr_cltn::remove(const std::string &name)
{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+ for (auto &attr: cltn) {
+ if (attr->name() == name) {
+ sc_attr_base *ret = attr;
+ std::swap(attr, cltn.back());
+ cltn.pop_back();
+ return ret;
+ }
+ }
return nullptr;
}
-void
-sc_attr_cltn::remove_all()
-{
- warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-}
+void sc_attr_cltn::remove_all() { cltn.clear(); }
+
+int sc_attr_cltn::size() const { return cltn.size(); }
} // namespace sc_core
diff --git a/src/systemc/ext/core/sc_attr.hh b/src/systemc/ext/core/sc_attr.hh
index e1c5ae771..16b0b1bed 100644
--- a/src/systemc/ext/core/sc_attr.hh
+++ b/src/systemc/ext/core/sc_attr.hh
@@ -39,40 +39,32 @@ namespace sc_core
class sc_attr_base
{
public:
- sc_attr_base(const std::string &);
- sc_attr_base(const sc_attr_base &);
+ sc_attr_base(const std::string &_name);
+ sc_attr_base(const sc_attr_base &other);
virtual ~sc_attr_base();
const std::string &name() const;
- protected:
- void warn_unimpl(const char *func);
-
private:
// Disabled
sc_attr_base();
sc_attr_base &operator = (const sc_attr_base &);
+
+ const std::string _name;
};
template <class T>
class sc_attribute : public sc_attr_base
{
public:
- sc_attribute(const std::string &_name) : sc_attr_base(_name)
- {
- warn_unimpl(__PRETTY_FUNCTION__);
- }
+ sc_attribute(const std::string &_name) : sc_attr_base(_name) {}
sc_attribute(const std::string &_name, const T &t) :
sc_attr_base(_name), value(t)
- {
- warn_unimpl(__PRETTY_FUNCTION__);
- }
+ {}
sc_attribute(const sc_attribute<T> &other) :
sc_attr_base(other.name()), value(other.value)
- {
- warn_unimpl(__PRETTY_FUNCTION__);
- }
- virtual ~sc_attribute() { warn_unimpl(__PRETTY_FUNCTION__); }
+ {}
+ virtual ~sc_attribute() {}
T value;
private:
@@ -85,8 +77,8 @@ class sc_attr_cltn
{
public:
typedef sc_attr_base *elem_type;
- typedef elem_type *iterator;
- typedef const elem_type *const_iterator;
+ typedef std::vector<elem_type>::iterator iterator;
+ typedef std::vector<elem_type>::const_iterator const_iterator;
iterator begin();
const_iterator begin() const;
@@ -114,8 +106,7 @@ class sc_attr_cltn
sc_attr_base *remove(const std::string &name);
void remove_all();
-
- int size() const { return cltn.size(); }
+ int size() const;
private:
std::vector<sc_attr_base *> cltn;