composite_output.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. \file
  12. \brief composite_output.cpp
  13. \details An example of textual representations of units.
  14. Output:
  15. @verbatim
  16. //[conversion_output_output
  17. 2 dyn
  18. 2 dyn
  19. 2 dyne
  20. cm g s^-1
  21. centimeter gram second^-1
  22. dyn
  23. dyne
  24. n
  25. nano
  26. n
  27. nano
  28. F
  29. farad
  30. 1 F
  31. 1 farad
  32. nF
  33. nanofarad
  34. 1 nF
  35. 1 nanofarad
  36. n(cm g s^-1)
  37. nano(centimeter gram second^-1)
  38. //]
  39. @endverbatim
  40. **/
  41. #include <boost/units/quantity.hpp>
  42. #include <boost/units/systems/cgs.hpp>
  43. #include <boost/units/io.hpp>
  44. #include <boost/units/scale.hpp>
  45. #include <boost/units/detail/utility.hpp>
  46. #include <boost/units/systems/si/capacitance.hpp>
  47. #include <boost/units/systems/si/io.hpp>
  48. #include <boost/units/systems/si/prefixes.hpp>
  49. #include <iostream>
  50. #include <sstream>
  51. namespace boost {
  52. namespace units {
  53. //[composite_output_snippet_1
  54. std::string name_string(const cgs::force&)
  55. {
  56. return "dyne";
  57. }
  58. std::string symbol_string(const cgs::force&)
  59. {
  60. return "dyn";
  61. }
  62. //]
  63. }
  64. }
  65. int main()
  66. {
  67. using namespace boost::units;
  68. using boost::units::cgs::centimeter;
  69. using boost::units::cgs::gram;
  70. using boost::units::cgs::second;
  71. using boost::units::cgs::dyne;
  72. //[composite_output_snippet_2]
  73. std::cout << 2.0 * dyne << std::endl
  74. << symbol_format << 2.0 * dyne << std::endl
  75. << name_format << 2.0 * dyne << std::endl
  76. << symbol_format << gram*centimeter/second << std::endl
  77. << name_format << gram*centimeter/second << std::endl
  78. << symbol_format << gram*centimeter/(second*second) << std::endl
  79. << name_format << gram*centimeter/(second*second) << std::endl
  80. << symbol_string(scale<10,static_rational<-9> >()) << std::endl
  81. << name_string(scale<10,static_rational<-9> >()) << std::endl
  82. << symbol_format << si::nano << std::endl
  83. << name_format << si::nano << std::endl
  84. << symbol_format << si::farad << std::endl
  85. << name_format << si::farad << std::endl
  86. << symbol_format << 1.0*si::farad << std::endl
  87. << name_format << 1.0*si::farad << std::endl
  88. << symbol_format << si::farad*si::nano << std::endl
  89. << name_format << si::farad*si::nano << std::endl
  90. << symbol_format << 1.0*si::farad*si::nano << std::endl
  91. << name_format << 1.0*si::farad*si::nano << std::endl
  92. << symbol_format << si::nano*gram*centimeter/second << std::endl
  93. << name_format << si::nano*gram*centimeter/second << std::endl;
  94. //]
  95. return 0;
  96. }