• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
3 //
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 /**
12 \file
13 
14 \brief composite_output.cpp
15 
16 \details An example of textual representations of units.
17 
18 Output:
19 @verbatim
20 
21 //[conversion_output_output
22 2 dyn
23 2 dyn
24 2 dyne
25 cm g s^-1
26 centimeter gram second^-1
27 dyn
28 dyne
29 n
30 nano
31 n
32 nano
33 F
34 farad
35 1 F
36 1 farad
37 nF
38 nanofarad
39 1 nF
40 1 nanofarad
41 n(cm g s^-1)
42 nano(centimeter gram second^-1)
43 //]
44 
45 @endverbatim
46 **/
47 #include <boost/units/quantity.hpp>
48 #include <boost/units/systems/cgs.hpp>
49 #include <boost/units/io.hpp>
50 #include <boost/units/scale.hpp>
51 
52 #include <boost/units/detail/utility.hpp>
53 
54 #include <boost/units/systems/si/capacitance.hpp>
55 #include <boost/units/systems/si/io.hpp>
56 #include <boost/units/systems/si/prefixes.hpp>
57 
58 #include <iostream>
59 #include <sstream>
60 
61 namespace boost {
62 
63 namespace units {
64 
65 //[composite_output_snippet_1
66 
name_string(const cgs::force &)67 std::string name_string(const cgs::force&)
68 {
69     return "dyne";
70 }
71 
symbol_string(const cgs::force &)72 std::string symbol_string(const cgs::force&)
73 {
74     return "dyn";
75 }
76 
77 //]
78 
79 }
80 
81 }
82 
main()83 int main()
84 {
85     using namespace boost::units;
86     using boost::units::cgs::centimeter;
87     using boost::units::cgs::gram;
88     using boost::units::cgs::second;
89     using boost::units::cgs::dyne;
90 
91     //[composite_output_snippet_2]
92     std::cout << 2.0 * dyne << std::endl
93               << symbol_format << 2.0 * dyne << std::endl
94               << name_format << 2.0 * dyne << std::endl
95               << symbol_format << gram*centimeter/second << std::endl
96               << name_format << gram*centimeter/second << std::endl
97               << symbol_format << gram*centimeter/(second*second) << std::endl
98               << name_format << gram*centimeter/(second*second) << std::endl
99               << symbol_string(scale<10,static_rational<-9> >()) << std::endl
100               << name_string(scale<10,static_rational<-9> >()) << std::endl
101               << symbol_format << si::nano << std::endl
102               << name_format << si::nano << std::endl
103               << symbol_format << si::farad << std::endl
104               << name_format << si::farad << std::endl
105               << symbol_format << 1.0*si::farad << std::endl
106               << name_format << 1.0*si::farad << std::endl
107               << symbol_format << si::farad*si::nano << std::endl
108               << name_format << si::farad*si::nano << std::endl
109               << symbol_format << 1.0*si::farad*si::nano << std::endl
110               << name_format << 1.0*si::farad*si::nano << std::endl
111               << symbol_format << si::nano*gram*centimeter/second << std::endl
112               << name_format << si::nano*gram*centimeter/second << std::endl;
113     //]
114 
115     return 0;
116 }
117