]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdc-option.cxx
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / ppdc / ppdc-option.cxx
CommitLineData
ac884b6a 1//
503b54c9 2// Option class for the CUPS PPD Compiler.
ac884b6a 3//
503b54c9
MS
4// Copyright 2007-2011 by Apple Inc.
5// Copyright 2002-2005 by Easy Software Products.
ac884b6a 6//
e3101897 7// Licensed under Apache License v2.0. See the file "LICENSE" for more information.
ac884b6a
MS
8//
9
10//
11// Include necessary headers...
12//
13
38e73f87 14#include "ppdc-private.h"
ac884b6a
MS
15
16
17//
18// 'ppdcOption::ppdcOption()' - Create a new option.
19//
20
21ppdcOption::ppdcOption(ppdcOptType ot, // I - Option type
22 const char *n, // I - Option name
23 const char *t, // I - Option text
24 ppdcOptSection s, // I - Section
25 float o) // I - Ordering number
94da7e34 26 : ppdcShared()
ac884b6a 27{
94da7e34 28 PPDC_NEW;
ac884b6a
MS
29
30 type = ot;
31 name = new ppdcString(n);
32 text = new ppdcString(t);
33 section = s;
34 order = o;
35 choices = new ppdcArray();
36 defchoice = 0;
37}
38
39
40//
41// 'ppdcOption::ppdcOption()' - Copy a new option.
42//
43
44ppdcOption::ppdcOption(ppdcOption *o) // I - Template option
45{
94da7e34
MS
46 PPDC_NEW;
47
e4572d57
MS
48 o->name->retain();
49 o->text->retain();
ac884b6a 50 if (o->defchoice)
e4572d57 51 o->defchoice->retain();
ac884b6a
MS
52
53 type = o->type;
54 name = o->name;
55 text = o->text;
56 section = o->section;
57 order = o->order;
58 choices = new ppdcArray(o->choices);
59 defchoice = o->defchoice;
60}
61
62
63//
64// 'ppdcOption::~ppdcOption()' - Destroy an option.
65//
66
67ppdcOption::~ppdcOption()
68{
94da7e34
MS
69 PPDC_DELETE;
70
ac884b6a
MS
71 name->release();
72 text->release();
73 if (defchoice)
74 defchoice->release();
e4572d57 75 choices->release();
ac884b6a
MS
76}
77
78
79//
80// 'ppdcOption::find_choice()' - Find an option choice.
81//
82
83ppdcChoice * // O - Choice or NULL
84ppdcOption::find_choice(const char *n) // I - Name of choice
85{
86 ppdcChoice *c; // Current choice
87
88
89 for (c = (ppdcChoice *)choices->first(); c; c = (ppdcChoice *)choices->next())
88f9aafc 90 if (!_cups_strcasecmp(n, c->name->value))
ac884b6a
MS
91 return (c);
92
93 return (0);
94}
95
96
97//
98// 'ppdcOption::set_defchoice()' - Set the default choice.
99//
100
101void
102ppdcOption::set_defchoice(ppdcChoice *c) // I - Choice
103{
104 if (defchoice)
105 defchoice->release();
106
107 if (c->name)
e4572d57 108 c->name->retain();
ac884b6a
MS
109
110 defchoice = c->name;
111}