log4cplus  2.0.8
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 
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 
96  log4cplus::tstring const & getProperty(tchar const * key) const;
97 
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 
122 
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_
std::map< log4cplus::tstring, log4cplus::tstring > StringMap
Definition: property.h:139
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:84
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:72
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