llstreamtools.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @file llstreamtools.h
  3. * @brief some helper functions for parsing legacy simstate and asset files.
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewergpl$
  6. *
  7. * Copyright (c) 2005-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_STREAM_TOOLS_H
  33. #define LL_STREAM_TOOLS_H
  34. #include <deque>
  35. #include <iostream>
  36. #include <string>
  37. #include <vector>
  38. #include "llpreprocessor.h"
  39. // Unless specifed otherwise these all return input_stream.good()
  40. // Skips emptyspace and lines that start with a #
  41. bool skip_comments_and_emptyspace(std::istream& input_stream);
  42. // Skips to character after the end of next keyword. A 'keyword' is defined as
  43. // the first word on a line
  44. bool skip_to_end_of_next_keyword(const char* keyword,
  45. std::istream& input_stream);
  46. bool get_line(std::string& output_string, std::istream& input_stream, int n);
  47. // *TODO: move these string manipulator functions to a different file
  48. // The 'keyword' is defined as the first word on a line
  49. // The 'value' is everything after the keyword on the same line starting at the
  50. // first non-whitespace and ending right before the newline.
  51. void get_keyword_and_value(std::string& keyword, std::string& value,
  52. const std::string& line);
  53. // Continue to read from the stream until you really cannot read anymore or
  54. // until we hit the count. Some istream implementations have a max that they
  55. // will read. Returns the number of bytes read.
  56. std::streamsize fullread(std::istream& istr, char* buf,
  57. std::streamsize requested);
  58. std::istream& operator>>(std::istream& str, const char* tocheck);
  59. // cat_streambuf is a std::streambuf subclass that accepts a variadic number
  60. // of std::streambuf* (e.g. some_istream.rdbuf()) and virtually concatenates
  61. // their contents. Derived from https://stackoverflow.com/a/49441066/5533635
  62. class cat_streambuf : public std::streambuf
  63. {
  64. public:
  65. // Only valid for std::streambuf* arguments
  66. template <typename... Inputs>
  67. cat_streambuf(Inputs... inputs)
  68. : mInputs{inputs...},
  69. mBuffer(1024)
  70. {
  71. }
  72. int underflow() override;
  73. private:
  74. std::deque<std::streambuf*> mInputs;
  75. std::vector<char> mBuffer;
  76. };
  77. #endif // LL_STREAM_TOOLS_H