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 15 #ifndef LIBSPIRV_PRINT_H_ 16 #define LIBSPIRV_PRINT_H_ 17 18 #include <iostream> 19 #include <sstream> 20 21 namespace libspirv { 22 23 // Wrapper for out stream selection. 24 class out_stream { 25 public: out_stream()26 out_stream() : pStream(nullptr) {} out_stream(std::stringstream & stream)27 explicit out_stream(std::stringstream& stream) : pStream(&stream) {} 28 get()29 std::ostream& get() { 30 if (pStream) { 31 return *pStream; 32 } 33 return std::cout; 34 } 35 36 private: 37 std::stringstream* pStream; 38 }; 39 40 namespace clr { 41 // Resets console color. 42 struct reset { 43 operator const char*(); 44 }; 45 // Sets console color to grey. 46 struct grey { 47 operator const char*(); 48 }; 49 // Sets console color to red. 50 struct red { 51 operator const char*(); 52 }; 53 // Sets console color to green. 54 struct green { 55 operator const char*(); 56 }; 57 // Sets console color to yellow. 58 struct yellow { 59 operator const char*(); 60 }; 61 // Sets console color to blue. 62 struct blue { 63 operator const char*(); 64 }; 65 } // namespace clr 66 67 } // namespace libspirv 68 69 #endif // LIBSPIRV_PRINT_H_ 70