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

fs::path <> string interoperability #7817

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

dimitre
Copy link
Member

@dimitre dimitre commented Dec 12, 2023

this PR is to experiment interoperability between fs::path and string.
I think this was not happening before because of some systems were using
std::experimental::filesystem::v1::__cxx11::path which caused errors when converting fs::path to string.
I've updated ofConstants.h in this PR so __cxx11 is not being used anymore

@dimitre
Copy link
Member Author

dimitre commented Dec 12, 2023

it will cause some test errors with stuff like
ofToDataPath(path).back() to get the latest character of a string, and it doesnt' work with fs::path
I personally think the gains outweight the potential differences.
the idea here is change return type to fs::path and remove the FS() versions
thoughts? @artificiel @ofTheo

@artificiel
Copy link
Contributor

+1 for path return type everywhere.

for the failing tests they should be updated to explicitly perform the string conversion:

ofxTestEq(ofPathToString(ofToDataPath("movies\\",true)).back(), '\\', "absolute ofToDataPath with \\ should end in \\");

(incidentally it's more or less what someone holding to some legacy code using string methods directly on the return of ofDataPath might need to do, but method chaining is not prevalent in user code)

@dimitre
Copy link
Member Author

dimitre commented Dec 12, 2023

Great. if we decide to proceed with this idea I'll complete the work in this same PR.

@dimitre dimitre marked this pull request as ready for review January 6, 2024 21:47
@dimitre
Copy link
Member Author

dimitre commented Jan 6, 2024

I've finally finished this one. I've updated the tests accordingly.
This PR changes return type from a number of core functions from string to fs::path
but brings end to end fs::path to the core.

opinions? @ofTheo @NickHardeman @artificiel @danoli3

@ofTheo
Copy link
Member

ofTheo commented Jan 6, 2024 via email

@dimitre
Copy link
Member Author

dimitre commented Jan 6, 2024

In the tests the things I had to change is something like ofToDataPath("").back()
and my own usage the only thing I had to change is one addon using this line

	string resultado = ofSystem("open " + ofToDataPath(fullFileName));

I had to switch to something like:

	string resultado = ofSystem("open " + ofPathToString(ofToDataPath(fullFileName)));
or 
	string resultado = ofSystem("open " + ofToDataPath(fullFileName).string());

@ofTheo
Copy link
Member

ofTheo commented Jan 7, 2024

ahh so does that mean any code that has string + fs::path ( which used to be ) string + string, now needs something like: string + fs::path.string().

I guess that is the downside - but the upside is support for non English filesystems right?

@dimitre
Copy link
Member Author

dimitre commented Jan 7, 2024

Yes exactly. support for different encodings end to end inside core.
I think two things are important for using OF for teaching:
being able to parse non english characters on path, and being able to work with spaces in paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants