cprintf.hh (4213:37a61d11f39f) cprintf.hh (5756:88038cdbb9e1)
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;
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;
54
55 std::ios::fmtflags saved_flags;
56 char saved_fill;
57 int saved_precision;
58
55
56 std::ios::fmtflags saved_flags;
57 char saved_fill;
58 int saved_precision;
59
59 void process(Format &fmt);
60 Format fmt;
61 void process();
60
61 public:
62 Print(std::ostream &stream, const std::string &format);
63 Print(std::ostream &stream, const char *format);
64 ~Print();
65
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
66 template <typename T>
74 template <typename T>
75 int
76 get_number(const T& data)
77 {
78 return 0;
79 }
80
81 template <typename T>
67 void
68 add_arg(const T &data)
69 {
82 void
83 add_arg(const T &data)
84 {
70 Format fmt;
71 process(fmt);
85 if (!cont)
86 process();
72
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
73 switch (fmt.format) {
74 case Format::character:
75 format_char(stream, data, fmt);
76 break;
77
78 case Format::integer:
79 format_integer(stream, data, fmt);
80 break;

--- 83 unchanged lines hidden ---
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 ---