How to pass file name list as a function parameter!? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

How to pass file name list as a function parameter!?

Post by tomay3000 »

Hello,
I am writing a Zip compress and extract utility, and I need to pass file name list as a function parameter,
So, should I use:

Code: Select all

std::vector<wxString>& vstrFileNames // Correct me here about the reference passing if I am wrong.
Or:

Code: Select all

std::vector<wxFileName>& vstrFileNames // Correct me here about the reference passing if I am wrong.
Or: there exists already a class I am missing!?

TIA.
Last edited by tomay3000 on Mon Apr 27, 2020 6:23 pm, edited 1 time in total.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: How to pass file name list as a function parameter!?

Post by Kvaz1r »

Why are you want to use reference and not value type? You can share vector via wxSharedPtr<> instead or not share anything at all.
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: How to pass file name list as a function parameter!?

Post by tomay3000 »

Kvaz1r wrote: Sun Apr 26, 2020 8:29 pm Why are you want to use reference and not value type? You can share vector via wxSharedPtr<> instead or not share anything at all.
I need a list of wxString or wxFileName to be passed as a function parameter.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to pass file name list as a function parameter!?

Post by ONEEYEMAN »

Hi,
The strings vector seems much easier.
Also, depending on the scenario you might use const vector...

Thank you.
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: How to pass file name list as a function parameter!?

Post by tomay3000 »

ONEEYEMAN wrote: Mon Apr 27, 2020 6:41 pm Hi,
The strings vector seems much easier.
Also, depending on the scenario you might use const vector...

Thank you.
I completely forgot about const, also there are situations where I need to convert from a wxArrayString to an std::vector and vice versa, so are there any predefined helper macros to do this I am missing! or should I implement it myself?

TIA.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: How to pass file name list as a function parameter!?

Post by Kvaz1r »

Both class provide iterators so you can use them to create another container.
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: How to pass file name list as a function parameter!?

Post by tomay3000 »

Kvaz1r wrote: Mon Apr 27, 2020 8:02 pm Both class provide iterators so you can use them to create another container.
I just figured it out:

Code: Select all

std::vector<wxString> vStrFileNames;
wxArrayString arrStrFileNames;

for (wxArrayString::const_iterator it = arrStrFileNames.begin(); it != arrStrFileNames.end(); ++it)
    vStrFileNames.push_back(*it);
Thank you.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: How to pass file name list as a function parameter!?

Post by Kvaz1r »

I mean something more straightforward:

Code: Select all

	wxArrayString  arrStrFileNames;
	arrStrFileNames.assign(vStrFileNames.begin(), vStrFileNames.end());//from std::vector<>

	std::vector<wxString> vec(arrStrFileNames.begin(), arrStrFileNames.end());//from wxArrayString
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: How to pass file name list as a function parameter!?

Post by tomay3000 »

Kvaz1r wrote: Mon Apr 27, 2020 8:58 pm I mean something more straightforward:

Code: Select all

	wxArrayString  arrStrFileNames;
	arrStrFileNames.assign(vStrFileNames.begin(), vStrFileNames.end());//from std::vector<>

	std::vector<wxString> vec(arrStrFileNames.begin(), arrStrFileNames.end());//from wxArrayString
I completely missed that.

Thank you again.
Post Reply