Advertisement
WeltEnSTurm

Untitled

Jan 7th, 2012
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1.  
  2. #ifndef IO_HPP_
  3. #define IO_HPP_
  4.  
  5. #include <iostream>
  6. #include "exception.hpp"
  7.  
  8. namespace ws {
  9.     namespace io {
  10.  
  11.         inline void write(const std::string& s){
  12.             if(long(s.find('%')) >= 0)
  13.                 throw Exception("writeln: expected argument for each %");
  14.             std::cout << s;
  15.         }
  16.  
  17.         inline void write(const std::wstring& s){
  18.             if(long(s.find('%')) >= 0)
  19.                 throw Exception("writeln: expected argument for each %");
  20.             std::wcout << s;
  21.         }
  22.  
  23.         template<typename T>
  24.         inline void write(const T& o){
  25.             std::cout << o;
  26.         }
  27.  
  28.         inline void writeln(const std::string& s){
  29.             if(long(s.find('%')) >= 0)
  30.                 throw Exception("writeln: expected argument for each %");
  31.             std::cout << s << std::endl;
  32.         }
  33.  
  34.         inline void writeln(const std::wstring& s){
  35.             if(long(s.find('%')) >= 0)
  36.                 throw Exception("writeln: expected argument for each %");
  37.             std::wcout << s << std::endl;
  38.         }
  39.  
  40.         template<typename T>
  41.         inline void writeln(const T& o){
  42.             std::cout << o << std::endl;
  43.         }
  44.  
  45.         template<typename T, typename... Args>
  46.         inline void writeln(std::string s, T value, Args... args) {
  47.             if(s.find('%') >= 0){
  48.                 long i = s.find('%');
  49.                 write(s.substr(0, i));
  50.                 write(value);
  51.                 s.erase(0, i+1);
  52.                 writeln(s, args...);
  53.             }else
  54.                 throw Exception("writeln: expected argument IDs (%)");
  55.         }
  56.  
  57.  
  58.         template<typename T, typename... Args>
  59.         inline void writeln(std::wstring s, T value, Args... args) {
  60.             if(s.find('%') >= 0){
  61.                 long i = s.find('%');
  62.                 write(s.substr(0, i));
  63.                 write(value);
  64.                 s.erase(0, i+1);
  65.                 writeln(s, args...);
  66.             }else
  67.                 throw Exception("writeln: expected argument IDs (%)");
  68.         }
  69.  
  70.     }
  71. }
  72.  
  73. #endif /* IO_HPP_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement