base: Move Named class to its own file
Named can be useful in instances where trace is not required. Because of that it has been moved to its own file. Named is intended for public inheritance; thus it should have a virtual destructor. Added a unit test for the Named class. Change-Id: I314e850b4fafd7804d919fd3fe6dec44822e1f48 Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38743 Reviewed-by: Gabe Black <gabe.black@gmail.com> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
be37868ca6
commit
eb9e11ad96
47
src/base/named.hh
Normal file
47
src/base/named.hh
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Daniel R. Carvalho
|
||||
* All rights reserved
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __BASE_NAMED_HH__
|
||||
#define __BASE_NAMED_HH__
|
||||
|
||||
#include <string>
|
||||
|
||||
/** Interface for things with names. This is useful when using DPRINTF. */
|
||||
class Named
|
||||
{
|
||||
private:
|
||||
const std::string _name;
|
||||
|
||||
public:
|
||||
Named(const std::string &name_) : _name(name_) { }
|
||||
virtual ~Named() = default;
|
||||
|
||||
const std::string &name() const { return _name; }
|
||||
};
|
||||
|
||||
#endif // __BASE_NAMED_HH__
|
||||
38
src/base/named.test.cc
Normal file
38
src/base/named.test.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Daniel R. Carvalho
|
||||
* All rights reserved
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met: redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer;
|
||||
* redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution;
|
||||
* neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "base/named.hh"
|
||||
|
||||
/** Test if a Named instance has the name it is assigned. */
|
||||
TEST(NamedTest, Name)
|
||||
{
|
||||
Named named("Named class");
|
||||
ASSERT_EQ("Named class", named.name());
|
||||
}
|
||||
@@ -145,20 +145,6 @@ struct StringWrap
|
||||
// the DPRINTF macros are used in a context without a visible name() function
|
||||
const std::string &name();
|
||||
|
||||
// Interface for things with names. (cf. SimObject but without other
|
||||
// functionality). This is useful when using DPRINTF
|
||||
class Named
|
||||
{
|
||||
protected:
|
||||
const std::string _name;
|
||||
|
||||
public:
|
||||
Named(const std::string &name_) : _name(name_) { }
|
||||
|
||||
public:
|
||||
const std::string &name() const { return _name; }
|
||||
};
|
||||
|
||||
/**
|
||||
* DPRINTF is a debugging trace facility that allows one to
|
||||
* selectively enable tracing statements. To use DPRINTF, there must
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.hh"
|
||||
#include "base/named.hh"
|
||||
#include "base/types.hh"
|
||||
#include "cpu/activity.hh"
|
||||
#include "cpu/minor/trace.hh"
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "cpu/minor/buffers.hh"
|
||||
#include "cpu/minor/cpu.hh"
|
||||
#include "cpu/minor/dyn_inst.hh"
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "base/refcnt.hh"
|
||||
#include "base/types.hh"
|
||||
#include "cpu/inst_seq.hh"
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "base/types.hh"
|
||||
#include "cpu/minor/buffers.hh"
|
||||
#include "cpu/minor/cpu.hh"
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "cpu/base.hh"
|
||||
#include "cpu/minor/buffers.hh"
|
||||
#include "cpu/minor/cpu.hh"
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "cpu/minor/buffers.hh"
|
||||
#include "cpu/minor/cpu.hh"
|
||||
#include "cpu/minor/pipe_data.hh"
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <sstream>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "base/trace.hh"
|
||||
#include "debug/MinorTiming.hh"
|
||||
#include "enums/OpClass.hh"
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "cpu/minor/buffers.hh"
|
||||
#include "cpu/minor/cpu.hh"
|
||||
#include "cpu/minor/pipe_data.hh"
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/named.hh"
|
||||
#include "base/types.hh"
|
||||
#include "cpu/minor/cpu.hh"
|
||||
#include "cpu/minor/dyn_inst.hh"
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "base/named.hh"
|
||||
#include "base/trace.hh"
|
||||
#include "base/types.hh"
|
||||
#include "debug/MemChecker.hh"
|
||||
|
||||
Reference in New Issue
Block a user