PDA

View Full Version : Parsing ASCII model files with QT



ar_jym
30th July 2015, 20:55
Hello and thank you for your time. I am new to C++ and QT. I need to parse an ASCII model file which contains multiple sub-circuits and multiple models within the sub-circuits. The sub-circuits are denoted by lines beginning with ".subckt", followed by sub-circuit parameters, followed by the models inside them, numbered sequentially and beginning with ".model some_name.1". I need to leave the entire sub-circuit as is. After the end of the sub-circuit, I need to append everything in the sub-circuit until the first model, then append the first model and remove the remaining models, and repeat this process for all of the models within the sub-circuit. For example, if I have a sub-circuit with two models in it, the end result would be three total sub-circuits, the original containing both models, and two new sub-circuits each containing one of the models.
I have been trying to solve this using QRegExp, cap() and reading the files line by line, but one of the problems I have encountered is that because the ".subckt" and ".model" are on separate lines, it does not capture everything after ".subckt" until ".model", it captures everything on the same line as ".subckt". Also the number of models within each sub-circuit is not constant, so I need a way to create as many new sub-circuits as there are models in a given sub-circuit.
Is QRegExp and cap() the way to go with this? Also, I need help with creating the loop or function that can count the number of models in a sub-circuit and create that number of new sub-circuits. Any help and suggestions are greatly appreciated. Thank you for you time and help.

anda_skoa
30th July 2015, 21:09
Maybe it would be better to parse the file into data structures, then manipulate these structures and then write the data out to a file again.

Cheers,
_

ar_jym
30th July 2015, 21:18
Thank you for your reply. How would I parse the file into data structures? Would I write my own parser or are there features for that?

anda_skoa
31st July 2015, 08:28
There are several ways to write a parser.

If the format is line oriented you can read lines and then parse each line depending on what you are expecting at the moment.

Cheers,
_

ar_jym
31st July 2015, 21:55
Can you give me an example of how I can do this? I am using QRegExp to capture lines and then put them in a QStringList. What type of data structure do you mean and how can I use the data in the structures later? Thank you.

anda_skoa
1st August 2015, 11:31
That depends on your data.
You write that you have sub circuits and models.
Find out which data they can hold and you arrive at the fields for these datastructures.
You can of course also just keep the strings.

The whole point is to make it easier for you to work on that data given your requirements.

Cheers,
_