OSDN Git Service

Support assignment of DEBUGLEVEL at configure time.
[mingw/mingw-get.git] / src / pkgopts.h
1 #ifndef PKGOPTS_H
2 /*
3  * pkgopts.h
4  *
5  * $Id$
6  *
7  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8  * Copyright (C) 2011, MinGW Project
9  *
10  *
11  * Public declarations of the data structures, values and functions
12  * for specification and control of global program options.
13  *
14  *
15  * This is free software.  Permission is granted to copy, modify and
16  * redistribute this software, under the provisions of the GNU General
17  * Public License, Version 3, (or, at your option, any later version),
18  * as published by the Free Software Foundation; see the file COPYING
19  * for licensing details.
20  *
21  * Note, in particular, that this software is provided "as is", in the
22  * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
23  * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
24  * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
25  * MinGW Project, accept liability for any damages, however caused,
26  * arising from the use of this software.
27  *
28  */
29 #define PKGOPTS_H  1
30
31 enum
32 { /* Specification of symbolic names (keys) for each of the individual
33    * entries in the options parameter array.
34    */
35   OPTION_FLAGS,
36   OPTION_DEBUGLEVEL,
37
38   /* This final entry specifies the size of the parameter array which
39    * comprises the data content of the options structure; it MUST be the
40    * final item in the enumeration, but is NOT intended to be used as
41    * a key into the data table itself.
42    */
43   OPTION_TABLE_SIZE
44 };
45
46 struct pkgopts
47 {
48   /* The primary data structure used to accumulate the settings data for
49    * user specified global program options; (fundamentally, this is a type
50    * agnostic array...
51    */
52   union
53   { /* ...which is suitable for storage of...
54      */
55     unsigned numeric;       /* ...integer numeric, or bit-map data...     */
56     const char *string;     /* ...and reference pointers for string data) */
57   }
58   flags[OPTION_TABLE_SIZE];
59 };
60
61 /* Bit-mapped control tags used by the CLI options parsing code...
62  */
63 #define OPTION_STORAGE_CLASS    (0x00000007 << 28)
64 /*
65  * ...to determine how option arguments are to be inserted into the
66  * global options table...
67  */
68 #define OPTION_STORE_STRING     (0x00000001 << 28)
69 #define OPTION_STORE_NUMBER     (0x00000002 << 28)
70 #define OPTION_MERGE_NUMBER     (0x00000003 << 28)
71 /*
72  * ...with specific handling for individual options.
73  */
74 #define OPTION_TRACE  (OPTION_MERGE_NUMBER | OPTION_DEBUGLEVEL)
75
76 /* Options controlled by bit-mapped flags within OPTION_FLAGS...
77  */
78 #define OPTION_VERBOSE          (0x00000003)
79 #define OPTION_VERBOSE_MAX      (0x00000003)
80
81 #if __cplusplus
82 /*
83  * We provide additional features for use in C++ modules.
84  */
85 #include <stdlib.h>
86
87 #ifndef EXTERN_C
88 /* This is primarily for convenience...
89  */
90 # define EXTERN_C  extern "C"
91 #endif
92
93 class pkgOpts : protected pkgopts
94 {
95   /* A derived "convenience" class, associating a collection
96    * of utility methods with the pkgopts structure.
97    */
98   public:
99     inline unsigned GetValue( int index )
100     {
101       /* Retrieve the value of a numeric data entry.
102        */
103       return this ? (flags[index].numeric) : 0;
104     }
105     inline const char *GetString( int index )
106     {
107       /* Retrieve a pointer to a string data entry.
108        */
109       return this ? (flags[index].string) : NULL;
110     }
111     inline unsigned Test( unsigned mask, int index = OPTION_FLAGS )
112     {
113       /* Test the state of specified bits within
114        * a bit-mapped numeric data (flags) entry.
115        */
116       return this ? (flags[index].numeric & mask) : 0;
117     }
118 };
119
120 /* Access modes for the following global options accessor function.
121  */
122 enum { OPTION_TABLE_LOOKUP, OPTION_TABLE_ASSIGN };
123
124 /* Global options accessor function; the default access mode is
125  * OPTION_TABLE_LOOKUP, (in which case the second argument is ignored),
126  * which allows us to simply use
127  *
128  *   result = pkgOptions()->GetValue( OPTION_KEY );
129  *
130  * to retrieve a value from the global options table.
131  *
132  * The OPTION_TABLE_ASSIGN access mode is provided for initialisation
133  * of the global options table reference pointer; it is used during
134  * program start-up, after which it is not normally used again.
135  */
136 EXTERN_C pkgOpts *pkgOptions( int = OPTION_TABLE_LOOKUP, struct pkgopts* = NULL );
137
138 #endif /* __cplusplus */
139
140 #endif /* PKGOPTS_H: $RCSfile$: end of file */