473,806 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(o bj2, string1, obj3, string2, argument1), then the third
line do this: obj5.methods3(o bj1, 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 2654

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4582
by: Garyrek | last post by:
Hi I have an url where I have xml data POSTED and I need to parse the URL to read the data - Meanwhile here is my xml data =================================== <?xml version="1.0" encoding="utf-16"?> <?adf version="1.0"?> <!DOCTYPE adf SYSTEM "http://whoscalling.com/dtd/adfdtd.dtd"> <adf> <prospect status="new">
6
2204
by: Jason Heyes | last post by:
I am starting to worry about the performance of formatted read/write operations on data-redundant objects in my program.What can I do to improve this performance should it become an issue? Thanks.
6
2670
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate the object and set default blank/null values), and then does all the Db access and number crunching to populate the new object. The factory returns the fully populated object to the caller. All the fields in the object are private, but have...
6
6011
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to assign a value to them. I wanted to trap for this exception in a subclass using super but it doesn't happen. I have read Guido's tutorial on new style classes and Shalabh's tuturial on new style attributes and methods, and thought I understood...
3
1254
by: John | last post by:
I have a text file that is formatted like this: 123456789 SOLD 1 12/12/2006 Smith 45,525 987654321 SOLD 3 01/01/2006 Jones 23,252
7
2152
by: Tracks | last post by:
I have old legacy code from vb5 where data was written to a file with a variant declaration (this was actually a coding error?)... in vb5 the code was: Dim thisdata as integer Dim thatdata Dim someother as integer thatdata = ubound( Array1 )
11
3359
by: waffle.horn | last post by:
Hi, if this makes sense i want to create a function that can be called so that it reads a single line from a file, then after using the information destroys it. Such that when the function is called that line of info does not exist anymore in the file. for example i have created a short example of where i am at, but I dont know how to alter what im doing so that i just read in a single line
0
1703
by: satarupa | last post by:
I want to read the formatted (bold,underline,italics) text of a word dcoument using c# i can read the document even the paragraphn in it but not the formatted text plzz help following is the code private void btnRead_Click(object sender, EventArgs e) { // ReadFile(textBox1.Text);
6
3740
by: Sean Davis | last post by:
I have a large file that I would like to transform and then feed to a function (psycopg2 copy_from) that expects a file-like object (needs read and readline methods). I have a class like so: class GeneInfo(): def __init__(self): #urllib.urlretrieve('ftp://ftp.ncbi.nih.gov/gene/DATA/ gene_info.gz',"/tmp/gene_info.gz")
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10624
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.