sc_attr.hh revision 12948
12139SN/A/*
22139SN/A * Copyright 2018 Google, Inc.
32139SN/A *
42139SN/A * Redistribution and use in source and binary forms, with or without
52139SN/A * modification, are permitted provided that the following conditions are
62139SN/A * met: redistributions of source code must retain the above copyright
72139SN/A * notice, this list of conditions and the following disclaimer;
82139SN/A * redistributions in binary form must reproduce the above copyright
92139SN/A * notice, this list of conditions and the following disclaimer in the
102139SN/A * documentation and/or other materials provided with the distribution;
112139SN/A * neither the name of the copyright holders nor the names of its
122139SN/A * contributors may be used to endorse or promote products derived from
132139SN/A * this software without specific prior written permission.
142139SN/A *
152139SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162139SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172139SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182139SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192139SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202139SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212139SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222139SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232139SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242139SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252139SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262139SN/A *
272139SN/A * Authors: Gabe Black
282665Ssaidi@eecs.umich.edu */
292665Ssaidi@eecs.umich.edu
302139SN/A#ifndef __SYSTEMC_EXT_CORE_SC_ATTR_HH__
314202Sbinkertn@umich.edu#define __SYSTEMC_EXT_CORE_SC_ATTR_HH__
328961Sgblack@eecs.umich.edu
3310196SCurtis.Dunham@arm.com#include <string>
342139SN/A#include <vector>
354202Sbinkertn@umich.edu
362152SN/Anamespace sc_core
372152SN/A{
382139SN/A
392139SN/Aclass sc_attr_base
402139SN/A{
412139SN/A  public:
422139SN/A    sc_attr_base(const std::string &_name);
432152SN/A    sc_attr_base(const sc_attr_base &other);
442152SN/A    virtual ~sc_attr_base();
452139SN/A
462139SN/A    const std::string &name() const;
472139SN/A
489020Sgblack@eecs.umich.edu  private:
494781Snate@binkert.org    // Disabled
507799Sgblack@eecs.umich.edu    sc_attr_base();
514781Snate@binkert.org    sc_attr_base &operator = (const sc_attr_base &);
524781Snate@binkert.org
533170Sstever@eecs.umich.edu    const std::string _name;
545664Sgblack@eecs.umich.edu};
558105Sgblack@eecs.umich.edu
566179Sksewell@umich.edutemplate <class T>
574781Snate@binkert.orgclass sc_attribute : public sc_attr_base
586329Sgblack@eecs.umich.edu{
594781Snate@binkert.org  public:
604781Snate@binkert.org    sc_attribute(const std::string &_name) : sc_attr_base(_name) {}
614781Snate@binkert.org    sc_attribute(const std::string &_name, const T &t) :
624781Snate@binkert.org        sc_attr_base(_name), value(t)
634781Snate@binkert.org    {}
644781Snate@binkert.org    sc_attribute(const sc_attribute<T> &other) :
652139SN/A        sc_attr_base(other.name()), value(other.value)
662139SN/A    {}
673546Sgblack@eecs.umich.edu    virtual ~sc_attribute() {}
684202Sbinkertn@umich.edu    T value;
692152SN/A
702152SN/A  private:
712152SN/A    // Disabled
722152SN/A    sc_attribute() {}
732152SN/A    sc_attribute<T> &operator = (const sc_attribute<T> &) { return *this; }
742152SN/A};
752152SN/A
762152SN/Aclass sc_attr_cltn
772152SN/A{
782152SN/A  public:
792152SN/A    typedef sc_attr_base *elem_type;
802152SN/A    typedef std::vector<elem_type>::iterator iterator;
812504SN/A    typedef std::vector<elem_type>::const_iterator const_iterator;
822504SN/A
832504SN/A    iterator begin();
842504SN/A    const_iterator begin() const;
852152SN/A    iterator end();
862504SN/A    const_iterator end() const;
872152SN/A
882152SN/A  private:
892152SN/A    // Disabled
902152SN/A    sc_attr_cltn &operator = (const sc_attr_cltn &);
912152SN/A
922152SN/A    // "Impelemtation defined" members required by the regression tests.
938584Sgblack@eecs.umich.edu  public:
948584Sgblack@eecs.umich.edu    sc_attr_cltn();
956993Snate@binkert.org
966993Snate@binkert.org    // It's non-standard for this not to be disabled.
976993Snate@binkert.org    sc_attr_cltn(const sc_attr_cltn &);
986993Snate@binkert.org
998887Sgeoffrey.blake@arm.com    ~sc_attr_cltn();
1006993Snate@binkert.org
1018584Sgblack@eecs.umich.edu    bool push_back(sc_attr_base *);
1028584Sgblack@eecs.umich.edu
1038584Sgblack@eecs.umich.edu    sc_attr_base *operator [] (const std::string &name);
1048584Sgblack@eecs.umich.edu    const sc_attr_base *operator [] (const std::string &name) const;
1058584Sgblack@eecs.umich.edu
10610196SCurtis.Dunham@arm.com    sc_attr_base *remove(const std::string &name);
10710196SCurtis.Dunham@arm.com
10810196SCurtis.Dunham@arm.com    void remove_all();
10910196SCurtis.Dunham@arm.com    int size() const;
11010196SCurtis.Dunham@arm.com
11110196SCurtis.Dunham@arm.com  private:
11210196SCurtis.Dunham@arm.com    std::vector<sc_attr_base *> cltn;
11310196SCurtis.Dunham@arm.com};
11410196SCurtis.Dunham@arm.com
11510196SCurtis.Dunham@arm.com} // namespace sc_core
11610196SCurtis.Dunham@arm.com
11710196SCurtis.Dunham@arm.com#endif  //__SYSTEMC_EXT_CORE_SC_ATTR_HH__
11810196SCurtis.Dunham@arm.com