TextReader.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "Types.h"
  23. namespace crown
  24. {
  25. class File;
  26. /// A reader that offers a convenient way to read text from a File
  27. class TextReader
  28. {
  29. public:
  30. TextReader(File& file);
  31. /// Reads characters from file and stores them as a C string
  32. /// into string until (size-1) characters have been read or
  33. /// either a newline or the End-of-File is reached, whichever
  34. /// comes first.
  35. /// A newline character makes fgets stop reading, but it is considered
  36. /// a valid character and therefore it is included in the string copied to string.
  37. /// A null character is automatically appended in str after the characters read to
  38. /// signal the end of the C string.
  39. size_t read_string(char* string, size_t size);
  40. private:
  41. File& m_file;
  42. };
  43. } // namespace crown