CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2004
    Posts
    1,361

    Strings to Objects

    I am working with XML and have a problem. How do you convert an a string into an object?

    What I have done is get the object tag (which tells me what object it is), and map it to a function (which takes an XML string containing the construction values) which then constructs the object. I have a table of string names and function pointers to call when it finds a match.

    Is there a better way to do this?

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Strings to Objects

    That is correct. It's almost the same as the well know Factory pattern.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Dec 2004
    Posts
    22

    Question Re: Strings to Objects

    Marg if we consider it as Factory, then probably implementation will be like this
    please correct me if some thing wrong this pattern design for the posted question.

    class Abstract {
    virtual void Object () = 0;
    };

    class AObject : public Absrtact {
    void Object (char *str) {
    strcpy (ostr,str);
    }
    private:
    char *ostr ;
    };


    class facotry {
    virtual AObject* FObject () = 0 ;
    };

    class Concretefactory : public factory {
    AObject* FObject () {
    return new AObject ;
    }

    };

    main () {
    Concretefactory *cf1 ;
    AObject aobj;
    aobj = cf1->Fobject () ;
    aobj -> Object ("Raghu") ;
    }

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Strings to Objects


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured