Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60612 - branches/units/autoprefix/libs/units/example
From: pbristow_at_[hidden]
Date: 2010-03-15 07:56:03


Author: pbristow
Date: 2010-03-15 07:56:02 EDT (Mon, 15 Mar 2010)
New Revision: 60612
URL: http://svn.boost.org/trac/boost/changeset/60612

Log:
Added thing_base_unit and euro_base_unit examples.
Text files modified:
   branches/units/autoprefix/libs/units/example/autoprefixes.cpp | 26 +++++++++++++++++++++++++-
   1 files changed, 25 insertions(+), 1 deletions(-)

Modified: branches/units/autoprefix/libs/units/example/autoprefixes.cpp
==============================================================================
--- branches/units/autoprefix/libs/units/example/autoprefixes.cpp (original)
+++ branches/units/autoprefix/libs/units/example/autoprefixes.cpp 2010-03-15 07:56:02 EDT (Mon, 15 Mar 2010)
@@ -58,6 +58,18 @@
   static const char* symbol() { return("b"); }
 };
 
+struct thing_base_unit : boost::units::base_unit<thing_base_unit, boost::units::dimensionless_type, 4>
+{
+ static const char* name() { return("thing"); }
+ static const char* symbol() { return(""); }
+};
+
+struct euro_base_unit : boost::units::base_unit<euro_base_unit, boost::units::dimensionless_type, 5>
+{
+ static const char* name() { return("EUR"); }
+ static const char* symbol() { return("€"); }
+};
+
 int main()
 {
   using std::cout;
@@ -88,7 +100,7 @@
 
   quantity<byte_base_unit::unit_type> b = 2048. * byte_base_unit::unit_type();
   cout << engineering_prefix << b << endl; // 2.048 kb
- cout << symbol_format << binary_prefix << b << endl; // "2 kib"
+ cout << symbol_format << binary_prefix << b << endl; // "2 Kib"
   //] [/autoprefixes_snippet_2]
 
   // Note that scalar dimensionless values are *not* prefixed automatically by the engineering_prefix or binary_prefix iostream manipulators.
@@ -118,7 +130,19 @@
   cout << boost::units::get_autoprefix(cout) << endl; // 8 is `autoprefix_binary` from `enum autoprefix_mode`.
   cout << boost::units::get_format(cout) << endl; // 1 is `name_fmt` from `enum format_mode`.
   //] [/autoprefixes_snippet_6]
+
+
+ quantity<thing_base_unit::unit_type> t = 2048. * thing_base_unit::unit_type();
+ cout << name_format << engineering_prefix << t << endl; // 2.048 kilothing
+ cout << symbol_format << engineering_prefix << t << endl; // 2.048 k
  
+ cout << binary_prefix << t << endl; // "2 Ki"
+
+ quantity<euro_base_unit::unit_type> ce = 2048. * euro_base_unit::unit_type();
+ cout << name_format << engineering_prefix << ce << endl; // 2.048 kiloEUR
+ cout << symbol_format << engineering_prefix << ce << endl; // 2.048 k€
+
+
     return 0;
 } // int main()
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk