All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
To: powertop@lists.01.org
Subject: Re: [Powertop] [RFC][PATCH 1/2] Adding report generator facility
Date: Tue, 09 Oct 2012 12:03:26 -0700	[thread overview]
Message-ID: <20121009190326.GB3633@swordfish> (raw)
In-Reply-To: 20121009185555.GA3633@swordfish

[-- Attachment #1: Type: text/plain, Size: 3299 bytes --]

On (10/09/12 11:55), Sergey Senozhatsky wrote:
> 
> so we still can call formatter = new report_formatter() and use it as we did before.
> the obvious problem is that we waste memory and CPU cycles on add* calls for basic
> class. in other words, if we take a look on the problem from a different angle,
> among all functions we have 3 types of functions (counting from 1):
> #1 those that must be NULL in base class - derived class implementation specific
> #2 those that must be same for all derived classes, but NULL in base class
> #3 those that must be derived with basic implementation
> 
> 
> 
> that leads to a quick solution (meaning that it may not be perfect nor beautiful). we define and
> implement base class with all function being both virtual and empty, let's call it base (report_formatter).
> then we define base_impl class, and implement only type #1 functions, for example, in our case a family of
> add*() functions plus get/clear result() and so on.
> 
> then we define and implement formatter clases, that should inherit from base_impl, and override
> class #2 functions (for example, escaping).
>

Oh, I messed up there. should be "and implement only type #2 functions" and "override class #1 functions".

	
	-ss
 
> 
> from the top of my head, schematically is something like this:
> 
> class base {
>         public:
>                 base() {}
>                 virtual ~base() {}
>                 virtual void foo(const char *p)
>                 {
>                         printf("base foo call\n");
>                 }
>                 virtual void bar()
>                 {
>                         printf("base bar call\n");
>                 }
>                 virtual void xyz()
>                 {
>                         printf("base xyz call\n");
>                 }
>                 virtual void begin_table()
>                 {
>                         printf("base begin table call\n");
>                 }
> };
> 
> class base_impl : public base {
>         public:
>                 std::string data;
>                 virtual void foo(const char *p)
>                 {
>                         printf("impl foo call\n");
>                         data.append(p);
>                 }
> 
>                 virtual void bar()
>                 {
>                         printf("impl bar call: %s\n", data.c_str());
>                 }
> };
> 
> class derived : public base_impl {
>         public:
>                 virtual void begin_table()
>                 {
>                         printf("derived begin table call\n");
>                 }
> };
> 
> 
> int main()
> {
>         class derived *d = new derived();
>         d->foo("test");
>         d->bar();
>         d->xyz();
>         d->begin_table();
> 
>         class base *b = new base();
>         b->foo("test");
>         b->bar();
>         b->xyz();
>         b->begin_table();
> 
>         delete d;
>         delete b;
>         return 0;
> }
> 
> $g++ -O2 test.cpp -o a.out
> 
> $./a.out 
> impl foo call
> impl bar call: test
> base xyz call
> derived begin table call
> 
> base foo call
> base bar call
> base xyz call
> base begin table call
> 
> 
> 
> 	-ss

             reply	other threads:[~2012-10-09 19:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-09 19:03 Sergey Senozhatsky [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-10-10 15:53 [Powertop] [RFC][PATCH 1/2] Adding report generator facility Chris Ferron
2012-10-10 15:39 Sergey Senozhatsky
2012-10-10 12:49 Igor Zhbanov
2012-10-09 19:31 Sergey Senozhatsky
2012-10-09 19:11 Sergey Senozhatsky
2012-10-09 18:55 Sergey Senozhatsky
2012-10-09 17:25 Igor Zhbanov
2012-10-09 17:02 Igor Zhbanov
2012-10-08 16:57 Sergey Senozhatsky
2012-10-05 10:15 Igor Zhbanov
2012-10-04 21:17 Sergey Senozhatsky
2012-10-04 21:07 Sergey Senozhatsky
2012-10-04 16:08 Ferron, Chris E
2012-10-03 17:05 Igor Zhbanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121009190326.GB3633@swordfish \
    --to=powertop@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.