1 /*----------------------------------------------------------------------------
 2 Name:      Properties.h
 3 Project:   xmlBlaster.org
 4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
 5 Comment:   Hold environment and command line properties.
 6 Author:    "Marcel Ruff" <xmlBlaster@marcelruff.info>
 7 Date:      06/2003
 8 See:       http://www.xmlblaster.org/xmlBlaster/doc/requirements/client.c.socket.html
 9 -----------------------------------------------------------------------------*/
10 #ifndef XMLBLASTER_Properties_H
11 #define XMLBLASTER_Properties_H
12 
13 #include <util/basicDefs.h>
14 
15 #ifdef __cplusplus
16 #ifndef XMLBLASTER_C_COMPILE_AS_CPP /* 'g++ -DXMLBLASTER_C_COMPILE_AS_CPP ...' allows to compile the lib as C++ code */
17 extern "C" {
18 #endif
19 #endif
20 
21 struct PropertiesStruct;
22 typedef struct PropertiesStruct Properties;
23 
24 /* Declare function pointers to use in struct to simulate object oriented access */
25 typedef const char *( * XmlBlasterPropertiesGetString)(Properties *xb, const char * key, const char *defaultValue);
26 typedef bool ( * XmlBlasterPropertiesGetBool)(Properties *xb, const char * key, bool defaultValue);
27 typedef int ( * XmlBlasterPropertiesGetInt)(Properties *xb, const char * key, int defaultValue);
28 typedef long ( * XmlBlasterPropertiesGetLong)(Properties *xb, const char * key, long defaultValue);
29 typedef int64_t ( * XmlBlasterPropertiesGetInt64)(Properties *xb, const char * key, int64_t defaultValue);
30 typedef double ( * XmlBlasterPropertiesGetDouble)(Properties *xb, const char * key, double defaultValue);
31 
32 /**
33  * Parses argv and has accessor methods for different data types.
34  * All client access to Properties goes over this struct and its function pointers.
35  */
36 struct PropertiesStruct {
37    int argc;             /**< Number of #argv */
38    char **argv;          /**< Pointer on the memory of the passed arguments */
39    const char *execName; /**< The executable name */
40    /**
41     * Access command line settings of for "myExec -logLevel TRACE".
42     * If the key is not found the environment is checked, if this
43     * does not contain the key the defaultValue is returned.
44     * @param xb The 'this' pointer
45     * @param key e.g. "logLevel"
46     * @param defaultValue e.g. "WARN"
47     */
48    XmlBlasterPropertiesGetString getString; /**< Access a property as a string */
49    XmlBlasterPropertiesGetBool getBool;     /**< Access a property converted to bool */
50    XmlBlasterPropertiesGetInt getInt;       /**< Access a property converted to int */
51    XmlBlasterPropertiesGetLong getLong;     /**< Access a property converted to long */
52    XmlBlasterPropertiesGetInt64 getInt64;   /**< Access a property converted to a 64 bit long */
53    XmlBlasterPropertiesGetDouble getDouble; /**< Access a property converted to double */
54 };
55 
56 /**
57  * Get an instance of this Properties struct.
58  * NOTE: Every call creates a new and independent instance
59  * @param argc Number of argv entries
60  * @param argv The first entry is expected to be the executable name, the others are tuples of form "-logLevel" "TRACE"
61  * @return NULL if bootstrapping failed. If not NULL you need to free() it when you are done
62  * usually by calling freeProperties().
63  */
64 Dll_Export extern Properties *createProperties(int argc, const char* const* argv);
65 
66 /**
67  * Free your instance after accessing xmlBlaster.
68  */
69 Dll_Export extern void freeProperties(Properties *props);
70 
71 /**
72  * Dump properties to console, for debugging only.
73  */
74 Dll_Export extern void dumpProperties(Properties *props);
75 
76 #ifdef __cplusplus
77 #ifndef XMLBLASTER_C_COMPILE_AS_CPP
78 }
79 #endif
80 #endif
81 
82 #endif /* XMLBLASTER_Properties_H */


syntax highlighted by Code2HTML, v. 0.9.1