xtd 0.2.0
size.h
Go to the documentation of this file.
1 #pragma once
5 #include "../drawing_export.h"
6 #include "size_f.h"
7 #include <xtd/iequatable>
8 #include <xtd/object>
9 #include <xtd/ustring>
10 #include <ostream>
11 
13 namespace xtd {
15  namespace drawing {
17  class point;
19 
31  class drawing_export_ size : public xtd::object, public xtd::iequatable<size> {
32  public:
34 
37  static const xtd::drawing::size empty;
39 
41 
44  size() = default;
47  explicit size(const xtd::drawing::point& point) noexcept;
51  size(int32 width, int32 height) noexcept;
53 
55  size(const xtd::drawing::size&) noexcept = default;
56  size& operator =(const xtd::drawing::size& size) noexcept = default;
57  operator size_f() const noexcept;
59 
61 
66  int32 height() const noexcept;
70  void height(int32 value) noexcept;
71 
74  bool is_empty() const noexcept;
75 
79  int32 width() const noexcept;
83  void width(int32 value) noexcept;
85 
87 
93  static size add(const size& size1, const size& size2) noexcept;
94 
98  static size ceiling(const size_f& value) noexcept;
99 
100  bool equals(const xtd::drawing::size& value) const noexcept override;
101 
105  static size round(const size_f& value) noexcept;
106 
111  static xtd::drawing::size subtract(const xtd::drawing::size& sz1, const xtd::drawing::size& sz2) noexcept;
112 
115  xtd::ustring to_string() const noexcept override;
116 
120  static size truncate(const size_f& value) noexcept;
122 
123 
125 
130  size operator +(const xtd::drawing::size& size) const noexcept;
131 
135  size& operator +=(const xtd::drawing::size& size) noexcept;
136 
140  size operator -(const xtd::drawing::size& size) const noexcept;
141 
145  size& operator -=(const xtd::drawing::size& size) noexcept;
147 
148  private:
149  int32 width_ = 0;
150  int32 height_ = 0;
151  };
152  }
153 
155  template<>
156  inline drawing::size parse<drawing::size>(const std::string& str) {
157  auto values = xtd::ustring(str).replace("}", "").replace(" height=", "").replace("{width=", "").split({','});
158  return {xtd::parse<int32>(values[0]), xtd::parse<int32>(values[1])};
159  }
161 }
value_t parse(const std::string &str)
Convert a string into a type.
Definition: parse.h:23
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:54
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:31
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
ustring replace(value_type old_char, value_type new_char) const noexcept
Replaces all occurrences of a specified char_t in this string with another specified char_t...
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1063
Stores an ordered pair of floating-point, which specify a height and width.
Definition: size_f.h:31
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
std::vector< ustring > split(const std::vector< value_type > &separators, size_t count, string_split_options options) const noexcept
Splits this string into a maximum number of substrings based on the characters in an array...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Contains xtd::drawing::size_f class.
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Specifies a printer&#39;s point (1/72 inch) as the unit of measure.
static const xtd::drawing::size empty
Gets a xtd::drawing::size class that has a Height and Width value of 0. This field is constant...
Definition: size.h:37