vfs: check userland buffers before reading them.
[haiku.git] / src / libs / print / libprint / PrinterCap.cpp
blob37b3beec7b61e4ea0304e7a6a595a84024a4cad2
1 /*
2 * PrinterCap.cpp
3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4 */
6 #include "PrinterCap.h"
7 #include "PrinterData.h"
9 BaseCap::BaseCap(const string &label)
11 fLabel(label)
16 BaseCap::~BaseCap()
21 const char*
22 BaseCap::Label() const
24 return fLabel.c_str();
28 EnumCap::EnumCap(const string &label, bool isDefault)
30 BaseCap(label),
31 fIsDefault(isDefault)
36 const char*
37 EnumCap::Key() const
39 return fKey.c_str();
43 PaperCap::PaperCap(const string &label, bool isDefault, JobData::Paper paper,
44 const BRect &paperRect, const BRect &physicalRect)
46 EnumCap(label, isDefault),
47 fPaper(paper),
48 fPaperRect(paperRect),
49 fPhysicalRect(physicalRect)
54 int32
55 PaperCap::ID() const
57 return fPaper;
61 PaperSourceCap::PaperSourceCap(const string &label, bool isDefault,
62 JobData::PaperSource paperSource)
64 EnumCap(label, isDefault),
65 fPaperSource(paperSource)
70 int32
71 PaperSourceCap::ID() const
73 return fPaperSource;
77 ResolutionCap::ResolutionCap(const string &label, bool isDefault,
78 int32 id, int xResolution, int yResolution)
80 EnumCap(label, isDefault),
81 fID(id),
82 fXResolution(xResolution),
83 fYResolution(yResolution)
88 int32
89 ResolutionCap::ID() const
91 return fID;
95 OrientationCap::OrientationCap(const string &label, bool isDefault,
96 JobData::Orientation orientation)
98 EnumCap(label, isDefault),
99 fOrientation(orientation)
104 int32
105 OrientationCap::ID() const
107 return fOrientation;
111 PrintStyleCap::PrintStyleCap(const string &label, bool isDefault,
112 JobData::PrintStyle printStyle)
114 EnumCap(label, isDefault),
115 fPrintStyle(printStyle)
120 int32
121 PrintStyleCap::ID() const
123 return fPrintStyle;
127 BindingLocationCap::BindingLocationCap(const string &label, bool isDefault,
128 JobData::BindingLocation bindingLocation)
130 EnumCap(label, isDefault),
131 fBindingLocation(bindingLocation)
136 int32
137 BindingLocationCap::ID() const
139 return fBindingLocation;
143 ColorCap::ColorCap(const string &label, bool isDefault, JobData::Color color)
145 EnumCap(label, isDefault),
146 fColor(color)
151 int32
152 ColorCap::ID() const
154 return fColor;
158 ProtocolClassCap::ProtocolClassCap(const string &label, bool isDefault,
159 int32 protocolClass, const string &description)
161 EnumCap(label, isDefault),
162 fProtocolClass(protocolClass),
163 fDescription(description)
168 int32
169 ProtocolClassCap::ID() const
171 return fProtocolClass;
175 DriverSpecificCap::DriverSpecificCap(const string& label, int32 category,
176 Type type)
178 EnumCap(label, false),
179 fCategory(category),
180 fType(type)
185 int32
186 DriverSpecificCap::ID() const
188 return fCategory;
192 ListItemCap::ListItemCap(const string& label, bool isDefault, int32 id)
194 EnumCap(label, isDefault),
195 fID(id)
200 int32
201 ListItemCap::ID() const
203 return fID;
207 BooleanCap::BooleanCap(const string& label, bool defaultValue)
209 BaseCap(label),
210 fDefaultValue(defaultValue)
215 bool
216 BooleanCap::DefaultValue() const
218 return fDefaultValue;
222 IntRangeCap::IntRangeCap(const string& label, int lower, int upper,
223 int defaultValue)
225 BaseCap(label),
226 fLower(lower),
227 fUpper(upper),
228 fDefaultValue(defaultValue)
233 int32
234 IntRangeCap::Lower() const
236 return fLower;
240 int32
241 IntRangeCap::Upper() const
243 return fUpper;
247 int32
248 IntRangeCap::DefaultValue() const
250 return fDefaultValue;
254 DoubleRangeCap::DoubleRangeCap(const string& label, double lower, double upper,
255 double defaultValue)
257 BaseCap(label),
258 fLower(lower),
259 fUpper(upper),
260 fDefaultValue(defaultValue)
265 double
266 DoubleRangeCap::Lower() const
268 return fLower;
272 double
273 DoubleRangeCap::Upper() const
275 return fUpper;
279 double
280 DoubleRangeCap::DefaultValue() const
282 return fDefaultValue;
286 PrinterCap::PrinterCap(const PrinterData *printer_data)
288 fPrinterData(printer_data)
293 PrinterCap::~PrinterCap()
298 const EnumCap*
299 PrinterCap::GetDefaultCap(CapID category) const
301 int count = CountCap(category);
302 if (count <= 0)
303 return NULL;
305 const BaseCap **base_cap = GetCaps(category);
306 while (count--) {
307 const EnumCap* enumCap = dynamic_cast<const EnumCap*>(*base_cap);
308 if (enumCap == NULL)
309 return NULL;
311 if (enumCap->fIsDefault) {
312 return enumCap;
315 base_cap++;
318 return static_cast<const EnumCap*>(GetCaps(category)[0]);
322 template<typename Predicate>
323 const BaseCap*
324 PrinterCap::FindCap(CapID category, Predicate& predicate) const
326 int count = CountCap(category);
327 if (count <= 0)
328 return NULL;
330 const BaseCap **base_cap = GetCaps(category);
331 while (count--) {
332 if (predicate(*base_cap)) {
333 return *base_cap;
335 base_cap++;
337 return NULL;
341 const EnumCap*
342 PrinterCap::FindCap(CapID category, int id) const
344 IDPredicate predicate(id);
345 return static_cast<const EnumCap*>(FindCap(category, predicate));
349 const BaseCap*
350 PrinterCap::FindCap(CapID category, const char* label) const
352 LabelPredicate predicate(label);
353 return FindCap(category, predicate);
357 const EnumCap*
358 PrinterCap::FindCapWithKey(CapID category, const char* key) const
360 KeyPredicate predicate(key);
361 return static_cast<const EnumCap*>(FindCap(category, predicate));
365 const BooleanCap*
366 PrinterCap::FindBooleanCap(CapID category) const
368 if (CountCap(category) != 1)
369 return NULL;
370 return dynamic_cast<const BooleanCap*>(GetCaps(category)[0]);
374 const IntRangeCap*
375 PrinterCap::FindIntRangeCap(CapID category) const
377 if (CountCap(category) != 1)
378 return NULL;
379 return dynamic_cast<const IntRangeCap*>(GetCaps(category)[0]);
383 const DoubleRangeCap*
384 PrinterCap::FindDoubleRangeCap(CapID category) const
386 if (CountCap(category) != 1)
387 return NULL;
388 return dynamic_cast<const DoubleRangeCap*>(GetCaps(category)[0]);
393 PrinterCap::GetProtocolClass() const {
394 return fPrinterData->GetProtocolClass();
398 const PrinterData*
399 PrinterCap::GetPrinterData() const
401 return fPrinterData;