31 std::fill(exponents_.begin(), exponents_.end(), 0);
61 return dimensionless();
139 return unit_symbols[idx];
145 ASSERT(is_def()).error(
"UnitSI object must be defined!");
147 std::stringstream output;
152 if (exponents_[
UnitSI::order_m ]!=1 || exponents_[ UnitSI::order_md ]) {
156 if (exponents_[ UnitSI::order_md ]>0) output <<
"+";
158 if (exponents_[ UnitSI::order_md ]) {
159 if (exponents_[ UnitSI::order_md ]==-1) output <<
"-";
160 else if (exponents_[ UnitSI::order_md ]!=1) output << exponents_[
UnitSI::order_md ];
170 if (output.str().size() > 0) output << form.
delimiter;
171 output << unit_symbol(i);
172 if (exponents_[i] != 1) output << form.
exp_open << exponents_[i] << form.
exp_close;
175 if (output.str().size()==0) {
186 for(
unsigned int i=0; i < n_base_units; i++ ) {
187 if (i!=0) ss <<
", ";
206 for(
unsigned int i=0; i < n_base_units; i++ ) {
213 std::fill(exponents_.begin(), exponents_.end(), 0);
219 double coef = converter.
convert(actual_unit);
221 if ( converter.
unit_si() == (*this) ) {
224 THROW( ExcNoncorrespondingUnit() << EI_UnitDefinition(actual_unit) << EI_ExpectedUnit(this->format_text()) );
240 for (
unsigned int i=0; i<7; i++) {
253 for (
unsigned int i=0; i<7; i++) {
std::string format(OutputFormat form) const
Generic output formating method.
bool is_def() const
Return true if the unit is defined.
std::string format_text() const
std::vector< int > exponents_
static UnitSI & Pa()
Returns Pascal.
double convert_unit_from(std::string actual_unit) const
Convert and check user-defined unit.
static UnitSI & one()
Returns dimensionless unit.
std::string format(CStringRef format_str, ArgList args)
std::string format_latex() const
UnitSI unit_si() const
Return unit_si_.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
UnitSI operator*(const UnitSI &a, const UnitSI &b)
Product of two units.
UnitSI operator/(const UnitSI &a, const UnitSI &b)
Proportion of two units.
static UnitSI & W()
Returns Watt.
static UnitSI & J()
Returns Joule.
double convert(std::string actual_unit)
void multiply(const UnitSI &other, int exp=1)
Multiply with power of given unit.
static const std::string & unit_symbol(unsigned int idx)
bool operator==(const UnitSI &other) const
Comparison operator.
void reset()
Reset UnitSI object (set vector of exponents to zeros and set undef flag)
UnitSI & m(int exp=1)
Methods set values of exponents for SI units with similar name.
Class for representation SI units of Fields.
UnitSI & md(int exp=-1)
The dimension dependent meter: md^y = m^(yd), where 'd' is dimension.
static UnitSI & dimensionless()
Returns dimensionless unit.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
void undef(bool val=true)