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
Public Member Functions | Public Attributes | Private Member Functions | List of all members
scifir::size_3d< T > Class Template Reference

Class that allows to store and calculate size in 3D, with width, height and depth. The template parameter T allows to select any scalar_unit or numeric type to be the type of the width, the height and the depth (they always have the same type in the same instance). The width, height and depth can be any scalar_unit, usually length, but imaginary spaces with custom dimensions are also allowed. Initialization string example: "1 m * 2 m * 4 m". More...

#include <size_3d.hpp>

Public Member Functions

 size_3d ()
 Default constructor. Both width, height and depth are initialized to 0, with the dimensions to the default of their base unit.
 
 size_3d (const size_3d< T > &x)
 Copy constructor. The width, height and depth are copied from the size_3d<T> x.
 
 size_3d (size_3d< T > &&x)
 Move constructor. The width, height and depth are moved from the size_3d<T> x.
 
 size_3d (const scalar_unit &new_width, const scalar_unit &new_height, const scalar_unit &new_depth)
 
 size_3d (const string &new_width, const string &new_height, const string &new_depth)
 Constructor. width is new_width, height is new_height and depth is new_depth, they are initialized by string.
 
 size_3d (const string &init_size_3d)
 Constructor. The member-variables are initialized by the initialization string init_size_3d.
 
size_3d< T > & operator= (const size_3d< T > &x)
 Copy assignment. The width, height and depth are copied from the size_3d<T> x.
 
size_3d< T > & operator= (size_3d< T > &&x)
 Move assignment. The width, height and depth are moved from the size_3d<T> x.
 
size_3d< T > & operator= (const string &init_size_3d)
 Assignment. The member-variables are initialized by the initialization string init_size_3d.
 
template<typename U >
size_3d< Toperator+ (const size_3d< U > &x) const
 Creates a new size_3d<T> by the addition of two size_3d<T> classes. The width, height and depth are the result of the addition of the two width, height or depth of the size_3d<T> classes.
 
template<typename U >
size_3d< Toperator- (const size_3d< U > &x) const
 Creates a new size_3d<T> by the difference of two size_3d<T> classes. The width, height and depth are the result of the difference of the two width, height or depth of the size_3d<T> classes.
 
template<typename U >
void operator+= (const size_3d< U > &x)
 Sums the width of size_3d<T> x to the width, sums the height of size_3d<T> x to the height and sums the depth of size_3d<T> x to the depth.
 
template<typename U >
void operator-= (const size_3d< U > &x)
 Substracts the width of size_3d<T> x to the width, substracts the height of size_3d<T> x to the height and substracts the depth of size_3d<T> x to the depth.
 
scalar_unit get_volume () const
 Calculates the volume as the multiplication of the width, height and depth.
 
string display () const
 Returns a string representation of size_3d<T>, with his width, height and depth.
 

Public Attributes

T width
 Width, usually stored as length.
 
T height
 Height, usually stored as length.
 
T depth
 Depth, usually stored as length.
 

Private Member Functions

void initialize_from_string (const string &init_size_3d)
 Internal function. Initializes the member-variables with an initialization string of size_3d<T>.
 

Detailed Description

template<typename T = length>
class scifir::size_3d< T >

Class that allows to store and calculate size in 3D, with width, height and depth. The template parameter T allows to select any scalar_unit or numeric type to be the type of the width, the height and the depth (they always have the same type in the same instance). The width, height and depth can be any scalar_unit, usually length, but imaginary spaces with custom dimensions are also allowed. Initialization string example: "1 m * 2 m * 4 m".

Definition at line 16 of file size_3d.hpp.

Constructor & Destructor Documentation

◆ size_3d() [1/6]

template<typename T = length>
size_3d::size_3d ( )
inline

Default constructor. Both width, height and depth are initialized to 0, with the dimensions to the default of their base unit.

Definition at line 19 of file size_3d.hpp.

19 : width(),height(),depth()
20 {}
T width
Width, usually stored as length.
Definition size_3d.hpp:101
T depth
Depth, usually stored as length.
Definition size_3d.hpp:103
T height
Height, usually stored as length.
Definition size_3d.hpp:102

◆ size_3d() [2/6]

template<typename T = length>
size_3d::size_3d ( const size_3d< T > &  x)
inline

Copy constructor. The width, height and depth are copied from the size_3d<T> x.

Definition at line 22 of file size_3d.hpp.

22 : width(x.width),height(x.height),depth(x.depth)
23 {}

◆ size_3d() [3/6]

template<typename T = length>
size_3d::size_3d ( size_3d< T > &&  x)
inline

Move constructor. The width, height and depth are moved from the size_3d<T> x.

Definition at line 25 of file size_3d.hpp.

25 : width(std::move(x.width)),height(std::move(x.height)),depth(std::move(x.depth))
26 {}

◆ size_3d() [4/6]

template<typename T = length>
scifir::size_3d< T >::size_3d ( const scalar_unit new_width,
const scalar_unit new_height,
const scalar_unit new_depth 
)
inlineexplicit

Definition at line 28 of file size_3d.hpp.

28 : width(new_width),height(new_height),depth(new_depth)
29 {}

◆ size_3d() [5/6]

template<typename T = length>
size_3d::size_3d ( const string new_width,
const string new_height,
const string new_depth 
)
inlineexplicit

Constructor. width is new_width, height is new_height and depth is new_depth, they are initialized by string.

