From ec7ab8e01d32956735a1322d635346af9289a0e0 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 30 Dec 2018 14:15:58 +0100 Subject: [PATCH] WIP: moved code. --- src/db/db/gsiDeclDbNetlistDeviceClasses.cc | 42 --------------------- src/gsi/gsi/gsiMethods.h | 43 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/db/db/gsiDeclDbNetlistDeviceClasses.cc b/src/db/db/gsiDeclDbNetlistDeviceClasses.cc index 8ce4a554c..e78bfd3bd 100644 --- a/src/db/db/gsiDeclDbNetlistDeviceClasses.cc +++ b/src/db/db/gsiDeclDbNetlistDeviceClasses.cc @@ -26,48 +26,6 @@ namespace gsi { -// TODO: move this to gsiMethods.h - -template -class ConstantValueGetter - : public StaticMethodBase -{ -public: - ConstantValueGetter (const std::string &name, const R &v, const std::string &doc) - : StaticMethodBase (name, doc, true), m_v (v) - { - } - - void initialize () - { - this->clear (); - // Note: a constant must not return a reference to an existing object, hence "set_return_new": - this->template set_return_new (); - } - - virtual MethodBase *clone () const - { - return new ConstantValueGetter (*this); - } - - virtual void call (void *, SerialArgs &, SerialArgs &ret) const - { - mark_called (); - ret.write (m_v); - } - -private: - R m_v; -}; - -template -Methods -constant (const std::string &name, const R &v, const std::string &doc = std::string ()) -{ - return Methods (new ConstantValueGetter (name, v, doc)); -} - - extern Class decl_dbDeviceClass; Class decl_dbDeviceClassResistor (decl_dbDeviceClass, "db", "DeviceClassResistor", diff --git a/src/gsi/gsi/gsiMethods.h b/src/gsi/gsi/gsiMethods.h index 8b1cc2ef5..d280395c1 100644 --- a/src/gsi/gsi/gsiMethods.h +++ b/src/gsi/gsi/gsiMethods.h @@ -810,6 +810,49 @@ constant (const std::string &name, R (*m) (), const std::string &doc = std::stri return Methods (new ConstantGetter (name, m, doc)); } +/** + * @brief A helper class to create a constant (a static method with "const" attribute, not taking any arguments) + * This version creates a constant getter from a real constant value. + */ +template +class ConstantValueGetter + : public StaticMethodBase +{ +public: + ConstantValueGetter (const std::string &name, const R &v, const std::string &doc) + : StaticMethodBase (name, doc, true), m_v (v) + { + } + + void initialize () + { + this->clear (); + // Note: a constant must not return a reference to an existing object, hence "set_return_new": + this->template set_return_new (); + } + + virtual MethodBase *clone () const + { + return new ConstantValueGetter (*this); + } + + virtual void call (void *, SerialArgs &, SerialArgs &ret) const + { + mark_called (); + ret.write (m_v); + } + +private: + R m_v; +}; + +template +Methods +constant (const std::string &name, const R &v, const std::string &doc = std::string ()) +{ + return Methods (new ConstantValueGetter (name, v, doc)); +} + struct return_by_value { typedef tl::False is_factory;