stringstream.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "stream.h"
  18. namespace embree
  19. {
  20. /*! simple tokenizer that produces a string stream */
  21. class StringStream : public Stream<std::string>
  22. {
  23. public:
  24. StringStream(const Ref<Stream<int> >& cin, const std::string& seps = "\n\t\r ",
  25. const std::string& endl = "", bool multiLine = false);
  26. public:
  27. ParseLocation location() { return cin->loc(); }
  28. std::string next();
  29. private:
  30. __forceinline bool isSeparator(int c) const { return isSepMap[c]; }
  31. private:
  32. Ref<Stream<int> > cin; /*! source character stream */
  33. bool isSepMap[256]; /*! map for fast classification of separators */
  34. std::string endl; /*! the token of the end of line */
  35. bool multiLine; /*! whether to parse lines wrapped with \ */
  36. };
  37. }