map with polymorphic key???

Discussion in 'C++' started by Daniel Suen, Jul 9, 2004.

  1. Daniel Suen

    Daniel Suen Guest

    Hi All,

    I am trying to implement various kinds of finite automaton simulators; I
    have abstract the transition mappings to be from a "Set" to another "Set"
    taking on some "Input". I come up with the data structure like the following
    to represent automatons,

    map<Set, map<Input, Set> >

    However, for deterministic finite automaton, I derive the class "State" from
    the class "Set", and the class "Symbol" from the class "Input". Now, I want
    to write a function that takes a string and run the automaton against the
    string. Therefore, for deterministic finite automaton, the signature of the
    function would be,

    run(string s, map<State, map<Symbol, State> >);

    I am wondering if there is any way for me to write something like the
    following,

    run(string s, map<Set, map<Input, Set> >);

    so that I can pass different kinds of automaton representation to the
    function.

    If I am not on the right track in the design, could someone point me out how
    I should structure the whole thing to make the code look beautiful?

    -Daniel.
    Daniel Suen, Jul 9, 2004
    #1
    1. Advertising

  2. On Fri, 9 Jul 2004 18:24:42 +0800, Daniel Suen <> wrote:

    > Hi All,
    >
    > I am trying to implement various kinds of finite automaton simulators; I
    > have abstract the transition mappings to be from a "Set" to another "Set"
    > taking on some "Input". I come up with the data structure like the
    > following
    > to represent automatons,
    >
    > map<Set, map<Input, Set> >
    >
    > However, for deterministic finite automaton, I derive the class "State"
    > from
    > the class "Set", and the class "Symbol" from the class "Input". Now, I
    > want
    > to write a function that takes a string and run the automaton against the
    > string. Therefore, for deterministic finite automaton, the signature of
    > the
    > function would be,
    >
    > run(string s, map<State, map<Symbol, State> >);
    >
    > I am wondering if there is any way for me to write something like the
    > following,
    >
    > run(string s, map<Set, map<Input, Set> >);
    >
    > so that I can pass different kinds of automaton representation to the
    > function.
    >
    > If I am not on the right track in the design, could someone point me out
    > how
    > I should structure the whole thing to make the code look beautiful?
    >
    > -Daniel.
    >


    Use a pointer (or preferably a smart pointer) for the key and a comparison
    object to call a virtual method on the keys.

    Whether that's good design for your application I couldn't say but it will
    get you a map with a polymorphic key.

    john
    John Harrison, Jul 9, 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. Manco

    can webmethods be polymorphic?

    Manco, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    322
    Lionel LASKE
    Feb 3, 2005
  2. Thomas Britton

    polymorphic behaviour from class constant

    Thomas Britton, May 1, 2004, in forum: Java
    Replies:
    1
    Views:
    332
    Chris Uppal
    May 2, 2004
  3. Patrick Guio
    Replies:
    6
    Views:
    3,194
    chris
    Oct 20, 2004
  4. Mize-ze
    Replies:
    4
    Views:
    507
    Robert Klemme
    Jan 1, 2007
  5. M P
    Replies:
    1
    Views:
    465
Loading...

Share This Page