xref: /haiku/src/apps/haikudepot/packagemodel/PackageCategory.cpp (revision 82bfaa954dcfd90582fb2c1a0e918971eea57091)
1 /*
2  * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2013, Rene Gollent <rene@gollent.com>.
4  * Copyright 2016-2023, Andrew Lindesay <apl@lindesay.co.nz>.
5  * All rights reserved. Distributed under the terms of the MIT License.
6  */
7 
8 
9 #include "PackageCategory.h"
10 
11 #include <Collator.h>
12 
13 #include "LocaleUtils.h"
14 #include "Logger.h"
15 
16 
17 PackageCategory::PackageCategory()
18 	:
19 	BReferenceable(),
20 	fCode(),
21 	fName()
22 {
23 }
24 
25 
26 PackageCategory::PackageCategory(const BString& code, const BString& name)
27 	:
28 	BReferenceable(),
29 	fCode(code),
30 	fName(name)
31 {
32 }
33 
34 
35 PackageCategory::PackageCategory(const PackageCategory& other)
36 	:
37 	BReferenceable(),
38 	fCode(other.fCode),
39 	fName(other.fName)
40 {
41 }
42 
43 
44 PackageCategory&
45 PackageCategory::operator=(const PackageCategory& other)
46 {
47 	fCode = other.fCode;
48 	fName = other.fName;
49 	return *this;
50 }
51 
52 
53 bool
54 PackageCategory::operator==(const PackageCategory& other) const
55 {
56 	return fCode == other.fCode && fName == other.fName;
57 }
58 
59 
60 bool
61 PackageCategory::operator!=(const PackageCategory& other) const
62 {
63 	return !(*this == other);
64 }
65 
66 
67 int
68 PackageCategory::Compare(const PackageCategory& other) const
69 {
70 	BCollator* collator = LocaleUtils::GetSharedCollator();
71 	int32 result = collator->Compare(Name().String(),
72 		other.Name().String());
73 	if (result == 0)
74 		result = Code().Compare(other.Code());
75 	return result;
76 }
77 
78 
79 bool IsPackageCategoryBefore(const CategoryRef& c1,
80 	const CategoryRef& c2)
81 {
82 	if (!c1.IsSet() || !c2.IsSet())
83 		HDFATAL("unexpected NULL reference in a referencable");
84 	return c1->Compare(*c2) < 0;
85 }
86