File: ppdfile.h

package info (click to toggle)
splix 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,604 kB
  • sloc: cpp: 4,907; makefile: 436; ansic: 42; sh: 38; xml: 34; python: 8
file content (262 lines) | stat: -rw-r--r-- 9,756 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * 	    ppdfile.h                 (C) 2006-2008, Aurélien Croc (AP²C)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the
 *  Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 *  $Id$
 * 
 */
#ifndef _PPDFILE_H_
#define _PPDFILE_H_

#include <cups/ppd.h>
#include <stdlib.h>

/**
  * @class PPDFile
  * @brief This class provides an easy method to manage PPD files.
  *
  * This class provides methods to access in a easy way to data contained in PPD
  * files. During the opening of the file, the PPD version can be compared with
  * the current project version, default and user values are set as default.
  * Next, data contained in the ppd file can be manipulated easily with two
  * methods. The second one (@ref PPDValue::setPreformatted) allows the 
  * use of special bytes in strings.
  */
class PPDFile
{
    public:
        /**
          * @brief This class manages a PPD value.
          *
          * Use the defined type PPDValue to use this class.
          *
          * In a PPD a string can be preformatted to contain unprintable 
          * characters. For that, insert the ASCII number between < and >.
          * @code
          * *QPDL beginPJL: "<1B>%-12345X"
          * @endcode
          *
          * To decode these preformatted string, call the @ref setPreformatted
          * method and read the string.
          *
          */
        class Value {
            protected:
                const char*         _value;
                char*               _preformatted;
                const char*         _out;
                float               _width;
                float               _height;
                float               _marginX;
                float               _marginY;

            public:
                /**
                 * Initialize a new instance.
                 */
                Value();
                /**
                 * Initialize a new instance with the specified string.
                 * @param value the specified value.
                 */
                Value(const char *value);
                /**
                 * Destroy the instance.
                 */
                virtual ~Value();

            public:
                /**
                 * Set a string.
                 * @param value the string value.
                 * @return itself.
                 */
                PPDFile::Value&     set(const char *value);
                /**
                 * Set width, height and X, Y margins
                 * @param width the width.
                 * @param height the height.
                 * @param marginX the X margin.
                 * @param marginY the Y margin.
                 * @return itself.
                 */
                PPDFile::Value&     set(float width, float height, float
                                        marginX, float marginY);
                /**
                 * Specify the represented string is preformatted.
                 * @return itself.
                 */
                PPDFile::Value&     setPreformatted();

            public:
                /**
                 * @return the width value.
                 */
                float               width() const {return _width;}
                /**
                 * @return the height value.
                 */
                float               height() const {return _height;}
                /**
                 * @return the X margin value.
                 */
                float               marginX() const {return _marginX;}
                /**
                 * @return the Y margin value.
                 */
                float               marginY() const {return _marginY;}
                /**
                  * @return TRUE if there is no associated string. Otherwise it
                  *         returns FALSE.
                  */
                bool                isNull() const {return _out ? false : true;}

                /**
                  * Copy the string into an allocated buffer.
                  * The user has to free the string at the end of its use.
                  * @return a pointer to an allocated buffer containing the
                  *         string. If there is no string, it returns NULL.
                  */
                char*               deepCopy() const;

                /**
                  * @return TRUE if the key is set to true, enable, enabled,
                  *         yes, 1 or on. Otherwise it returns FALSE.
                  */
                bool                isTrue() const;
                /**
                  * @return FALSE if the key is set to true, enable, enabled,
                  *         yes, 1 or on. Otherwise it returns TRUE.
                  */
                bool                isFalse() const {return !isTrue();}

		        /**
                  * @return TRUE if the key is set to true, enable, enabled,
                  *         yes, 1 or on. Otherwise it returns FALSE.
		          */
                operator bool() const {return isTrue();}
                /**
                 * @return the string pointer.
                 */
                operator const char*() const {return _out;}
                /**
                 * @return the unsigned long converted value.
                 */
                operator unsigned long() const 
                        {return _out ? strtol(_out, (char**)NULL, 10) : 0;}
                /**
                 * @return the long converted value.
                 */
                operator long() const 
                        {return _out ? strtol(_out, (char**)NULL, 10) : 0;}
                /**
                 * @return the float converted value.
                 */
                operator float() const 
                        {return _out ? strtof(_out, (char**)NULL) : 0;}
                /**
                 * @return the double converted value.
                 */
                operator double() const 
                        {return _out ? strtod(_out, (char**)NULL) : 0;}
                /**
                 * @return the long double converted value.
                 */
                operator long double() const 
                        {return _out ? strtold(_out, (char**)NULL) : 0;}
                /**
                 * Compare the value with a string.
                 * The comparison is case insensitive.
                 * @param val the string to compare to
                 * @return TRUE if the strings are equivalent. Otherwise it
                 *         returns FALSE.
                 */
                bool    operator == (const char* val) const;
                /**
                 * Compare the value with a string.
                 * The comparison is case insensitive.
                 * @param val the string to compare to
                 * @return TRUE if the strings are different. Otherwise it
                 *         returns FALSE.
                 */
                bool    operator != (const char* val) const;
                /**
                 * Assignment operator.
                 * @param val the specified value.
                 */
                void    operator = (const Value &val);
        };

    protected:
        ppd_file_t*             _ppd;

    public:
        /**
         * Initialize a new PPDFile instance.
         */
        PPDFile();
        /**
         * Destroy the instance.
         * the PPD file will be closed if it was opened.
         */
        virtual~ PPDFile();

    public:
        /**
          * Open a PPD file and check its integrity.
          * @param file the file path and name
          * @param version the current SpliX version
          * @param useropts the user options
          * @return TRUE if the PPD has been successfully opened. Otherwise it
          *         returns false.
          */
        bool                    open(const char *file, const char *version, 
                                    const char *useropts = "");
        /**
          * Close a previously opened PPD file.
          */
        void                    close();

    public:
        /**
          * Get the string associated to a key or a key and a group.
          * @param name the key name
          * @param opt the name of the group if the key is in the group.
          *            Otherwise it must be set to NULL
          * @return a PPDValue instance containing the string or NULL if the key
          *         or the group/key doesn't exists or if there is no data 
          *         associated.
          */
        Value                   get(const char *name, const char *opt=NULL);
        /**
          * Get the page size information.
          * @param name the page format name
          * @return a PPDValue instance containing the width and the height of
          *         the page format requested.
          */
        Value                   getPageSize(const char *name);
};

/**
 * Represent a PPD value
 */
typedef PPDFile::Value PPDValue;


#endif /* _PPDFILE_H_ */

/* vim: set expandtab tabstop=4 shiftwidth=4 smarttab tw=80 cin enc=utf8: */