xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
size.h
Go to the documentation of this file.
1 #pragma once
5 #include <ostream>
6 #include <xtd/object.h>
7 #include <xtd/ustring.h>
8 #include "../drawing_export.h"
9 #include "size_f.h"
10 
12 namespace xtd {
14  namespace drawing {
16  class point;
18 
25  class drawing_export_ size : public object {
26  public:
28  static const xtd::drawing::size empty;
29 
31  size() = default;
32 
35  explicit size(const xtd::drawing::point& point);
36 
40  size(int32_t width, int32_t height) : width_(width), height_(height) {}
41 
43  size(const xtd::drawing::size&) = default;
44  bool operator==(const xtd::drawing::size& value) const {return width_ == value.width_ && height_ == value.height_;}
45  bool operator!=(const xtd::drawing::size& value) const {return !operator==(value);}
46  size& operator=(const xtd::drawing::size& size) = default;
47  size operator+(const xtd::drawing::size& size) const;
48  size operator-(const xtd::drawing::size& size) const;
49  size& operator+=(const xtd::drawing::size& size);
50  size& operator-=(const xtd::drawing::size& size);
51  operator size_f() {return size_f(static_cast<float>(width_), static_cast<float>(height_));}
53 
57  int32_t height() const {return height_;}
58 
62  void height(int32_t height) {height_ = height;}
63 
67  int32_t width() const {return width_;}
68 
72  void width(int32_t width) {width_ = width;}
73 
78  static size add(const size& size1, const size& size2);
79 
83  static size ceiling(const size_f& value);
84 
87  bool is_empty() const {return *this == size::empty;}
88 
92  static size round(const size_f& value);
93 
100 
103  xtd::ustring to_string() const noexcept override {return "{width=" + std::to_string(width_) + ", height=" + std::to_string(height_) + "}";}
104 
108  static size truncate(const size_f& value);
109 
111  friend std::ostream& operator<<(std::ostream& os, const xtd::drawing::size& size) noexcept {
112  return os << size.to_string();
113  }
115 
116  private:
117  int32_t width_ = 0;
118  int32_t height_ = 0;
119  };
120  }
121 
122  template<>
123  inline drawing::size parse<drawing::size>(const std::string& str) {
124  auto values = xtd::ustring(str).replace("}", "").replace(" height=", "").replace("{width=", "").split({','});
125  return {xtd::parse<int32_t>(values[0]), xtd::parse<int32_t>(values[1])};
126  }
127 }
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
Stores an ordered pair of floating-point, which specify a height and width.
Definition: size_f.h:24
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
size(int32_t width, int32_t height)
Initializes a new instance of the Size class from the specified dimensions.
Definition: size.h:40
size()=default
Initializes a new instance of the Size class that has a Height and Width value of 0.
static size round(const size_f &value)
Converts the specified size_f to a size object by rounding the size_f values to the nearest integer.
void height(int32_t height)
Sets the vertical component of this Size Class.
Definition: size.h:62
int32_t width() const
Gets the horizontal component of this Size class.
Definition: size.h:67
static size truncate(const size_f &value)
Converts the specified size_f to a size by truncating the values of the size_f.
static const xtd::drawing::size empty
Gets a Size class that has a Height and Width value of 0. This field is constant.
Definition: size.h:28
int32_t height() const
Gets he vertical component of this Size Class.
Definition: size.h:57
xtd::ustring to_string() const noexcept override
Creates a human-readable string that represents this size class.
Definition: size.h:103
void width(int32_t width)
Sets the horizontal component of this Size class.
Definition: size.h:72
static size ceiling(const size_f &value)
Converts the specified size_f to a size by rounding the values of the size_f to the next higher integ...
bool is_empty() const
Tests whether this Size class has width and height of 0.
Definition: size.h:87
static xtd::drawing::size subtract(const xtd::drawing::size &sz1, const xtd::drawing::size &sz2)
Returns the result of subtracting specified size from the specified size.
size(const xtd::drawing::point &point)
IInitializes a new instance of the Size class from the specified Point class.
static size add(const size &size1, const size &size2)
Adds the width and height of one Size class to the width and height of another size class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
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.
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.
#define drawing_export_
Define shared library export.
Definition: drawing_export.h:13
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37
@ point
Specifies a printer's point (1/72 inch) as the unit of measure.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.
Contains xtd::drawing::size_f class.
Contains xtd::ustring class.