X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffmt.h;h=ba75958802b7760b6f6b352827e4f313048e717f;hp=7dc605fd05086434d05def3a6165146033877f2b;hb=5b1368cb791cab043f0435628cacbaff36e39b7b;hpb=36f9e78ae75f5e14b132f37d249340ad3480b8ce diff --git a/source/fmt.h b/source/fmt.h index 7dc605f..ba75958 100644 --- a/source/fmt.h +++ b/source/fmt.h @@ -66,58 +66,60 @@ public: }; private: - unsigned wd; - unsigned prec; - bool spos; - wchar_t fillc; - Base base; - bool sbase; + unsigned wd; + unsigned prec; + bool spos; + wchar_t fillc; + Base base; + bool sbase; FloatMode fmode; - bool spoint; - Align align; - bool ucase; - Type type; + bool spoint; + Align align; + bool ucase; + Type type; public: - Fmt() { reset(); } - Fmt(const char *f) { reset(); parse(f); } + Fmt() { reset(); } + Fmt(const char *f) { reset(); parse(f); } Fmt(const std::string &f) { reset(); parse(f.c_str()); } - Fmt &width(unsigned w) { wd=w; return *this; } - Fmt &precision(unsigned p) { prec=p; return *this; } - Fmt &showpos(bool s=true) { spos=s; return *this; } - Fmt &fill(wchar_t f) { fillc=f; return *this; } - Fmt &fixed() { fmode=FIXED; return *this; } - Fmt &scientific() { fmode=SCI; return *this; } - Fmt &showpoint(bool s=true) { spoint=s; return *this; } - Fmt &showbase(bool s=true) { sbase=s; return *this; } - Fmt &left() { align=LEFT; return *this; } - Fmt &right() { align=RIGHT; return *this; } - Fmt &dec() { base=DEC; return *this; } - Fmt &hex() { base=HEX; return *this; } - Fmt &oct() { base=OCT; return *this; } - Fmt &bin() { base=BIN; return *this; } - Fmt &uppercase(bool u=true) { ucase=u; return *this; } - Fmt &numeric() { type=NUM; return *this; } - Fmt &character() { type=CHAR; return *this; } - Fmt &string() { type=STR; return *this; } +private: + void parse(const char *); + +public: + Fmt &width(unsigned w) { wd = w; return *this; } + Fmt &precision(unsigned p) { prec = p; return *this; } + Fmt &showpos(bool s=true) { spos = s; return *this; } + Fmt &fill(wchar_t f) { fillc = f; return *this; } + Fmt &fixed() { fmode = FIXED; return *this; } + Fmt &scientific() { fmode = SCI; return *this; } + Fmt &showpoint(bool s=true) { spoint = s; return *this; } + Fmt &showbase(bool s=true) { sbase = s; return *this; } + Fmt &left() { align = LEFT; return *this; } + Fmt &right() { align = RIGHT; return *this; } + Fmt &dec() { base = DEC; return *this; } + Fmt &hex() { base = HEX; return *this; } + Fmt &oct() { base = OCT; return *this; } + Fmt &bin() { base = BIN; return *this; } + Fmt &uppercase(bool u=true) { ucase = u; return *this; } + Fmt &numeric() { type = NUM; return *this; } + Fmt &character() { type = CHAR; return *this; } + Fmt &string() { type = STR; return *this; } Fmt &reset(); - unsigned get_width() const { return wd; } - unsigned get_precision() const { return prec; } - bool get_showpos() const { return spos; } - wchar_t get_fill() const { return fillc; } - Base get_base() const { return base; } - bool get_showbase() const { return sbase; } + unsigned get_width() const { return wd; } + unsigned get_precision() const { return prec; } + bool get_showpos() const { return spos; } + wchar_t get_fill() const { return fillc; } + Base get_base() const { return base; } + bool get_showbase() const { return sbase; } FloatMode get_floatmode() const { return fmode; } - bool get_showpoint() const { return spoint; } - Align get_align() const { return align; } - bool get_uppercase() const { return ucase; } - Type get_type() const { return type; } + bool get_showpoint() const { return spoint; } + Align get_align() const { return align; } + bool get_uppercase() const { return ucase; } + Type get_type() const { return type; } void apply(std::ostream &) const; -private: - void parse(const char *); }; inline std::ostream &operator<<(std::ostream &o, const Fmt &f)