1 /*
2  * libosinfo:
3  *
4  * Copyright (C) 2009-2020 Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <osinfo/osinfo.h>
22 #include <glib/gi18n-lib.h>
23 
24 /**
25  * SECTION:osinfo_oslist
26  * @short_description: A list of os platforms
27  * @see_also: #OsinfoList, #OsinfoOs
28  *
29  * #OsinfoOsList is a list specialization that stores
30  * only #OsinfoOs objects.
31  */
32 
33 struct _OsinfoOsListPrivate
34 {
35     gboolean unused;
36 };
37 
38 G_DEFINE_TYPE_WITH_PRIVATE(OsinfoOsList, osinfo_oslist, OSINFO_TYPE_PRODUCTLIST);
39 
40 static void
osinfo_oslist_finalize(GObject * object)41 osinfo_oslist_finalize(GObject *object)
42 {
43     /* Chain up to the parent class */
44     G_OBJECT_CLASS(osinfo_oslist_parent_class)->finalize(object);
45 }
46 
47 /* Init functions */
48 static void
osinfo_oslist_class_init(OsinfoOsListClass * klass)49 osinfo_oslist_class_init(OsinfoOsListClass *klass)
50 {
51     GObjectClass *g_klass = G_OBJECT_CLASS(klass);
52 
53     g_klass->finalize = osinfo_oslist_finalize;
54 }
55 
56 static void
osinfo_oslist_init(OsinfoOsList * list)57 osinfo_oslist_init(OsinfoOsList *list)
58 {
59     list->priv = osinfo_oslist_get_instance_private(list);
60 }
61 
62 
63 /**
64  * osinfo_oslist_new:
65  *
66  * Construct a new os list that is initially empty.
67  *
68  * Returns: (transfer full): an empty os list
69  */
osinfo_oslist_new(void)70 OsinfoOsList *osinfo_oslist_new(void)
71 {
72     return g_object_new(OSINFO_TYPE_OSLIST,
73                         "element-type", OSINFO_TYPE_OS,
74                         NULL);
75 }
76 
77 
78 /**
79  * osinfo_oslist_new_copy:
80  * @source: the os list to copy
81  *
82  * Construct a new os list that is filled with oss
83  * from @source
84  *
85  * Returns: (transfer full): a copy of the os list
86  * Deprecated: 0.2.2: Use osinfo_list_new_copy() instead.
87  */
osinfo_oslist_new_copy(OsinfoOsList * source)88 OsinfoOsList *osinfo_oslist_new_copy(OsinfoOsList *source)
89 {
90     OsinfoOsList *newList = osinfo_oslist_new();
91     osinfo_list_add_all(OSINFO_LIST(newList),
92                         OSINFO_LIST(source));
93     return newList;
94 }
95 
96 /**
97  * osinfo_oslist_new_filtered:
98  * @source: the os list to copy
99  * @filter: the filter to apply
100  *
101  * Construct a new os list that is filled with oss
102  * from @source that match @filter
103  *
104  * Returns: (transfer full): a filtered copy of the os list
105  * Deprecated: 0.2.2: Use osinfo_list_new_filtered() instead.
106  */
osinfo_oslist_new_filtered(OsinfoOsList * source,OsinfoFilter * filter)107 OsinfoOsList *osinfo_oslist_new_filtered(OsinfoOsList *source, OsinfoFilter *filter)
108 {
109     OsinfoOsList *newList = osinfo_oslist_new();
110     osinfo_list_add_filtered(OSINFO_LIST(newList),
111                              OSINFO_LIST(source),
112                              filter);
113     return newList;
114 }
115 
116 /**
117  * osinfo_oslist_new_intersection:
118  * @sourceOne: the first os list to copy
119  * @sourceTwo: the second os list to copy
120  *
121  * Construct a new os list that is filled with only the
122  * oss that are present in both @sourceOne and @sourceTwo.
123  *
124  * Returns: (transfer full): an intersection of the two os lists
125  * Deprecated: 0.2.2: Use osinfo_list_new_intersection() instead.
126  */
osinfo_oslist_new_intersection(OsinfoOsList * sourceOne,OsinfoOsList * sourceTwo)127 OsinfoOsList *osinfo_oslist_new_intersection(OsinfoOsList *sourceOne, OsinfoOsList *sourceTwo)
128 {
129     OsinfoOsList *newList = osinfo_oslist_new();
130     osinfo_list_add_intersection(OSINFO_LIST(newList),
131                                  OSINFO_LIST(sourceOne),
132                                  OSINFO_LIST(sourceTwo));
133     return newList;
134 }
135 
136 /**
137  * osinfo_oslist_new_union:
138  * @sourceOne: the first os list to copy
139  * @sourceTwo: the second os list to copy
140  *
141  * Construct a new os list that is filled with all the
142  * oss that are present in either @sourceOne and @sourceTwo.
143  *
144  * Returns: (transfer full): a union of the two os lists
145  * Deprecated: 0.2.2: Use osinfo_list_new_union() instead.
146  */
osinfo_oslist_new_union(OsinfoOsList * sourceOne,OsinfoOsList * sourceTwo)147 OsinfoOsList *osinfo_oslist_new_union(OsinfoOsList *sourceOne, OsinfoOsList *sourceTwo)
148 {
149     OsinfoOsList *newList = osinfo_oslist_new();
150     osinfo_list_add_union(OSINFO_LIST(newList),
151                           OSINFO_LIST(sourceOne),
152                           OSINFO_LIST(sourceTwo));
153     return newList;
154 }
155