[Interest] [External] Re: Design question: providing loop status

Sean Murphy Sean.M.Murphy at us.kbr.com
Thu Apr 21 17:13:44 CEST 2022


Thanks for the response!

> The most generic and flexible interface is to only do a certain number of
> iterations per function call, then the caller can do whatever is necessary for
> progress reporting and could even interrupt the process, e.g.:
>
> int lines = 0;
> while(thing.canParse()) {
>     lines += thing.parseLines(5);
>     Q_EMIT parsedLines(lines);
> }

Ok, so this idea would require modifications to my POD class (which I can do) to make
it a lot smarter than it currently is. Right now, the class just has a single "read from file"
function which has the following pseudo-code:

  bool parseFile(const std::string& filename)
  {
    // clear internal "dataItem" vector
    // open filename
    // while not EOF, parse filename, adding dataItems to the vector
    // return true if successful with all of the above, false otherwise
  }

So currently there's no intermediate states within that class, but I could probably refactor
it to add the functionality you're describing, while keeping the existing function above that
the current codebase relies on. Current codebase gets the dumb function, future users can
use the added functionality if they want.

> This requires moving state from the function itself to the class instance,
> which can be easy or hard depending on the content. Or if you can use
> C++20, maybe try coroutines? Those are basically a language feature for that.

I hadn't heard of these, but I'll check these out. I'm not sure we can use C++ 20 features -
we've got some older compilers that we might not be able to upgrade.

Thanks,
Sean
This e-mail, including any attached files, may contain confidential information, privileged information and/or trade secrets for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.


More information about the Interest mailing list