1//
2// "$Id: ppdc-option.cxx 3277 2011-05-20 07:30:39Z msweet $"
3//
4//   Option class for the CUPS PPD Compiler.
5//
6//   Copyright 2007-2011 by Apple Inc.
7//   Copyright 2002-2005 by Easy Software Products.
8//
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/".
14//
15// Contents:
16//
17//   ppdcOption::ppdcOption()    - Copy a new option.
18//   ppdcOption::~ppdcOption()   - Destroy an option.
19//   ppdcOption::find_choice()   - Find an option choice.
20//   ppdcOption::set_defchoice() - Set the default choice.
21//
22
23//
24// Include necessary headers...
25//
26
27#include "ppdc-private.h"
28
29
30//
31// 'ppdcOption::ppdcOption()' - Create a new option.
32//
33
34ppdcOption::ppdcOption(ppdcOptType    ot,	// I - Option type
35                       const char     *n,	// I - Option name
36		       const char     *t,	// I - Option text
37		       ppdcOptSection s,	// I - Section
38                       float          o)	// I - Ordering number
39  : ppdcShared()
40{
41  PPDC_NEW;
42
43  type      = ot;
44  name      = new ppdcString(n);
45  text      = new ppdcString(t);
46  section   = s;
47  order     = o;
48  choices   = new ppdcArray();
49  defchoice = 0;
50}
51
52
53//
54// 'ppdcOption::ppdcOption()' - Copy a new option.
55//
56
57ppdcOption::ppdcOption(ppdcOption *o)		// I - Template option
58{
59  PPDC_NEW;
60
61  o->name->retain();
62  o->text->retain();
63  if (o->defchoice)
64    o->defchoice->retain();
65
66  type      = o->type;
67  name      = o->name;
68  text      = o->text;
69  section   = o->section;
70  order     = o->order;
71  choices   = new ppdcArray(o->choices);
72  defchoice = o->defchoice;
73}
74
75
76//
77// 'ppdcOption::~ppdcOption()' - Destroy an option.
78//
79
80ppdcOption::~ppdcOption()
81{
82  PPDC_DELETE;
83
84  name->release();
85  text->release();
86  if (defchoice)
87    defchoice->release();
88  choices->release();
89}
90
91
92//
93// 'ppdcOption::find_choice()' - Find an option choice.
94//
95
96ppdcChoice *					// O - Choice or NULL
97ppdcOption::find_choice(const char *n)		// I - Name of choice
98{
99  ppdcChoice	*c;				// Current choice
100
101
102  for (c = (ppdcChoice *)choices->first(); c; c = (ppdcChoice *)choices->next())
103    if (!_cups_strcasecmp(n, c->name->value))
104      return (c);
105
106  return (0);
107}
108
109
110//
111// 'ppdcOption::set_defchoice()' - Set the default choice.
112//
113
114void
115ppdcOption::set_defchoice(ppdcChoice *c)	// I - Choice
116{
117  if (defchoice)
118    defchoice->release();
119
120  if (c->name)
121    c->name->retain();
122
123  defchoice = c->name;
124}
125
126
127//
128// End of "$Id: ppdc-option.cxx 3277 2011-05-20 07:30:39Z msweet $".
129//
130