Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-07-26 16:46:22


> !Pseudocode;
>
> double app_data;
>
> Widget* line_edit;
>
> Binding app_data_connection
> (ref(app_data) >> scale(10.) >> to_string(fixed(),
> precision(2)));
>
> // Move app_data to Widget
> app_data_connection.write();
>
> // Update app_data from Widget
> app_data_connection.read();
>

Great idea!.

Also you can use formating template parameters.

Pseudocode
----------

//format class
class Precision
{
public:
   int m_prec;
   
   Precision& operator=(int prec)
   {
      m_prec = prec;
      return *this;
   }

   std::string operator()( double d )
   {
       do the conversion and return string
   }
};

f()
{
...
Widget<double>* line_edit;
double app_data;
Precision prec;
prec. = 2;
line_edit.set( app_data, prec );
...
prec = 3;
line_edit.set( app_data, prec );
...
}

template< typename T>
class Widget
{
  template <typename Format>
  void set( T d, Format f )
  {
     std::string text;
     text = f(d)
     ...use the text
  }
};

Eugene

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk