1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PPAPI_CPP_SIZE_H_
6 #define PPAPI_CPP_SIZE_H_
8 #include "ppapi/c/pp_size.h"
9 #include "ppapi/cpp/logging.h"
12 /// This file defines the API to create a size based on width
17 /// A size of an object based on width and height.
21 /// The default constructor. Initializes the width and height to 0.
27 /// A constructor accepting a pointer to a <code>PP_Size</code> and
28 /// converting the <code>PP_Size</code> to a <code>Size</code>. This is an
29 /// implicit conversion constructor.
31 /// @param[in] s A pointer to a <code>PP_Size</code>.
32 Size(const PP_Size
& s
) { // Implicit.
33 // Want the >= 0 checking of the setter.
38 /// A constructor accepting two int values for width and height and
39 /// converting them to a <code>Size</code>.
41 /// @param[in] w An int value representing a width.
42 /// @param[in] h An int value representing a height.
44 // Want the >= 0 checking of the setter.
53 /// PP_Size() allows implicit conversion of a <code>Size</code> to a
54 /// <code>PP_Size</code>.
61 /// Getter function for returning the internal <code>PP_Size</code> struct.
63 /// @return A const reference to the internal <code>PP_Size</code> struct.
64 const PP_Size
& pp_size() const {
68 /// Getter function for returning the internal <code>PP_Size</code> struct.
70 /// @return A mutable reference to the <code>PP_Size</code> struct.
75 /// Getter function for returning the value of width.
77 /// @return The value of width for this <code>Size</code>.
82 /// Setter function for setting the value of width.
84 /// @param[in] w A new width value.
85 void set_width(int w
) {
93 /// Getter function for returning the value of height.
95 /// @return The value of height for this <code>Size</code>.
100 /// Setter function for setting the value of height.
102 /// @param[in] h A new height value.
103 void set_height(int h
) {
111 /// GetArea() determines the area (width * height).
113 /// @return The area.
114 int GetArea() const {
115 return width() * height();
118 /// SetSize() sets the value of width and height.
120 /// @param[in] w A new width value.
121 /// @param[in] h A new height value.
122 void SetSize(int w
, int h
) {
127 /// Enlarge() enlarges the size of an object.
129 /// @param[in] w A width to add the current width.
130 /// @param[in] h A height to add to the current height.
131 void Enlarge(int w
, int h
) {
132 set_width(width() + w
);
133 set_height(height() + h
);
136 /// IsEmpty() determines if the size is zero.
138 /// @return true if the size is zero.
139 bool IsEmpty() const {
140 // Size doesn't allow negative dimensions, so testing for 0 is enough.
141 return (width() == 0) || (height() == 0);
150 /// This function determines whether the width and height values of two sizes
153 /// @param[in] lhs The <code>Size</code> on the left-hand side of the equation.
154 /// @param[in] rhs The <code>Size</code> on the right-hand side of the
157 /// @return true if they are equal, false if unequal.
158 inline bool operator==(const pp::Size
& lhs
, const pp::Size
& rhs
) {
159 return lhs
.width() == rhs
.width() && lhs
.height() == rhs
.height();
162 /// This function determines whether two <code>Sizes</code> are not equal.
164 /// @param[in] lhs The <code>Size</code> on the left-hand side of the equation.
165 /// @param[in] rhs The <code>Size</code> on the right-hand side of the equation.
167 /// @return true if the <code>Size</code> of lhs are equal to the
168 /// <code>Size</code> of rhs, otherwise false.
169 inline bool operator!=(const pp::Size
& lhs
, const pp::Size
& rhs
) {
170 return !(lhs
== rhs
);
173 #endif // PPAPI_CPP_SIZE_H_