Adding Prolog/Epilog

Discussion in 'C++' started by Neo, Dec 1, 2006.

  1. Neo

    Neo Guest

    I want to log information for a function call like

    void Add(void)
    {

    }

    When above function gets called, it should output strings like

    Entering Add
    Exiting Add

    So every function call should get logged. I want to add this
    funcionality to each function I am going to write and it should get
    added implicitly.
    Can I create function prolog and epilogs? How to do that ? Is that
    feasible?
     
    Neo, Dec 1, 2006
    #1
    1. Advertising

  2. Neo

    dasjotre Guest

    Neo wrote:
    > I want to log information for a function call like
    >
    > void Add(void)
    > {
    >
    > }
    >
    > When above function gets called, it should output strings like
    >
    > Entering Add
    > Exiting Add
    >
    > So every function call should get logged. I want to add this
    > funcionality to each function I am going to write and it should get
    > added implicitly.
    > Can I create function prolog and epilogs? How to do that ? Is that
    > feasible?


    check http://www.research.att.com/~bs/wrapper.pdf
     
    dasjotre, Dec 1, 2006
    #2
    1. Advertising

  3. Neo

    Ondra Holub Guest

    Neo napsal:
    > I want to log information for a function call like
    >
    > void Add(void)
    > {
    >
    > }
    >
    > When above function gets called, it should output strings like
    >
    > Entering Add
    > Exiting Add
    >
    > So every function call should get logged. I want to add this
    > funcionality to each function I am going to write and it should get
    > added implicitly.
    > Can I create function prolog and epilogs? How to do that ? Is that
    > feasible?


    You can simply create this class:
    class LogEnterExit
    {
    public:
    LogEnterExit(const char* fn): fn_(fn) { std::cout << "Entering " <<
    fn << "\n"; }
    ~LogEnterExit() { std::cout << "Exitting " << fn_ << "\n"; }

    private:
    const char* fn_;
    };

    And then in your functions:
    void Func()
    {
    LogEnterExit("void Func()");

    // Your code
    }

    It is simple and has drawback in constructors. 'Entering' is written
    after member initialization.
     
    Ondra Holub, Dec 1, 2006
    #3
  4. Neo

    David Harmon Guest

    On 1 Dec 2006 06:48:08 -0800 in comp.lang.c++, "Ondra Holub"
    <> wrote,
    >And then in your functions:
    >void Func()
    >{
    > LogEnterExit("void Func()");
    >
    > // Your code
    >}


    Seems like that temporary would get destroyed sooner than you would
    like.
     
    David Harmon, Dec 1, 2006
    #4
  5. Neo

    Ondra Holub Guest

    David Harmon napsal:
    > On 1 Dec 2006 06:48:08 -0800 in comp.lang.c++, "Ondra Holub"
    > <> wrote,
    > >And then in your functions:
    > >void Func()
    > >{
    > > LogEnterExit("void Func()");
    > >
    > > // Your code
    > >}

    >
    > Seems like that temporary would get destroyed sooner than you would
    > like.


    Yes, there is missing name of variable (I wrote it from scratch). It
    shold be:

    void Func()
    {
    LogEnterExit logger("void Func()");

    // Your code
    }
     
    Ondra Holub, Dec 1, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Hopkins

    Content is not allowed in prolog

    Scott Hopkins, Apr 21, 2004, in forum: Java
    Replies:
    0
    Views:
    7,183
    Scott Hopkins
    Apr 21, 2004
  2. Nick
    Replies:
    0
    Views:
    3,235
  3. Dave Dubin

    [ANN] XML Processing in Prolog

    Dave Dubin, Jul 6, 2005, in forum: XML
    Replies:
    0
    Views:
    435
    Dave Dubin
    Jul 6, 2005
  4. Andrey Tatarinov

    method prolog/epilog

    Andrey Tatarinov, Jul 30, 2004, in forum: C++
    Replies:
    10
    Views:
    770
  5. Neo

    Adding Prolog to Epilog

    Neo, Dec 1, 2006, in forum: C++
    Replies:
    7
    Views:
    349
Loading...

Share This Page