• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "print_range.h"
17 #include "print_log.h"
18 
19 namespace OHOS::Print {
PrintRange()20 PrintRange::PrintRange() : hasStartPage_(false), startPage_(0), hasEndPage_(false),
21     endPage_(0), hasPages_(false)
22 {
23     pages_.clear();
24 }
25 
PrintRange(const PrintRange & right)26 PrintRange::PrintRange(const PrintRange &right)
27 {
28     hasStartPage_ = right.hasStartPage_;
29     startPage_ = right.startPage_;
30     hasEndPage_ = right.hasEndPage_;
31     endPage_ = right.endPage_;
32     hasPages_ = right.hasPages_;
33     pages_.assign(right.pages_.begin(), right.pages_.end());
34 }
35 
operator =(const PrintRange & right)36 PrintRange &PrintRange::operator=(const PrintRange &right)
37 {
38     if (this != &right) {
39         hasStartPage_ = right.hasStartPage_;
40         startPage_ = right.startPage_;
41         hasEndPage_ = right.hasEndPage_;
42         endPage_ = right.endPage_;
43         hasPages_ = right.hasPages_;
44         pages_.assign(right.pages_.begin(), right.pages_.end());
45     }
46     return *this;
47 }
48 
~PrintRange()49 PrintRange::~PrintRange()
50 {
51     pages_.clear();
52 }
53 
Reset()54 void PrintRange::Reset()
55 {
56     hasStartPage_ = false;
57     startPage_ = 0;
58     hasEndPage_ = false;
59     endPage_ = 0;
60     hasPages_ = false;
61     pages_.clear();
62 }
63 
HasStartPage() const64 bool PrintRange::HasStartPage() const
65 {
66     return hasStartPage_;
67 }
68 
GetStartPage() const69 uint32_t PrintRange::GetStartPage() const
70 {
71     return startPage_;
72 }
73 
HasEndPage() const74 bool PrintRange::HasEndPage() const
75 {
76     return hasEndPage_;
77 }
78 
GetEndPage() const79 uint32_t PrintRange::GetEndPage() const
80 {
81     return endPage_;
82 }
83 
HasPages() const84 bool PrintRange::HasPages() const
85 {
86     return hasPages_;
87 }
88 
GetPages(std::vector<uint32_t> & pages) const89 void PrintRange::GetPages(std::vector<uint32_t> &pages) const
90 {
91     pages.assign(pages_.begin(), pages_.end());
92 }
93 
SetStartPage(uint32_t startpage)94 void PrintRange::SetStartPage(uint32_t startpage)
95 {
96     hasStartPage_ = true;
97     startPage_ = startpage;
98 }
99 
SetEndPage(uint32_t endpage)100 void PrintRange::SetEndPage(uint32_t endpage)
101 {
102     hasEndPage_ = true;
103     endPage_ = endpage;
104 }
105 
SetPages(const std::vector<uint32_t> & pages)106 void PrintRange::SetPages(const std::vector<uint32_t> &pages)
107 {
108     hasPages_ = true;
109     pages_.assign(pages.begin(), pages.end());
110 }
111 
ReadFromParcel(Parcel & parcel)112 void PrintRange::ReadFromParcel(Parcel &parcel)
113 {
114     hasStartPage_ = parcel.ReadBool();
115     if (hasStartPage_) {
116         SetStartPage(parcel.ReadUint32());
117     }
118 
119     hasEndPage_ = parcel.ReadBool();
120     if (hasEndPage_) {
121         SetEndPage(parcel.ReadUint32());
122     }
123 
124     hasPages_ = parcel.ReadBool();
125     if (hasPages_) {
126         std::vector<uint32_t> pages;
127         parcel.ReadUInt32Vector(&pages);
128         if (pages.size() > 0) {
129             SetPages(pages);
130         }
131     }
132 }
133 
Marshalling(Parcel & parcel) const134 bool PrintRange::Marshalling(Parcel &parcel) const
135 {
136     parcel.WriteBool(hasStartPage_);
137     if (hasStartPage_) {
138         parcel.WriteUint32(GetStartPage());
139     }
140 
141     parcel.WriteBool(hasEndPage_);
142     if (hasEndPage_) {
143         parcel.WriteUint32(GetEndPage());
144     }
145 
146     parcel.WriteBool(hasPages_);
147     if (hasPages_ && !parcel.WriteUInt32Vector(pages_)) {
148         PRINT_HILOGE("Failed to marshalling print range object");
149         return false;
150     }
151     return true;
152 }
153 
Unmarshalling(Parcel & parcel)154 std::shared_ptr<PrintRange> PrintRange::Unmarshalling(Parcel &parcel)
155 {
156     auto nativeObj = std::make_shared<PrintRange>();
157     nativeObj->ReadFromParcel(parcel);
158     return nativeObj;
159 }
160 
Dump()161 void PrintRange::Dump()
162 {
163     if (hasStartPage_) {
164         PRINT_HILOGD("startPage_ = %{public}d", startPage_);
165     }
166 
167     if (hasEndPage_) {
168         PRINT_HILOGD("endPage_ = %{public}d", endPage_);
169     }
170 
171     if (hasPages_) {
172         uint32_t pageLength = pages_.size();
173         for (uint32_t i = 0; i < pageLength; i++) {
174             PRINT_HILOGD("pages_ = %{public}d", pages_[i]);
175         }
176     }
177 }
178 } // namespace OHOS::Print
179