fstream 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGDB_FSTREAM
  14. #define OSGDB_FSTREAM 1
  15. #include <osgDB/Export>
  16. #include <osg/Export>
  17. #include <fstream>
  18. namespace osgDB
  19. {
  20. /**
  21. * Convenience function for fstream open , std::ifstream, and std::ofstream to
  22. * automatically handle UTF-8 to UTF-16 filename conversion. Always use one
  23. * of these classes in any OpenSceneGraph code instead of the STL equivalent.
  24. */
  25. void OSGDB_EXPORT open(std::fstream& fs, const char* filename,std::ios_base::openmode mode);
  26. class ifstream : public std::ifstream
  27. {
  28. public:
  29. OSGDB_EXPORT ifstream();
  30. OSGDB_EXPORT explicit ifstream(const char* filename,
  31. std::ios_base::openmode mode = std::ios_base::in);
  32. OSGDB_EXPORT ~ifstream();
  33. void OSGDB_EXPORT open(const char* filename,
  34. std::ios_base::openmode mode = std::ios_base::in);
  35. };
  36. class ofstream : public std::ofstream
  37. {
  38. public:
  39. OSGDB_EXPORT ofstream();
  40. OSGDB_EXPORT explicit ofstream(const char* filename,
  41. std::ios_base::openmode mode = std::ios_base::out);
  42. OSGDB_EXPORT ~ofstream();
  43. void OSGDB_EXPORT open(const char* filename,
  44. std::ios_base::openmode mode = std::ios_base::out);
  45. };
  46. }
  47. #endif