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