log4cplus  2.1.0
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  , fThrow = (1 << 5)
65  };
66 
68  explicit Properties(log4cplus::tistream& input);
69  explicit Properties(const log4cplus::tstring& inputFile, unsigned flags = 0);
70  virtual ~Properties();
71 
72  // constants
74 
75  // methods
79  bool exists(const log4cplus::tstring& key) const;
80  bool exists(tchar const * key) const;
81 
85  std::size_t size() const
86  {
87  return data.size();
88  }
89 
97  log4cplus::tstring const & getProperty(tchar const * key) const;
98 
107  const log4cplus::tstring& defaultVal) const;
108 
112  std::vector<log4cplus::tstring> propertyNames() const;
113 
117  void setProperty(const log4cplus::tstring& key, const log4cplus::tstring& value);
118 
123 
130 
131  bool getInt (int & val, log4cplus::tstring const & key) const;
132  bool getUInt (unsigned & val, log4cplus::tstring const & key) const;
133  bool getLong (long & val, log4cplus::tstring const & key) const;
134  bool getULong (unsigned long & val, log4cplus::tstring const & key) const;
135  bool getBool (bool & val, log4cplus::tstring const & key) const;
136  bool getString (log4cplus::tstring & val, log4cplus::tstring const & key) const;
137 
138  protected:
139  // Types
140  typedef std::map<log4cplus::tstring, log4cplus::tstring> StringMap;
141 
142  // Methods
143  void init(log4cplus::tistream& input);
144 
145  // Data
147  unsigned flags;
148 
149  private:
150  template <typename StringType>
151  log4cplus::tstring const & get_property_worker (
152  StringType const & key) const;
153 
154  template <typename ValType>
155  bool get_type_val_worker (ValType & val,
156  log4cplus::tstring const & key) const;
157  };
158  } // end namespace helpers
159 
160 }
161 
162 
163 #endif // LOG4CPLUS_HELPERS_PROPERTY_HEADER_
std::map< log4cplus::tstring, log4cplus::tstring > StringMap
Definition: property.h:140
bool getLong(long &val, log4cplus::tstring const &key) const
void setProperty(const log4cplus::tstring &key, const log4cplus::tstring &value)
Inserts value into this map indexed by key.
std::vector< log4cplus::tstring > propertyNames() const
Returns all the keys in this property list.
bool getUInt(unsigned &val, log4cplus::tstring const &key) const
std::size_t size() const
Returns the number of entries in this map.
Definition: property.h:85
bool getInt(int &val, log4cplus::tstring const &key) const
log4cplus::tstring const & getProperty(tchar const *key) const
bool exists(tchar const *key) const
Properties(log4cplus::tistream &input)
bool getULong(unsigned long &val, log4cplus::tstring const &key) const
bool getString(log4cplus::tstring &val, log4cplus::tstring const &key) const
log4cplus::tstring getProperty(const log4cplus::tstring &key, const log4cplus::tstring &defaultVal) const
Searches for the property with the specified key in this property list.
void init(log4cplus::tistream &input)
bool exists(const log4cplus::tstring &key) const
Tests to see if key can be found in this map.
log4cplus::tstring const & getProperty(const log4cplus::tstring &key) const
Searches for the property with the specified key in this property list.
bool removeProperty(const log4cplus::tstring &key)
Removed the property index by key from this map.
Properties getPropertySubset(const log4cplus::tstring &prefix) const
Returns a subset of the "properties" whose keys start with "prefix".
bool getBool(bool &val, log4cplus::tstring const &key) const
Properties(const log4cplus::tstring &inputFile, unsigned flags=0)
static const tchar PROPERTIES_COMMENT_CHAR
Definition: property.h:73
std::basic_string< tchar > tstring
Definition: tstring.h:39
char tchar
Definition: tchar.h:56
std::basic_istream< tchar > tistream
Definition: streams.h:41
#define LOG4CPLUS_EXPORT
Definition: win32.h:141