scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
dimension.hpp File Reference
#include "./prefix.hpp"
#include "boost/algorithm/string.hpp"
#include "unicode/uchar.h"
#include <algorithm>
#include <cstring>
#include <cstddef>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
Include dependency graph for dimension.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  scifir::dimension
 Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes, 1 byte for the dimension type, 1 byte for the prefix, 1 byte for the position (which can be the NUMERATOR or the DENOMINATOR), and 3 bytes for the custom dimension (in case it's used one). A base dimension is a dimension that doesn't has more base dimensions, a derived dimension has always base dimensions from which it's defined. More...
 

Namespaces

namespace  scifir
 The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
 

Functions

vector< dimensionscifir::create_dimensions (string init_dimensions)
 Creates the dimensions from an initialization string of dimensions.
 
vector< dimensionscifir::create_base_dimensions (const string &init_dimensions)
 Creates the base dimensions from an initialization string of dimensions.
 
string scifir::to_string (const dimension &x)
 Creates the string representation of a dimension.
 
string scifir::to_string (const vector< dimension > &x_dimensions, bool with_brackets)
 Creates the string representation of a vector of dimensions. Used to display the dimensions of scalar_unit and all vector_unit classes. The dimensions can be displayed optionally between brackets like '[]' too.
 
string scifir::to_latex (const vector< dimension > &x_dimensions, bool with_brackets)
 
vector< dimensionscifir::create_base_dimensions (const vector< dimension > &x)
 Creates all the base dimensions from a vector of dimensions.
 
vector< dimensionscifir::create_base_dimensions (const vector< dimension > &x, long double &value)
 Creates all the base dimensions from a vector of dimensions, updating also the associated value related to those dimensions based on the prefix math and the conversion factor of the dimension, if that conversion factor is different than one.
 
vector< dimensionscifir::multiply_dimensions (const vector< dimension > &x, const vector< dimension > &y)
 Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensions at the numerator and at the denominator are cancelled.
 
vector< dimensionscifir::multiply_dimensions (vector< dimension > x, const vector< dimension > &y, long double &value)
 Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensions at the numerator and at the denominator are cancelled. It also updates the value associated with those two vectors of dimensions with the prefix m ath and the conversion factor of those dimensions.
 
vector< dimensionscifir::divide_dimensions (vector< dimension > x, const vector< dimension > &y, long double &value)
 Divides the first vector of dimensions with the other. The result is normalized after, which means that equal dimensions at the numerator and at the denominator are cancelled. It also updates the value associated with those two vectors of dimensions with the prefix m ath and the conversion factor of those dimensions.
 
vector< dimensionscifir::square_dimensions (vector< dimension > x, int index, long double &value)
 Squares a vector of dimensions by an index. The value is updated too related to the prefix math and the conversion factor of this operation.
 
vector< dimensionscifir::power_dimensions (const vector< dimension > &x, int exponent)
 Powers the dimensions by an exponent.
 
vector< dimensionscifir::normalize_dimensions (const vector< dimension > &x)
 Normalizes the dimensions, which means that repited dimensions at the numerator and at the denominator are cancelled.
 
vector< dimensionscifir::normalize_dimensions (const vector< dimension > &x, long double &value)
 Normalizes the dimensions, which means that repited dimensions at the numerator and at the denominator are cancelled. The value is updated if there are dimensions cancelled.
 
bool scifir::is_dimension_char (const UChar32 &x)
 
bool scifir::common_dimension (const dimension &x, const dimension &y)
 Checks if there's an equal basic dimension between the basic dimensions of those two dimensions.
 
bool scifir::equal_dimensions (const string &init_dimensions_x, const string &init_dimensions_y)
 Checks if two initialization strings of dimensions initialize the same basic dimensions.
 
bool scifir::equal_dimensions (const vector< dimension > &x, const vector< dimension > &y)
 
bool scifir::equal_dimensions_and_prefixes (const vector< dimension > &x, const vector< dimension > &y)
 Checks if the base dimensions of two vectors of dimensions are equal, and if they have also the same prefixes.
 
bool operator== (const scifir::dimension &x, const scifir::dimension &y)
 Checks if the dimension type, the position and the prefix of two dimensions are the same.
 
bool operator!= (const scifir::dimension &x, const scifir::dimension &y)
 Checks if the dimension type and the position of two dimensions are any of them different. The prefix is not compared.
 
ostream & operator<< (ostream &os, const scifir::dimension &x)
 Adds the string representation of a dimension to an output stream.
 

Function Documentation

◆ operator!=()

bool operator!= ( const scifir::dimension x,
const scifir::dimension y 
)

Checks if the dimension type and the position of two dimensions are any of them different. The prefix is not compared.

Definition at line 2471 of file dimension.cpp.

2472{
2473 return !(x == y);
2474}

◆ operator<<()

ostream & operator<< ( ostream &  os,
const scifir::dimension x 
)

Adds the string representation of a dimension to an output stream.

Definition at line 2476 of file dimension.cpp.

2477{
2478 return os << x.prefix.get_symbol() << x.get_symbol();
2479}
scifir::prefix prefix
The prefix of the dimension. It's used along with the symbol of the dimension when printing it.
Definition dimension.hpp:74
string get_symbol() const
Returns the symbol of the dimension. In the case of a custom dimension, it returns the custom dimensi...
string get_symbol() const
Symbol of the prefix given the prefix_type. The symbol of micro is supported in his Unicode version.
Definition prefix.cpp:152

◆ operator==()

bool operator== ( const scifir::dimension x,
const scifir::dimension y 
)

Checks if the dimension type, the position and the prefix of two dimensions are the same.

Definition at line 2459 of file dimension.cpp.

2460{
2462 {
2463 return true;
2464 }
2465 else
2466 {
2467 return false;
2468 }
2469}
dimension::position dimension_position
The position of the dimension, which can be the NUMERATOR, the DENOMINATOR or NO_POSITION....
Definition dimension.hpp:76
dimension::type dimension_type
The type of the dimension.
Definition dimension.hpp:75