469,648 Members | 1,174 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

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

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.
Jul 19 '05 #1
0 2401

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Garyrek | last post: by
6 posts views Thread by Samuel M. Smith | last post: by
3 posts views Thread by John | last post: by
6 posts views Thread by Sean Davis | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.