Spec -> EmptySpec. Improve comments.

This commit is contained in:
Victor Zverovich 2014-01-01 09:06:25 -08:00
parent 59c5612e87
commit fec6bc04f5
2 changed files with 12 additions and 13 deletions

View File

@ -322,12 +322,12 @@ enum Alignment {
// Flags. // Flags.
enum { SIGN_FLAG = 1, PLUS_FLAG = 2, HASH_FLAG = 4 }; enum { SIGN_FLAG = 1, PLUS_FLAG = 2, HASH_FLAG = 4 };
// Formatting specifier. // An empty format specifier.
struct Spec {}; struct EmptySpec {};
// Formatting type specifier. // A type specifier.
template <char TYPE> template <char TYPE>
struct TypeSpec : Spec { struct TypeSpec : EmptySpec {
Alignment align() const { return ALIGN_DEFAULT; } Alignment align() const { return ALIGN_DEFAULT; }
unsigned width() const { return 0; } unsigned width() const { return 0; }
@ -339,7 +339,7 @@ struct TypeSpec : Spec {
char fill() const { return ' '; } char fill() const { return ' '; }
}; };
// Formatting width specifier. // A width specifier.
struct WidthSpec { struct WidthSpec {
unsigned width_; unsigned width_;
// Fill is always wchar_t and cast to char if necessary to avoid having // Fill is always wchar_t and cast to char if necessary to avoid having
@ -352,17 +352,17 @@ struct WidthSpec {
wchar_t fill() const { return fill_; } wchar_t fill() const { return fill_; }
}; };
// Formatting alignment specifier. // An alignment specifier.
struct AlignSpec : WidthSpec { struct AlignSpec : WidthSpec {
Alignment align_; Alignment align_;
AlignSpec(unsigned width, wchar_t fill) AlignSpec(unsigned width, wchar_t fill, Alignment align = ALIGN_DEFAULT)
: WidthSpec(width, fill), align_(ALIGN_DEFAULT) {} : WidthSpec(width, fill), align_(align) {}
Alignment align() const { return align_; } Alignment align() const { return align_; }
}; };
// Formatting specifier that provides both alignment and type. // An alignment and type specifier.
template <char TYPE> template <char TYPE>
struct AlignTypeSpec : AlignSpec { struct AlignTypeSpec : AlignSpec {
AlignTypeSpec(unsigned width, wchar_t fill) : AlignSpec(width, fill) {} AlignTypeSpec(unsigned width, wchar_t fill) : AlignSpec(width, fill) {}
@ -374,7 +374,7 @@ struct AlignTypeSpec : AlignSpec {
char type() const { return TYPE; } char type() const { return TYPE; }
}; };
// Full formatting specifier. // A full format specifier.
struct FormatSpec : AlignSpec { struct FormatSpec : AlignSpec {
unsigned flags_; unsigned flags_;
char type_; char type_;
@ -382,8 +382,6 @@ struct FormatSpec : AlignSpec {
FormatSpec(unsigned width = 0, char type = 0, wchar_t fill = ' ') FormatSpec(unsigned width = 0, char type = 0, wchar_t fill = ' ')
: AlignSpec(width, fill), flags_(0), type_(type) {} : AlignSpec(width, fill), flags_(0), type_(type) {}
Alignment align() const { return align_; }
bool sign_flag() const { return (flags_ & SIGN_FLAG) != 0; } bool sign_flag() const { return (flags_ & SIGN_FLAG) != 0; }
bool plus_flag() const { return (flags_ & PLUS_FLAG) != 0; } bool plus_flag() const { return (flags_ & PLUS_FLAG) != 0; }
bool hash_flag() const { return (flags_ & HASH_FLAG) != 0; } bool hash_flag() const { return (flags_ & HASH_FLAG) != 0; }
@ -574,7 +572,7 @@ class BasicWriter {
return internal::CheckPtr(&buffer_[size], n); return internal::CheckPtr(&buffer_[size], n);
} }
CharPtr PrepareFilledBuffer(unsigned size, const Spec &, char sign) { CharPtr PrepareFilledBuffer(unsigned size, const EmptySpec &, char sign) {
CharPtr p = GrowBuffer(size); CharPtr p = GrowBuffer(size);
*p = sign; *p = sign;
return p + size - 1; return p + size - 1;

View File

@ -444,6 +444,7 @@ TEST(WriterTest, pad) {
TEST(WriterTest, PadString) { TEST(WriterTest, PadString) {
EXPECT_EQ("test ", str(Writer() << pad("test", 8))); EXPECT_EQ("test ", str(Writer() << pad("test", 8)));
EXPECT_EQ("test******", str(Writer() << pad("test", 10, '*')));
} }
TEST(WriterTest, NoConflictWithIOManip) { TEST(WriterTest, NoConflictWithIOManip) {