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

D

ding feng

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top