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
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
line. At each line, call object's method then go to next line until
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
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.
|All times are GMT. The time now is 08:34 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.