00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00047 #ifndef FASTFORMAT_INCL_FASTFORMAT_BUNDLES_HPP_WININI_BUNDLE
00048 #define FASTFORMAT_INCL_FASTFORMAT_BUNDLES_HPP_WININI_BUNDLE
00049
00050
00051
00052
00053
00054 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00055 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WININI_BUNDLE_MAJOR 1
00056 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WININI_BUNDLE_MINOR 1
00057 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WININI_BUNDLE_REVISION 3
00058 # define FASTFORMAT_VER_FASTFORMAT_BUNDLES_HPP_WININI_BUNDLE_EDIT 13
00059 #endif
00060
00061
00062
00063
00064
00065 #ifndef __cplusplus
00066 # error This file can only be included in C++ compilation units
00067 #endif
00068
00069
00070
00071
00072
00073
00074 #include <fastformat/fastformat.h>
00075
00076
00077 #include <winstl/winstl.h>
00078
00079
00080 #include <stlsoft/shims/access/string.hpp>
00081 #include <stlsoft/util/minmax.hpp>
00082
00083
00084 #include <stdexcept>
00085 #include <string>
00086
00087
00088
00089
00090
00091 #if !defined(FASTFORMAT_NO_NAMESPACE)
00092 namespace fastformat
00093 {
00094 #endif
00095
00096
00097
00098
00099
00102 class winini_bundle
00103 {
00106 public:
00107 typedef ff_char_t char_type;
00108 typedef std::basic_string<char_type> string_type;
00109 typedef winini_bundle class_type;
00111
00114 public:
00115 explicit winini_bundle(char_type const *source, char_type const *section);
00116
00117 template <typename S0, typename S1>
00118 explicit winini_bundle(S0 const& source, S1 const& section)
00119 : m_iniFileName(::stlsoft::c_str_data(source), ::stlsoft::c_str_len(source))
00120 , m_iniSection(::stlsoft::c_str_data(section), ::stlsoft::c_str_len(section))
00121 {}
00122
00123 ~winini_bundle() throw();
00125
00128 public:
00129 string_type operator [](char_type const *name) const throw(std::out_of_range);
00130 template <typename S>
00131 string_type operator [](S const& name) const throw(std::out_of_range)
00132 {
00133 FASTFORMAT_DECLARE_c_str_ptr_();
00134
00135 return operator [](FASTFORMAT_INVOKE_c_str_ptr_(FASTFORMAT_INVOKE_c_str_ptr_(name)));
00136 }
00138
00141 private:
00143
00146 private:
00147 const string_type m_iniFileName;
00148 const string_type m_iniSection;
00150
00153 private:
00154 winini_bundle(class_type const&);
00155 class_type& operator =(class_type const&);
00157 };
00158
00159
00160
00161
00162
00163 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00164
00165 inline winini_bundle::winini_bundle(char_type const *source, char_type const *section)
00166 : m_iniFileName(source)
00167 , m_iniSection(section)
00168 {}
00169
00170 inline winini_bundle::~winini_bundle() throw()
00171 {}
00172
00173 inline winini_bundle::string_type winini_bundle::operator [](char_type const *name) const throw(std::out_of_range)
00174 {
00175 static const char_type sentinel[] = FASTFORMAT_LITERAL_STRING("{5DDAADE5-5134-4734-ACB8-A6D0FA3BD0EA}-{D875F19B-8279-4c44-9517-F16366BC13E3}");
00176
00177 ::SetLastError(0);
00178
00179 char_type result[1001];
00180 DWORD dw = ::GetPrivateProfileString(
00181 m_iniSection.c_str()
00182 , name
00183 , sentinel
00184 , &result[0]
00185 , STLSOFT_NUM_ELEMENTS(result)
00186 , m_iniFileName.c_str());
00187
00188 if(dw == STLSOFT_NUM_ELEMENTS(sentinel) - 1)
00189 {
00190 if(0 == string_type::traits_type::compare(sentinel, result, stlsoft::minimum(size_t(dw), STLSOFT_NUM_ELEMENTS(sentinel) - 1)))
00191 {
00192 throw std::out_of_range("section/key combination does not exist in the given INI file");
00193 }
00194 }
00195
00196 ::GetLastError();
00197
00198 return string_type(result, dw);
00199 }
00200
00201 #endif
00202
00203
00204
00205
00206
00207 #if !defined(FASTFORMAT_NO_NAMESPACE)
00208 }
00209 #endif
00210
00211
00212
00213 #endif
00214
00215