Home | History | Annotate | Download | only in source
      1 // Copyright (c) 2015-2016 The Khronos Group Inc.
      2 //
      3 // Permission is hereby granted, free of charge, to any person obtaining a
      4 // copy of this software and/or associated documentation files (the
      5 // "Materials"), to deal in the Materials without restriction, including
      6 // without limitation the rights to use, copy, modify, merge, publish,
      7 // distribute, sublicense, and/or sell copies of the Materials, and to
      8 // permit persons to whom the Materials are furnished to do so, subject to
      9 // the following conditions:
     10 //
     11 // The above copyright notice and this permission notice shall be included
     12 // in all copies or substantial portions of the Materials.
     13 //
     14 // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
     15 // KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
     16 // SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
     17 //    https://www.khronos.org/registry/
     18 //
     19 // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     22 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
     23 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     24 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     25 // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
     26 
     27 #ifndef LIBSPIRV_PRINT_H_
     28 #define LIBSPIRV_PRINT_H_
     29 
     30 #include <iostream>
     31 #include <sstream>
     32 
     33 namespace libspirv {
     34 
     35 // Wrapper for out stream selection.
     36 class out_stream {
     37  public:
     38   out_stream() : pStream(nullptr) {}
     39   explicit out_stream(std::stringstream& stream) : pStream(&stream) {}
     40 
     41   std::ostream& get() {
     42     if (pStream) {
     43       return *pStream;
     44     }
     45     return std::cout;
     46   }
     47 
     48  private:
     49   std::stringstream* pStream;
     50 };
     51 
     52 namespace clr {
     53 // Resets console color.
     54 struct reset {
     55   operator const char*();
     56 };
     57 // Sets console color to grey.
     58 struct grey {
     59   operator const char*();
     60 };
     61 // Sets console color to red.
     62 struct red {
     63   operator const char*();
     64 };
     65 // Sets console color to green.
     66 struct green {
     67   operator const char*();
     68 };
     69 // Sets console color to yellow.
     70 struct yellow {
     71   operator const char*();
     72 };
     73 // Sets console color to blue.
     74 struct blue {
     75   operator const char*();
     76 };
     77 }  // namespace clr
     78 
     79 }  // namespace libspirv
     80 
     81 #endif  // LIBSPIRV_PRINT_H_
     82