Definition at line 31 of file size_3d.hpp.

31 : width(new_width),height(new_height),depth(new_depth)
32 {}

◆ size_3d() [6/6]

template<typename T = length>
size_3d::size_3d ( const string init_size_3d)
inlineexplicit

Constructor. The member-variables are initialized by the initialization string init_size_3d.

Definition at line 34 of file size_3d.hpp.

34 : size_3d()
35 {
36 initialize_from_string(init_size_3d);
37 }
size_3d()
Default constructor. Both width, height and depth are initialized to 0, with the dimensions to the de...
Definition size_3d.hpp:19
void initialize_from_string(const string &init_size_3d)
Internal function. Initializes the member-variables with an initialization string of size_3d<T>.
Definition size_3d.hpp:106

Member Function Documentation

◆ display()

template<typename T = length>
string size_3d::display ( ) const
inline

Returns a string representation of size_3d<T>, with his width, height and depth.

Definition at line 94 of file size_3d.hpp.

95 {
96 ostringstream output;
97 output << width << " * " << height << " * " << depth;
98 return output.str();
99 }

◆ get_volume()

template<typename T = length>
scalar_unit size_3d::get_volume ( ) const
inline

Calculates the volume as the multiplication of the width, height and depth.

Definition at line 89 of file size_3d.hpp.

90 {
91 return scalar_unit(width * height * depth);
92 }

◆ initialize_from_string()

template<typename T = length>
void size_3d::initialize_from_string ( const string init_size_3d)
inlineprivate

Internal function. Initializes the member-variables with an initialization string of size_3d<T>.

Definition at line 106 of file size_3d.hpp.

107 {
108 vector<string> widths;
109 boost::split(widths,init_size_3d,boost::is_any_of("*"));
110 if (widths.size() == 3)
111 {
112 boost::trim(widths[0]);
113 boost::trim(widths[1]);
114 boost::trim(widths[2]);
115 width = T(widths[0]);
116 height = T(widths[1]);
117 depth = T(widths[2]);
118 }
119 }

◆ operator+()

template<typename T = length>
template<typename U >
size_3d< T > size_3d::operator+ ( const size_3d< U > &  x) const
inline

Creates a new size_3d<T> by the addition of two size_3d<T> classes. The width, height and depth are the result of the addition of the two width, height or depth of the size_3d<T> classes.

Definition at line 62 of file size_3d.hpp.

63 {
64 return size_3d<T>(width + x.width,height + x.height,depth + x.depth);
65 }

◆ operator+=()

template<typename T = length>
template<typename U >
void size_3d::operator+= ( const size_3d< U > &  x)
inline

Sums the width of size_3d<T> x to the width, sums the height of size_3d<T> x to the height and sums the depth of size_3d<T> x to the depth.

Definition at line 74 of file size_3d.hpp.

75 {
76 width += x.width;
77 height += x.height;
78 depth += x.depth;
79 }

◆ operator-()

template<typename T = length>
template<typename U >
size_3d< T > size_3d::operator- ( const size_3d< U > &  x) const
inline

Creates a new size_3d<T> by the difference of two size_3d<T> classes. The width, height and depth are the result of the difference of the two width, height or depth of the size_3d<T> classes.

Definition at line 68 of file size_3d.hpp.

69 {
70 return size_3d<T>(width - x.width,height - x.height,depth - x.depth);
71 }

◆ operator-=()

template<typename T = length>
template<typename U >
void size_3d::operator-= ( const size_3d< U > &  x)
inline

Substracts the width of size_3d<T> x to the width, substracts the height of size_3d<T> x to the height and substracts the depth of size_3d<T> x to the depth.

Definition at line 82 of file size_3d.hpp.

83 {
84 width -= x.width;
85 height -= x.height;
86 depth -= x.depth;
87 }

◆ operator=() [1/3]

template<typename T = length>
size_3d< T > & size_3d::operator= ( const size_3d< T > &  x)
inline

Copy assignment. The width, height and depth are copied from the size_3d<T> x.

Definition at line 39 of file size_3d.hpp.

40 {
41 width = x.width;
42 height = x.height;
43 depth = x.depth;
44 return *this;
45 }

◆ operator=() [2/3]

template<typename T = length>
size_3d< T > & size_3d::operator= ( const string init_size_3d)
inline

Assignment. The member-variables are initialized by the initialization string init_size_3d.

Definition at line 55 of file size_3d.hpp.

56 {
57 initialize_from_string(init_size_3d);
58 return *this;
59 }

◆ operator=() [3/3]

template<typename T = length>
size_3d< T > & size_3d::operator= ( size_3d< T > &&  x)
inline

Move assignment. The width, height and depth are moved from the size_3d<T> x.

Definition at line 47 of file size_3d.hpp.

48 {
49 width = std::move(x.width);
50 height = std::move(x.height);
51 depth = std::move(x.depth);
52 return *this;
53 }

Member Data Documentation

◆ depth

template<typename T = length>
T size_3d::depth

Depth, usually stored as length.

Definition at line 103 of file size_3d.hpp.

◆ height

template<typename T = length>
T size_3d::height

Height, usually stored as length.

Definition at line 102 of file size_3d.hpp.

◆ width

template<typename T = length>
T size_3d::width

Width, usually stored as length.

Definition at line 101 of file size_3d.hpp.


The documentation for this class was generated from the following files: