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 other character types in filenames (fixes #6) #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions stl_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ namespace stl_reader {
*
* \returns true if the file was successfully read into the provided container.
*/
template <class TNumberContainer1, class TNumberContainer2,
template <class TChar,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile(const char* filename,
bool ReadStlFile(const TChar* filename,
TNumberContainer1& coordsOut,
TNumberContainer2& normalsOut,
TIndexContainer1& trisOut,
Expand All @@ -201,9 +202,10 @@ bool ReadStlFile(const char* filename,
/** \copydetails ReadStlFile
* \sa ReadStlFile, ReadStlFile_ASCII
*/
template <class TNumberContainer1, class TNumberContainer2,
template <class TChar,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_ASCII(const char* filename,
bool ReadStlFile_ASCII(const TChar* filename,
TNumberContainer1& coordsOut,
TNumberContainer2& normalsOut,
TIndexContainer1& trisOut,
Expand All @@ -214,9 +216,10 @@ bool ReadStlFile_ASCII(const char* filename,
* \todo support systems with big endianess
* \sa ReadStlFile, ReadStlFile_BINARY
*/
template <class TNumberContainer1, class TNumberContainer2,
template <class TChar,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_BINARY(const char* filename,
bool ReadStlFile_BINARY(const TChar* filename,
TNumberContainer1& coordsOut,
TNumberContainer2& normalsOut,
TIndexContainer1& trisOut,
Expand All @@ -227,7 +230,8 @@ bool ReadStlFile_BINARY(const char* filename,
* with the keyword solid. This should work for many stl files, but may
* fail, of course.
*/
inline bool StlFileHasASCIIFormat(const char* filename);
template<typename TChar>
inline bool StlFileHasASCIIFormat(const TChar* filename);


/// convenience mesh class which makes accessing the stl data more easy
Expand All @@ -242,20 +246,27 @@ class StlMesh {

/// initializes the mesh from the stl-file specified through filename
/** \{ */
StlMesh (const char* filename)
template<class TChar>
StlMesh (const TChar* filename)
{
read_file (filename);
}

StlMesh (const std::string& filename)
{
read_file (filename);
read_file (filename.c_str());
}

StlMesh (const std::wstring& wfilename)
{
read_file (wfilename.c_str());
}
/** \} */

/// fills the mesh with the contents of the specified stl-file
/** \{ */
bool read_file (const char* filename)
template<class TChar>
bool read_file (const TChar* filename)
{
bool res = false;

Expand All @@ -280,11 +291,6 @@ class StlMesh {

return res;
}

bool read_file (const std::string& filename)
{
return read_file (filename.c_str());
}
Comment on lines -284 to -287
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry, I didn't see this last time. But it seems that you removed this method? I think it is in the public interface, so some users may rely on it. Unless there's a good reason to remove it, I would thus rather keep it. And if we have an std::string overload, I think it would even make sense to add a second overload with const std::wstring&, as you did in the constructor...

/** \} */

/// returns the number of vertices in the mesh
Expand Down Expand Up @@ -509,9 +515,10 @@ namespace stl_reader_impl {
}// end of namespace stl_reader_impl


template <class TNumberContainer1, class TNumberContainer2,
template <class TChar,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile(const char* filename,
bool ReadStlFile(const TChar* filename,
TNumberContainer1& coordsOut,
TNumberContainer2& normalsOut,
TIndexContainer1& trisOut,
Expand All @@ -524,9 +531,10 @@ bool ReadStlFile(const char* filename,
}


template <class TNumberContainer1, class TNumberContainer2,
template <class TChar,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_ASCII(const char* filename,
bool ReadStlFile_ASCII(const TChar* filename,
TNumberContainer1& coordsOut,
TNumberContainer2& normalsOut,
TIndexContainer1& trisOut,
Expand Down Expand Up @@ -634,9 +642,10 @@ bool ReadStlFile_ASCII(const char* filename,
}


template <class TNumberContainer1, class TNumberContainer2,
template <class TChar,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_BINARY(const char* filename,
bool ReadStlFile_BINARY(const TChar* filename,
TNumberContainer1& coordsOut,
TNumberContainer2& normalsOut,
TIndexContainer1& trisOut,
Expand Down Expand Up @@ -699,8 +708,8 @@ bool ReadStlFile_BINARY(const char* filename,
return true;
}


inline bool StlFileHasASCIIFormat(const char* filename)
template<class TChar>
inline bool StlFileHasASCIIFormat(const TChar* filename)
{
using namespace std;
ifstream in(filename);
Expand Down