print.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2015-2016 The Khronos Group Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef SOURCE_PRINT_H_
  15. #define SOURCE_PRINT_H_
  16. #include <iostream>
  17. #include <sstream>
  18. namespace spvtools {
  19. // Wrapper for out stream selection.
  20. class out_stream {
  21. public:
  22. out_stream() : pStream(nullptr) {}
  23. explicit out_stream(std::stringstream& stream) : pStream(&stream) {}
  24. std::ostream& get() {
  25. if (pStream) {
  26. return *pStream;
  27. }
  28. return std::cout;
  29. }
  30. private:
  31. std::stringstream* pStream;
  32. };
  33. namespace clr {
  34. // Resets console color.
  35. struct reset {
  36. operator const char*();
  37. bool isPrint;
  38. };
  39. // Sets console color to grey.
  40. struct grey {
  41. operator const char*();
  42. bool isPrint;
  43. };
  44. // Sets console color to red.
  45. struct red {
  46. operator const char*();
  47. bool isPrint;
  48. };
  49. // Sets console color to green.
  50. struct green {
  51. operator const char*();
  52. bool isPrint;
  53. };
  54. // Sets console color to yellow.
  55. struct yellow {
  56. operator const char*();
  57. bool isPrint;
  58. };
  59. // Sets console color to blue.
  60. struct blue {
  61. operator const char*();
  62. bool isPrint;
  63. };
  64. } // namespace clr
  65. } // namespace spvtools
  66. #endif // SOURCE_PRINT_H_