Re: TreeView::append_column_numeric() format?



On Tue, 2004-11-23 at 04:23, Murray Cumming wrote:
> > pks timing com writes:
> >  >
> >  >   append_column_numeric(modelcolumn, Gtk::FixedDecimals(3));
> 
> So far I think:
> 1. I don't think it would be a good idea to add a whole generic numeric
> formatting framework to gtkmm just for use by this convenience method.
> 2. If this was not used in any other part of the API, then people would
> never become familiar with it, so it would make this method far too
> difficult to use.
> 
> >  >   append_column_numeric(modelcolumn, User::DerivedFormat(anything,
> > they_need, to_format));

How about taking a step back and making it more generic?
template <typename Trans>
append_column_translated(modelcolumn, const Trans& translator =
Trans());

template <typename T>
struct NumericTranslatorSample {
NumericTranslatorSample(int precision = 0) : _prec(precision) {}
    string ConvertToRep(const T& val) {
	stringstream s;
	s << setw(_prec) << val << ends;
	return s.str();
    }
    T ConvertFromRep(const string& str) {
	stringstream s(str);
	T val;
	s >> setw(_prec) >> val;
	return val;
    }
    int _prec;
};

TreeModelColumn<int> foo;
TreeModelColumn<float> bar;
TreeModelColumn<complex> baz;
TreeModelColumn<MyType> whatever

append_column_translated<NumericTranslatorSample<int> >(foo);
append_column_translated<NumericTranslatorSample<float> >(bar,
    NumericTranslatorSample<float>(4));
append_column_translated<NumericTranslatorSample<complex> >(baz);
append_column_translated<MyTranslator>(whatever);


This is what I had in mind in cojunction with the lexical_cast<> code.

Regards,
Carl




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]