1/* 2 * Copyright (c) 2002-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 37 unchanged lines hidden (view full) --- 46#define CPRINTF_DEFINITION VARARGS_DEFINITION(cp::Print) 47 48struct Print 49{ 50 protected: 51 std::ostream &stream; 52 const char *format; 53 const char *ptr; |
54 bool cont; |
55 56 std::ios::fmtflags saved_flags; 57 char saved_fill; 58 int saved_precision; 59 |
60 Format fmt; 61 void process(); |
62 63 public: 64 Print(std::ostream &stream, const std::string &format); 65 Print(std::ostream &stream, const char *format); 66 ~Print(); 67 |
68 int 69 get_number(int data) 70 { 71 return data; 72 } 73 |
74 template <typename T> |
75 int 76 get_number(const T& data) 77 { 78 return 0; 79 } 80 81 template <typename T> |
82 void 83 add_arg(const T &data) 84 { |
85 if (!cont) 86 process(); |
87 |
88 if (fmt.get_width) { 89 fmt.get_width = false; 90 cont = true; 91 fmt.width = get_number(data); 92 return; 93 } 94 95 if (fmt.get_precision) { 96 fmt.get_precision = false; 97 cont = true; 98 fmt.precision = get_number(data); 99 return; 100 } 101 |
102 switch (fmt.format) { 103 case Format::character: 104 format_char(stream, data, fmt); 105 break; 106 107 case Format::integer: 108 format_integer(stream, data, fmt); 109 break; --- 83 unchanged lines hidden --- |