[Fwd: perl AUTOLOADER vs c++]

Discussion in 'C++' started by Billy N. Patton, Oct 15, 2004.

  1. -------- Original Message --------
    Subject: perl AUTOLOADER vs c++
    Date: Fri, 15 Oct 2004 13:28:18 -0500
    From: Billy N. Patton <>
    Organization: Texas Instruments
    Newsgroups: alt.comp.lang.learn.c-c++

    Assume I have a perl class/module called Ui.

    The need for this is to have ALL io the exact same.

    If I need a new switch my command line parser will just add it to the
    hash of the blessed class. I don't have to export the method to get to
    the data I can simple call the class with the proper name and the
    autoload will take care of the rest, With a little coding in the auto
    loader.
    Ex:
    if I pass in -abc some_value.
    the command line parser will set in my hash 'abc' => 'some_value'

    With out the autoloader I have no access unless I've exported the hash
    But with the autoloader I can do
    $val = $ui->abc();


    I've created a Ui class in C++. All the variables are declared as
    static. I only want one copy of each variable.
    Currently, I'm having to do a get and a set type method for each
    variable in my private section.

    Does c++ have something similar to perls autoloader?
    THis would greatly increase the functionality of my Ui class.
    Dynamic switches and methods :)

    --
    ___ _ ____ ___ __ __
    / _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
    / _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
    /____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
    /___/
    Texas Instruments ASIC Circuit Design Methodlogy Group
    Dallas, Texas, 214-480-4455,

    --
    ___ _ ____ ___ __ __
    / _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
    / _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
    /____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
    /___/
    Texas Instruments ASIC Circuit Design Methodlogy Group
    Dallas, Texas, 214-480-4455,
     
    Billy N. Patton, Oct 15, 2004
    #1
    1. Advertising

  2. Billy N. Patton

    David Hilsee Guest

    Re: perl AUTOLOADER vs c++]

    "Billy N. Patton" <> wrote in message
    news:ckpcnr$jl7$...
    >
    >
    > -------- Original Message --------
    > Subject: perl AUTOLOADER vs c++
    > Date: Fri, 15 Oct 2004 13:28:18 -0500
    > From: Billy N. Patton <>
    > Organization: Texas Instruments
    > Newsgroups: alt.comp.lang.learn.c-c++
    >
    > Assume I have a perl class/module called Ui.
    >
    > The need for this is to have ALL io the exact same.
    >
    > If I need a new switch my command line parser will just add it to the
    > hash of the blessed class. I don't have to export the method to get to
    > the data I can simple call the class with the proper name and the
    > autoload will take care of the rest, With a little coding in the auto
    > loader.
    > Ex:
    > if I pass in -abc some_value.
    > the command line parser will set in my hash 'abc' => 'some_value'
    >
    > With out the autoloader I have no access unless I've exported the hash
    > But with the autoloader I can do
    > $val = $ui->abc();
    >
    >
    > I've created a Ui class in C++. All the variables are declared as
    > static. I only want one copy of each variable.
    > Currently, I'm having to do a get and a set type method for each
    > variable in my private section.
    >
    > Does c++ have something similar to perls autoloader?
    > THis would greatly increase the functionality of my Ui class.
    > Dynamic switches and methods :)


    Perl and C++ are very different languages. C++ doesn't have Perl's AUTOLOAD
    feature or AutoLoader module (which presumably depends on the AUTOLOAD
    feature). Functions must be declared before they are used, and you can't
    depend on a "magic" function "finding" the function's definition for you at
    runtime (at least, not on any implementation I've ever seen). I see a few
    options. You can either write getters/setters by hand, make the data
    members public (blech), or instead use an associative container like a
    std::map<std::string,SomeType> to map a string key to its value. Then you
    could just write

    SomeType GetSomeType( const std::string& key ) {
    // may want to throw an exception if key is not in map
    return container[key];
    }

    I'd probably just write the getter and setter for each member unless there
    are a lot of members, in which case I might consider using the associative
    container.

    --
    David Hilsee
     
    David Hilsee, Oct 15, 2004
    #2
    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. Augustus Fernandis

    Problem with using AutoLoader Module.

    Augustus Fernandis, Nov 13, 2004, in forum: Perl
    Replies:
    2
    Views:
    475
    Augustus
    Nov 15, 2004
  2. Davide Carboni
    Replies:
    0
    Views:
    364
    Davide Carboni
    Dec 18, 2003
  3. David Masover

    [ANN] autoloader, version 0.0.2

    David Masover, Nov 24, 2009, in forum: Ruby
    Replies:
    7
    Views:
    205
    Robert Klemme
    Nov 25, 2009
  4. Shahriar
    Replies:
    3
    Views:
    197
  5. Brian McCauley

    Problems with using Autoloader

    Brian McCauley, Nov 14, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    99
    Augustus
    Nov 15, 2004
Loading...

Share This Page