| 1 | // | 
|---|---|
| 2 | // Units.cpp | 
| 3 | // | 
| 4 | // This sample demonstrates the Units. | 
| 5 | // | 
| 6 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | 
| 7 | // and Contributors. | 
| 8 | // | 
| 9 | // SPDX-License-Identifier: BSL-1.0 | 
| 10 | // | 
| 11 | |
| 12 | |
| 13 | #include "Poco/Util/Units.h" | 
| 14 | #include <iostream> | 
| 15 | |
| 16 | |
| 17 | using namespace Poco::Util::Units::Values; | 
| 18 | using namespace Poco::Util::Units::Constants; | 
| 19 | |
| 20 | |
| 21 | using Poco::Util::Units::square; | 
| 22 | using Poco::Util::Units::cube; | 
| 23 | |
| 24 | |
| 25 | namespace Poco { | 
| 26 | namespace Util { | 
| 27 | namespace Units { | 
| 28 | namespace Units { | 
| 29 | typedef Compose<Scale<N, 1, 1000>, Power<m, -3> > SpecificWeight;// [kN/m^3] | 
| 30 | } // namespace Units | 
| 31 | namespace Values { | 
| 32 | typedef Value<double, Units::SpecificWeight> SpecificWeight; | 
| 33 | } } } } // namespace Poco::Util::Units | 
| 34 | |
| 35 | |
| 36 | int main() | 
| 37 | { | 
| 38 | std::cout << "One mile is "<< km(mile(1)) << std::endl; | 
| 39 | // Output: One mile is 1.60934 km | 
| 40 | |
| 41 | std::cout << "Flow rate is "<< m3(mile(1)*inch(80)*foot(9))/s(minute(5)) << std::endl; | 
| 42 | // Output: Flow rate is 29.9026 (m)^3.(s)^-1 | 
| 43 | |
| 44 | hour h; | 
| 45 | //h = cm(3); // Compile-time error: incompatible units | 
| 46 | //h = 4; // Compile-time error: 4 of what? | 
| 47 | h = day(4); // Ok: h is 96 hours | 
| 48 | |
| 49 | m l = cm(42); | 
| 50 | std::cout << cm(42) << " == "<< l << " == "<< milli(l) << std::endl; | 
| 51 | std::cout << "Area of circle with radius "<< l << | 
| 52 | " is "<< mm2(square(l) * pi) << std::endl; | 
| 53 | |
| 54 | SpecificWeight sw(9.81); // water | 
| 55 | |
| 56 | std::cout << "Volume of a water cube with side size "<< m(0.1) << | 
| 57 | " is "<< liter(cube(m(0.1))) << | 
| 58 | " and weighs "<< N(sw * cube(m(.1))) << std::endl; | 
| 59 | |
| 60 | m radius_equator(6378135); | 
| 61 | m radius_pole(6356750); | 
| 62 | m3 vol((pi * square(radius_equator) * radius_pole) * 4/3); | 
| 63 | |
| 64 | std::cout << "Volume of Earth is "<< vol | 
| 65 | << " ("<< yotta(liter(vol)) << ")"<< std::endl; | 
| 66 | std::cout << "It takes "<< minute(AU/c) << " for a Sun beam to reach Earth."<< std::endl; | 
| 67 | |
| 68 | |
| 69 | std::cout << std::endl << m(1) << " is:"<< std::endl; | 
| 70 | std::cout << "-------------"<< std::endl; | 
| 71 | |
| 72 | std::cout << deca(m(1)) << std::endl; | 
| 73 | std::cout << hecto(m(1)) << std::endl; | 
| 74 | std::cout << kilo(m(1)) << std::endl; | 
| 75 | std::cout << mega(m(1)) << std::endl; | 
| 76 | std::cout << giga(m(1)) << std::endl; | 
| 77 | std::cout << tera(m(1)) << std::endl; | 
| 78 | std::cout << peta(m(1)) << std::endl; | 
| 79 | std::cout << exa(m(1)) << std::endl; | 
| 80 | std::cout << zetta(m(1)) << std::endl; | 
| 81 | std::cout << yotta(m(1)) << std::endl; | 
| 82 | |
| 83 | std::cout << deci(m(1)) << std::endl; | 
| 84 | std::cout << centi(m(1)) << std::endl; | 
| 85 | std::cout << milli(m(1)) << std::endl; | 
| 86 | std::cout << micro(m(1)) << std::endl; | 
| 87 | std::cout << nano(m(1)) << std::endl; | 
| 88 | std::cout << pico(m(1)) << std::endl; | 
| 89 | std::cout << femto(m(1)) << std::endl; | 
| 90 | std::cout << atto(m(1)) << std::endl; | 
| 91 | std::cout << zepto(m(1)) << std::endl; | 
| 92 | std::cout << yocto(m(1)) << std::endl; | 
| 93 | |
| 94 | return 0; | 
| 95 | } | 
| 96 | 
