Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple extensions in parse_file_extension_argument (). #2347

Merged
merged 1 commit into from
Jun 27, 2018

Conversation

frozar
Copy link
Contributor

@frozar frozar commented Jun 20, 2018

Add another parse_file_extension_argument () which deals with several extensions given as argument.

@taketwo
Copy link
Member

taketwo commented Jun 20, 2018

Let's try to avoid copy/pasted code. The "old" parse function can now be implemented by simply running the new one: parse_file_extension_argument (argc, argv, { ext });

Also, please improve the docstring.
Edit: sorry, I was not specific. I meant that the name of parameter inside the docstring should match the one in code. Also, I think using plural "extensions" would be better.

@frozar
Copy link
Contributor Author

frozar commented Jun 20, 2018

Ok, I did another proposition in the last commit.
Edit*: I cannot do the vector initialisation you proposed because this syntax is supported only since c++-11

/** \brief Parse command line arguments for file names with given extension
* \param[in] argc the number of command line arguments
* \param[in] argv the command line arguments
* \param[in] ext the extension to search for
* \return a vector with file names indices
*/
PCL_EXPORTS std::vector<int>
parse_file_extension_argument (int argc, const char * const * argv, const std::string &ext);
parse_file_extension_argument (int argc, const char * const * argv, const std::string ext)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference got lost

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad.

{
std::vector<int> indices;
for (int i = 1; i < argc; ++i)
{
std::string fname = std::string (argv[i]);
std::string ext = extension;
bool found = false;
for (int j = 0; j < extension.size (); ++j)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: comparison of integers of different signs: 'int' and 'std::vector::size_type' (aka 'unsigned long') [-Wsign-compare]

Please use size_t

// Additional check: we want to be able to differentiate between .p and .png
if ((ext.size () - (fname.size () - it)) == 0)
indices.push_back (i);
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you are trying to achieve here. continue in the end of the iteration does not do anything, it will "continue" anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it was a pretty bad joke (but makes me laugth a lot).

@frozar
Copy link
Contributor Author

frozar commented Jun 21, 2018

For an unobvious reason, the compilation of the app pcl_pcd_video_player failes. The error message is:

CMakeFiles/pcl_pcd_video_player.dir/src/pcd_video_player/pcd_video_player.cpp.o: In function `~sp_counted_base':
/home/travis/build/PointCloudLibrary/pcl/common/include/pcl/console/parse.h:369: multiple definition of `pcl::console::parse_file_extension_argument(int, char const* const*, std::string const&)'
CMakeFiles/pcl_pcd_video_player.dir/include/pcl/apps/moc_pcd_video_player.cxx.o:/home/travis/build/PointCloudLibrary/pcl/common/include/pcl/console/parse.h:369: first defined here
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)

Locally, I also see that the compilation of other apps fail too.

If a have any suggest to fix it, don't hesitate!

@taketwo
Copy link
Member

taketwo commented Jun 21, 2018

If a function is defined directly in header you should inline it. However, I'd prefer if you move implementation (even though it's a three-liner) to the "cpp" file.

@frozar
Copy link
Contributor Author

frozar commented Jun 21, 2018 via email

pcl::console::parse_file_extension_argument (int argc, const char * const * argv,
const std::string &ext)
{
std::vector<std::string> extensions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indentation.

@taketwo taketwo merged commit e560933 into PointCloudLibrary:master Jun 27, 2018
@frozar frozar deleted the parse_argument branch June 29, 2018 23:59
@SergioRAgostinho SergioRAgostinho changed the title [PARSE] Another 'parse_file_extension_argument ()' Add support for multiple extensions in parse_file_extension_argument () in console parsing tools. Aug 25, 2018
@SergioRAgostinho SergioRAgostinho changed the title Add support for multiple extensions in parse_file_extension_argument () in console parsing tools. Add support for multiple extensions in parse_file_extension_argument (). Aug 25, 2018
@SergioRAgostinho SergioRAgostinho added the changelog: enhancement Meta-information for changelog generation label Aug 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: enhancement Meta-information for changelog generation module: common
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants