Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to read from a formatted file, and then call object's methods

Thread Tools

how to read from a formatted file, and then call object's methods

ding feng
Posts: n/a
I have got formatted files. All of these file takes this form:
obj1 method1 obj2 string1 obj3 string2 argument.

Of course, each file can have maximum fields as shown above, or
minimun fields
like this:
obj1 method1.

For example, file1 can be like this:
10 obj1 method1
20 obj1 method2 obj2 string1 obj3 string2 argument1
30 obj5 method3 obj1 string1 obj3

Another example is as in file2:
10 obj10 method55 obj30
20 obj1 method7 obj3 string1 obj7
30 obj11 method2 obj20 string1 obj30 string2 argument2

As you can imagine, obj means object, the target is to read one line
by one
line. At each line, call object's method then go to next line until
the final
line reaches.

The difficult for it is each line calls the different method by
passing different parameters. For example, in file1, the first line do
this: int obj1.method1(), however, the second line might do this: int
obj1.methods2(obj2, string1, obj3, string2, argument1), then the third
line do this: obj5.methods3(obj1, string1, obj3).

I wonder whether it is possible to create a dynamic template, where
the format is stored there. This template will store each field of
each line dynamically. For example, int pos=0, in files1, the first
field of the first line will be stored into firstobj[pos], the second
field into method[pos], since the first line reaches end, the rest
fields are set to null. then call firstobj[pos].method[pos](). then
pos++. Then read second line, the first field firstobj[pos],
method[pos], secondobj[pos], string1[pos], thirdobj[pos],
string2[pos], argument1[pos]. Then call
firstobj[pos].methods[pos](secondobj[pos], string1[pos],
thirdobj[pos], string2[pos], argument1[pos]).

The above is what I intend to do. However, it seems not practical to
use arrays to store each field and call object method because each
line has different length.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Required user to read - then click a checkbox and then a button becomes enabled. Mufasa ASP .Net 7 09-04-2007 06:04 PM
Help. SessionID is x then y then x then y ASP General 0 09-03-2005 03:02 PM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
How To: Datagrid Date Column formatted if Null then "Active"? JDP@Work ASP .Net Web Controls 1 10-15-2004 07:38 PM