log4cplus  2.0.6
property.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: property.h
4 // Created: 2/2002
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 2002-2017 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
24 #ifndef LOG4CPLUS_HELPERS_PROPERTY_HEADER_
25 #define LOG4CPLUS_HELPERS_PROPERTY_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <log4cplus/streams.h>
34 #include <log4cplus/tstring.h>
35 #include <map>
36 #include <vector>
37 
38 
39 namespace log4cplus {
40  namespace helpers {
41 
44  public:
45  enum PFlags
46  {
47  // These encoding related options occupy 2 bits of the flags
48  // and are mutually exclusive. These flags are synchronized
49  // with PCFlags in PropertyConfigurator.
50 
51  fEncodingShift = 3
52  , fEncodingMask = 0x3
53  , fUnspecEncoding = (0 << fEncodingShift)
54 #if defined (LOG4CPLUS_HAVE_CODECVT_UTF8_FACET) && defined (UNICODE)
55  , fUTF8 = (1 << fEncodingShift)
56 #endif
57 #if (defined (LOG4CPLUS_HAVE_CODECVT_UTF16_FACET) || defined (_WIN32)) \
58  && defined (UNICODE)
59  , fUTF16 = (2 << fEncodingShift)
60 #endif
61 #if defined (LOG4CPLUS_HAVE_CODECVT_UTF32_FACET) && defined (UNICODE)
62  , fUTF32 = (3 << fEncodingShift)
63 #endif
64  };
65 
66  Properties();
67  explicit Properties(log4cplus::tistream& input);
68  explicit Properties(const log4cplus::tstring& inputFile, unsigned flags = 0);
69  virtual ~Properties();
70 
71  // constants
73 
74  // methods
78  bool exists(const log4cplus::tstring& key) const;
79  bool exists(tchar const * key) const;
80 
84  std::size_t size() const
85  {
86  return data.size();
87  }
88 
95  log4cplus::tstring const & getProperty(const log4cplus::tstring& key) const;
96  log4cplus::tstring const & getProperty(tchar const * key) const;
97 
105  log4cplus::tstring getProperty(const log4cplus::tstring& key,
106  const log4cplus::tstring& defaultVal) const;
107 
111  std::vector<log4cplus::tstring> propertyNames() const;
112 
116  void setProperty(const log4cplus::tstring& key, const log4cplus::tstring& value);
117 
121  bool removeProperty(const log4cplus::tstring& key);
122 
128  Properties getPropertySubset(const log4cplus::tstring& prefix) const;
129 
130  bool getInt (int & val, log4cplus::tstring const & key) const;
131  bool getUInt (unsigned & val, log4cplus::tstring const & key) const;
132  bool getLong (long & val, log4cplus::tstring const & key) const;
133  bool getULong (unsigned long & val, log4cplus::tstring const & key) const;
134  bool getBool (bool & val, log4cplus::tstring const & key) const;
135  bool getString (log4cplus::tstring & val, log4cplus::tstring const & key) const;
136 
137  protected:
138  // Types
139  typedef std::map<log4cplus::tstring, log4cplus::tstring> StringMap;
140 
141  // Methods
142  void init(log4cplus::tistream& input);
143 
144  // Data
146  unsigned flags;
147 
148  private:
149  template <typename StringType>
150  log4cplus::tstring const & get_property_worker (
151  StringType const & key) const;
152 
153  template <typename ValType>
154  bool get_type_val_worker (ValType & val,
155  log4cplus::tstring const & key) const;
156  };
157  } // end namespace helpers
158 
159 }
160 
161 
162 #endif // LOG4CPLUS_HELPERS_PROPERTY_HEADER_
tstring.h
log4cplus::helpers::Properties::StringMap
std::map< log4cplus::tstring, log4cplus::tstring > StringMap
Definition: property.h:139
log4cplus
Definition: appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::helpers::Properties::PROPERTIES_COMMENT_CHAR
static const tchar PROPERTIES_COMMENT_CHAR
Definition: property.h:72
streams.h
log4cplus::helpers::Properties::flags
unsigned flags
Definition: property.h:146
log4cplus::helpers::Properties::data
StringMap data
Definition: property.h:145
log4cplus::tchar
char tchar
Definition: tchar.h:56
config.hxx
log4cplus::helpers::Properties
Definition: property.h:43
log4cplus::helpers::Properties::PFlags
PFlags
Definition: property.h:45
log4cplus::tistream
std::basic_istream< tchar > tistream
Definition: streams.h:41
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::helpers::Properties::size
std::size_t size() const
Returns the number of entries in this map.
Definition: property.h:84