Skip to content

Commit

Permalink
Add support for other character types in filenames (fixes sreiter#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hebert committed Jan 17, 2023
1 parent a878405 commit 84c237c
Showing 1 changed file with 32 additions and 23 deletions.
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 CharT,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile(const char* filename,
bool ReadStlFile(const CharT* 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 CharT,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_ASCII(const char* filename,
bool ReadStlFile_ASCII(const CharT* 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 CharT,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_BINARY(const char* filename,
bool ReadStlFile_BINARY(const CharT* 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 CharT>
inline bool StlFileHasASCIIFormat(const CharT* 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 CharT>
StlMesh (const CharT* 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 CharT>
bool read_file (const CharT* 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());
}
/** \} */

/// 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 CharT,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile(const char* filename,
bool ReadStlFile(const CharT* 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 CharT,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_ASCII(const char* filename,
bool ReadStlFile_ASCII(const CharT* 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 CharT,
class TNumberContainer1, class TNumberContainer2,
class TIndexContainer1, class TIndexContainer2>
bool ReadStlFile_BINARY(const char* filename,
bool ReadStlFile_BINARY(const CharT* 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 CharT>
inline bool StlFileHasASCIIFormat(const CharT* filename)
{
using namespace std;
ifstream in(filename);
Expand Down

0 comments on commit 84c237c

Please sign in to comment.