]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdc-array.cxx
Full sweep of all Clang warnings, plus some bug fixes for incorrect memcpy usage.
[thirdparty/cups.git] / ppdc / ppdc-array.cxx
CommitLineData
ac884b6a
MS
1//
2// "$Id$"
3//
7e86f2f6 4// Array class for the CUPS PPD Compiler.
ac884b6a 5//
7e86f2f6
MS
6// Copyright 2007-2014 by Apple Inc.
7// Copyright 2002-2005 by Easy Software Products.
ac884b6a 8//
7e86f2f6
MS
9// These coded instructions, statements, and computer programs are the
10// property of Apple Inc. and are protected by Federal copyright
11// law. Distribution and use rights are outlined in the file "LICENSE.txt"
12// which should have been included with this file. If this file is
13// file is missing or damaged, see the license at "http://www.cups.org/".
ac884b6a
MS
14//
15
16//
17// Include necessary headers...
18//
19
38e73f87 20#include "ppdc-private.h"
ac884b6a
MS
21
22
23//
24// 'ppdcArray::ppdcArray()' - Create a new array.
25//
26
27ppdcArray::ppdcArray(ppdcArray *a)
94da7e34 28 : ppdcShared()
ac884b6a 29{
94da7e34
MS
30 PPDC_NEW;
31
ac884b6a
MS
32 if (a)
33 {
34 count = a->count;
35 alloc = count;
36
37 if (count)
38 {
39 // Make a copy of the array...
40 data = new ppdcShared *[count];
41
7e86f2f6 42 memcpy(data, a->data, (size_t)count * sizeof(ppdcShared *));
ac884b6a
MS
43
44 for (int i = 0; i < count; i ++)
e4572d57 45 data[i]->retain();
ac884b6a
MS
46 }
47 else
48 data = 0;
49 }
50 else
51 {
52 count = 0;
53 alloc = 0;
54 data = 0;
55 }
56
57 current = 0;
58}
59
60
61//
62// 'ppdcArray::~ppdcArray()' - Destroy an array.
63//
64
65ppdcArray::~ppdcArray()
66{
94da7e34
MS
67 PPDC_DELETE;
68
ac884b6a
MS
69 for (int i = 0; i < count; i ++)
70 data[i]->release();
71
72 if (alloc)
73 delete[] data;
74}
75
76
77//
78// 'ppdcArray::add()' - Add an element to an array.
79//
80
81void
82ppdcArray::add(ppdcShared *d)
83{
84 ppdcShared **temp;
85
86
87 if (count >= alloc)
88 {
89 alloc += 10;
90 temp = new ppdcShared *[alloc];
91
7e86f2f6 92 memcpy(temp, data, (size_t)count * sizeof(ppdcShared *));
ac884b6a
MS
93
94 delete[] data;
95 data = temp;
96 }
97
98 data[count++] = d;
99}
100
101
102//
103// 'ppdcArray::first()' - Return the first element in the array.
104//
105
106ppdcShared *
107ppdcArray::first()
108{
109 current = 0;
110
111 if (current >= count)
112 return (0);
113 else
114 return (data[current ++]);
115}
116
117
118//
119// 'ppdcArray::next()' - Return the next element in the array.
120//
121
122ppdcShared *
123ppdcArray::next()
124{
125 if (current >= count)
126 return (0);
127 else
128 return (data[current ++]);
129}
130
131
132//
133// 'ppdcArray::remove()' - Remove an element from the array.
134//
135
136void
137ppdcArray::remove(ppdcShared *d) // I - Data element
138{
139 int i; // Looping var
140
141
142 for (i = 0; i < count; i ++)
143 if (d == data[i])
144 break;
145
146 if (i >= count)
147 return;
148
149 count --;
150 d->release();
151
152 if (i < count)
7e86f2f6 153 memmove(data + i, data + i + 1, (size_t)(count - i) * sizeof(ppdcShared *));
ac884b6a
MS
154}
155
156
157//
158// End of "$Id$".
159//