1 // Module: Log4CPLUS
2 // File: property.h
3 // Created: 2/2002
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright (C) Tad E. Smith All rights reserved.
8 //
9 // This software is published under the terms of the Apache Software
10 // License version 1.1, a copy of which has been included with this
11 // distribution in the LICENSE.APL file.
12 //
13
14 /** @file */
15
16 #ifndef LOG4CPLUS_HELPERS_PROPERTY_HEADER_
17 #define LOG4CPLUS_HELPERS_PROPERTY_HEADER_
18
19 #include <log4cplus/config.h>
20 #include <log4cplus/streams.h>
21 #include <log4cplus/tstring.h>
22 #include <map>
23 #include <vector>
24
25 #if (defined(__MWERKS__) && defined(__MACOS__))
26 using std::size_t;
27 #endif
28
29
30 namespace log4cplus {
31 namespace helpers {
32
33 class LOG4CPLUS_EXPORT Properties {
34 public:
35 Properties();
36 explicit Properties(log4cplus::tistream& input);
37 explicit Properties(const log4cplus::tstring& inputFile);
38 virtual ~Properties();
39
40 // constants
41 static const tchar PROPERTIES_COMMENT_CHAR;
42
43 // methods
44 /**
45 * Tests to see if <code>key</code> can be found in this map.
46 */
47 bool exists(const log4cplus::tstring& key) const {
48 return data.find(key) != data.end();
49 }
50
51
52 /**
53 * Returns the number of entries in this map.
54 */
55 size_t size() const {
56 return data.size();
57 }
58
59 /**
60 * Searches for the property with the specified key in this property
61 * list. If the key is not found in this property list, the default
62 * property list, and its defaults, recursively, are then checked.
63 * The method returns <code>null</code> if the property is not found.
64 */
65 log4cplus::tstring getProperty(const log4cplus::tstring& key) const;
66
67 /**
68 * Searches for the property with the specified key in this property
69 * list. If the key is not found in this property list, the default
70 * property list, and its defaults, recursively, are then checked.
71 * The method returns the default value argument if the property is
72 * not found.
73 */
74 log4cplus::tstring getProperty(const log4cplus::tstring& key,
75 const log4cplus::tstring& defaultVal) const;
76
77 /**
78 * Returns all the keys in this property list.
79 */
80 std::vector<log4cplus::tstring> propertyNames() const;
81
82 /**
83 * Inserts <code>value</code> into this map indexed by <code>key</code>.
84 */
85 void setProperty(const log4cplus::tstring& key, const log4cplus::tstring& value);
86
87 /**
88 * Removed the property index by <code>key</code> from this map.
89 */
90 bool removeProperty(const log4cplus::tstring& key);
91
92 /**
93 * Returns a subset of the "properties" whose keys start with
94 * "prefix". The returned "properties" have "prefix" trimmed from
95 * their keys.
96 */
97 Properties getPropertySubset(const log4cplus::tstring& prefix) const;
98
99 protected:
100 // Types
101 // LOG4CPLUS_EXPIMP_TEMPLATE template class LOG4CPLUS_EXPORT std::map<log4cplus::tstring, log4cplus::tstring>;
102 typedef std::map<log4cplus::tstring, log4cplus::tstring> StringMap;
103
104 // Methods
105 void init(log4cplus::tistream& input);
106
107 // Data
108 StringMap data;
109 };
110 } // end namespace helpers
111
112 }
113
114
115 #endif // LOG4CPLUS_HELPERS_PROPERTY_HEADER_
syntax highlighted by Code2HTML, v. 0.9.1