• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to build data parser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to build data parser


  • Subject: Re: how to build data parser
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Mon, 28 Mar 2005 04:28:15 +0200

At 17:27 Uhr -1000 26.03.2005, Daniel Child wrote:
The parse file method would return an array of objects. I'm stuck with two things I haven't done before. How do I specify an object type (e.g. Word class or Stroke class object)? And once I have scanned individual lines of text, how can assign the parsed fields to the correct member variable fields of the object class being passed in?

Okay, now that we know you're not trying to reinvent the wheel, you may want to get us some information. As Matt said in another message, if you want an answer, give us some info. There are so many things that can be parsed that just saying "I'm writing a parser" is like saying "I want an animal". It's getting a little tiring, especially considering that the official list resources posting tells you to read ESR's "how to ask smart questions", which states this in a very comprehensible way.


That having been said, it's a *really bad* idea to go about this the way you're doing. Each object knows best what data it contains and what format it has, so let the object take care of that. That's what OO's concept of encapsulation is all about.

Create a common base class for all file-readable objects (or a protocol) and have a look at Cocoa's runtime introspection facilities (NSClassFromString etc.). For example, if you need to create many different kinds of classes, it's very easy to have an NSDictionary that maps object names to classes, and then you can just send alloc/init messages to the class you got from the dictionary to create an object, passing it the data stream from which it is to read its data. You only read the token that indicates what kind of object it is.

That's basically the same design as used in NSUnarchiver, just that since you're writing it yourself you can easily make it fit whatever format you need.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >how to build data parser (From: Daniel Child <email@hidden>)

  • Prev by Date: Re: ObjectiveC++ strange warning at class declaration
  • Next by Date: Re: ObjectiveC++ strange warning at class declaration
  • Previous by thread: Re: how to build data parser
  • Next by thread: I can pass through without typing correct username and password(the user is admin group, and set the password to null)
  • Index(es):
    • Date
    • Thread