Line data Source code
1 : /* @file dimension.hpp */ 2 : 3 : #pragma once 4 : 5 : #include <cstdint> 6 : 7 : namespace xo { 8 : namespace qty { 9 : enum class dim { 10 : invalid = -1, 11 : 12 : /** weight. native unit = 1 gram **/ 13 : mass, 14 : /** distance. native unit = 1 meter **/ 15 : distance, 16 : /** time. native unit = 1 second **/ 17 : time, 18 : /** a currency amount. native unit depends on actual currency. 19 : * For USD: one US dollar. 20 : * 21 : * NOTE: unit system isn't suitable for multicurrency work: 22 : * (1usd + 1eur) is well-defined, but (1sec + 1m) is not. 23 : **/ 24 : currency, 25 : /** a screen price **/ 26 : price, 27 : 28 : /** comes last, counts entries **/ 29 : n_dim 30 : }; 31 : 32 : inline const char * 33 27 : dim2str(dim x) 34 : { 35 27 : switch(x) { 36 : case dim::mass: return "mass"; 37 6 : case dim::distance: return "distance"; 38 6 : case dim::time: return "time"; 39 0 : case dim::currency: return "currency"; 40 0 : case dim::price: return "price"; 41 0 : default: break; 42 : } 43 0 : return "?dim"; 44 : } 45 : 46 : static constexpr std::size_t n_dim = static_cast<std::size_t>(dim::n_dim); 47 : } /*namespace qty*/ 48 : } /*namespace xo*/ 49 : 50 : /* end dimension.hpp */